Created
July 7, 2016 07:32
-
-
Save qlkvg/5f33b58469a552cc68a50380549f0951 to your computer and use it in GitHub Desktop.
viewing depth map from openni2 compatible device with opencv2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import cv2 | |
import numpy as np | |
from primesense import openni2 | |
from primesense import _openni2 as c_api | |
openni2.initialize("<PATH TO OPENNI2 REDIST FOLDER>") | |
dev = openni2.Device.open_any() | |
depth_stream = dev.create_depth_stream() | |
depth_stream.start() | |
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 640, resolutionY = 480, fps = 30)) | |
while True: | |
frame = depth_stream.read_frame() | |
frame_data = frame.get_buffer_as_uint16() | |
img = np.frombuffer(frame_data, dtype=np.uint16) | |
img.shape = (1, 480, 640) | |
img = np.concatenate((img, img, img), axis=0) | |
img = np.swapaxes(img, 0, 2) | |
img = np.swapaxes(img, 0, 1) | |
cv2.imshow("image", img) | |
cv2.waitKey(34) | |
openni2.unload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 9 and 10 must be swapped, otherwise it is not going to work.