Last active
January 30, 2016 16:48
-
-
Save r9y9/e928a8115fb7b6cae4ae to your computer and use it in GitHub Desktop.
Similar one of Protonect in libfreenect2
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
# coding: utf-8 | |
import numpy as np | |
import cv2 | |
from pylibfreenect2 import Freenect2, FrameMap, SyncMultiFrameListener | |
from pylibfreenect2 import FrameType, Registration, Frame | |
from pylibfreenect2 import OpenGLPacketPipeline, CpuPacketPipeline | |
fn = Freenect2() | |
pipeline = OpenGLPacketPipeline() | |
device = fn.openDefaultDevice(pipeline=pipeline) | |
listener = SyncMultiFrameListener( | |
FrameType.Color | FrameType.Ir | FrameType.Depth) | |
# Register listeners | |
device.setColorFrameListener(listener) | |
device.setIrAndDepthFrameListener(listener) | |
device.start() | |
# NOTE: must be called after device.start() | |
registration = Registration(device.getIrCameraParams(), | |
device.getColorCameraParams()) | |
undistorted = Frame(512, 424, 4) | |
registered = Frame(512, 424, 4) | |
while True: | |
frames = listener.waitForNewFrame() | |
color = frames["color"] | |
ir = frames["ir"] | |
depth = frames["depth"] | |
registration.apply(color, depth, undistorted, registered) | |
cv2.imshow("ir", ir.asarray() / 65535.) | |
cv2.imshow("depth", depth.asarray() / 4500.) | |
cv2.imshow("color", cv2.resize(color.asarray(), (512, 424))) | |
cv2.imshow("registered", registered.astype(np.uint8)) | |
key = cv2.waitKey(delay=1) | |
if key == ord('q'): | |
break | |
device.stop() | |
device.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment