简体   繁体   中英

PyOpenNI input for OpenCV

I'm working with OpenCV in Python. I want to get input from Asus Xtion . I'm able to successfully run samples from PyOpenNI . I want to use the image obtained (str format) by igen.get_synced_image_map_bgr() in opencv.

igen-ImageGenerator

I want to convert it to IplImage . How can I do it,or How can I otherwise use the input from the depth sensor in Opencv python code.

I recently used the string format depth data from Kinect in PyOpenNI with OpenCV. Use numpy arrays which can be created from strings and which are the default data type in cv2 (OpenCV) for Python.

Code example here: http://euanfreeman.co.uk/pyopenni-and-opencv/

Not sure how Kinect differs from your depth sensor but that may be a useful starting point. Good luck!

Edit: added code

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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