简体   繁体   English

使用python OpenCV从Kinect设备检索频道

[英]Retrieving Channels from Kinect device using python OpenCV

I put together some simple code in python to grab different channels from OpenNI devices. 我在python中放了一些简单的代码,以从OpenNI设备获取不同的通道。 I built OpenCV myself with all the PrimeSense and OpenNI support enabled. 我在启用所有PrimeSense和OpenNI支持的情况下自行构建了OpenCV。 The OpenNI samples work perfectly for both the Kinect sensor and PrimeSense sensor, as well as the OpenCV samples for testing OpenNI support (./cpp-example-openni_capture). OpenNI示例适用于Kinect传感器和PrimeSense传感器,以及适用于测试OpenNI支持的OpenCV示例(./cpp-example-openni_capture)。

Here is the code I put together. 这是我编写的代码。

import cv2
import cv2.cv as cv

capture = cv2.VideoCapture(cv.CV_CAP_OPENNI)
capture.set(cv.CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, cv.CV_CAP_OPENNI_VGA_30HZ)

print capture.get(cv.CV_CAP_PROP_OPENNI_REGISTRATION)

while True:
    if not capture.grab():
        print "Unable to Grab Frames from camera"
        break
    okay1, depth_map = capture.retrieve(cv.CV_CAP_OPENNI_DEPTH_MAP)
    if not okay1:
        print "Unable to Retrieve Disparity Map from camera"
        break
    okay2, gray_image = capture.retrieve(cv.CV_CAP_OPENNI_GRAY_IMAGE)
    if not okay2:
        print "Unable to retrieve Gray Image from device"
        break
    cv2.imshow("depth camera", depth_map)
    cv2.imshow("rgb camera", gray_image)
    if cv2.waitKey(10) == 27:
        break
cv2.destroyAllWindows()
capture.release()

So everything runs fine, but the results that are being displayed are not the correct channels... For example if I wanted to access the gray image channel and the depth map channel, both images being displayed are depth_maps. 因此,一切运行正常,但是显示的结果不是正确的通道...例如,如果我要访问灰色图像通道和深度图通道,则显示的两个图像都是depth_maps。

Yes I've tried accessing other channels and changing the OPENNI_IMAGE_GENERATOR_MODE. 是的,我尝试访问其他频道并更改OPENNI_IMAGE_GENERATOR_MODE。 Unfortunately the results have stayed consistent. 不幸的是,结果一直保持一致。 No matter what I try I always get the same depth channel back. 无论我尝试什么,我总是会得到相同的深度通道。 depth_map-gray_image yields an all black image. depth_map-gray_image产生全黑图像。

Like I said the C++ OpenCV OpenNI examples all work perfectly for both the Kinect sensor and primesense sensor. 就像我说的那样,C ++ OpenCV OpenNI示例对于Kinect传感器和质感传感器都非常适用。 It seems like a problem with the Python modules, or I am doing something really stupid. Python模块似乎有问题,或者我做的事情确实很愚蠢。

EDIT: Running on Ubuntu 12.04 LTS 编辑:在Ubuntu 12.04 LTS上运行

Thanks for helping. 感谢您的帮助。 Drew 德鲁

Retrieve looks like this ( http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-retrieve ): 检索看起来像这样( http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-retrieve ):

Python: cv2.VideoCapture.retrieve([ image [, channel]]) → retval, image Python:cv2.VideoCapture.retrieve([ image [,channel]])→retval,image

So you need two values to pass to retrieve. 因此,您需要传递两个值才能进行检索。

I'm not sure what image is supposed to be, but sending in a place holder seems to do the trick. 我不确定应该是什么图像,但是发送占位符似乎可以解决问题。


okay1, depth_map = capture.retrieve( 0 , cv.CV_CAP_OPENNI_DEPTH_MAP) okay1,depth_map = capture.retrieve( 0 ,cv.CV_CAP_OPENNI_DEPTH_MAP)
okay2, gray_image = capture.retrieve( 0 , cv.CV_CAP_OPENNI_GRAY_IMAGE) okay2,gray_image = capture.retrieve( 0 ,cv.CV_CAP_OPENNI_GRAY_IMAGE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM