用于OpenCV的PyOpenNI输入

时间:2013-01-21 11:19:55

标签: python kinect openni xt

我在Python中使用 OpenCV 。我想从华硕Xtion获得输入。 我能够成功运行PyOpenNI的样本。 我想在opencv中使用igen.get_synced_image_map_bgr()获得的图像(str格式)。

IGEN-ImageGenerator

我想将其转换为IplImage。 我怎么能这样做,或者如何在Opencv python代码中使用深度传感器的输入。

1 个答案:

答案 0 :(得分:0)

我最近在PyOpenNI中使用了Kinect的字符串格式深度数据和OpenCV。使用可以从字符串创建的numpy数组,它们是Python的cv2(OpenCV)中的默认数据类型。

此处的代码示例:http://euanfreeman.co.uk/pyopenni-and-opencv/

不确定Kinect与深度传感器的区别,但这可能是一个有用的起点。祝好运!

编辑:添加代码

from openni import *
import numpy as np
import cv2

# Initialise OpenNI
context = Context()
context.init()

# Create a depth generator to access the depth stream
depth = DepthGenerator()
depth.create(context)
depth.set_resolution_preset(RES_VGA)
depth.fps = 30

# Start Kinect
context.start_generating_all()
context.wait_any_update_all()

# Create array from the raw depth map string
frame = np.fromstring(depth.get_raw_depth_map_8(), "uint8").reshape(480, 640)

# Render in OpenCV
cv2.imshow("image", frame)