奧比中光大白 RGBD相機 python opencv代碼實現

奧比中光 "大白",彩色圖像UVC協議,深度用openni。(很煩)

我們的項目需要在python中使用,問了奧比中光的技術支持,說沒有python版本的demo,就自己寫了一個。

彩色:

import cv2
import sys

capture_width  = 800
capture_height = 1280


cap = cv2.VideoCapture(0)
cap.set(3, capture_width)
cap.set(4, capture_height)

for i in range(10):
  cap.read()

ret, img = cap.read()
cv2.imwrite("uvc.png", img)
cap.release()

深度:

import cv2
import numpy as np
from openni import openni2
from openni import _openni2 as c_api
import time
import imutils
import ctypes
from openni import openni2
redistPath = "../lib/Redist/" 
#redist就是sdk文件夾下,Windows下的Redist文件夾,裏面是openni.ini等
openni2.initialize(reds'd'kistPath) 


fps = 30      # frames per second
width = 640       # Width of image
height = 400      # height of image


dev = openni2.Device.open_any()
print(dev.get_device_info())
depth_stream = dev.create_depth_stream()
dev.set_image_registration_mode(True)
dev.set_depth_color_sync_enabled(True)


depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat=c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_1_MM,
                                                   resolutionX=width,
                                                   resolutionY=height,
                                                   fps=fps))
depth_stream.start()
while True:
    frame = depth_stream.read_frame()
    frame_data = frame.get_buffer_as_uint16()
    img = np.ndarray((frame.height, frame.width), dtype=np.uint16,buffer=frame_data)

    cv2.imshow("Depth", img)
    if (cv2.waitKey(1) & 0xFF == ord('q')):
        break

openni2.unload()
dev.close()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章