I'm having a bear of a time getting up and running with Pyrealsense2 python bindings as part of the Intel RealSense SDK v2.7.9 release (with the ultimate goal of using it with OpenCV 3.3's python bindings). I can't seem to find much actual documentation on use and almost no examples. Generally, because the bindings are advertised as Cython wrappers I assume that less some obvious syntactical differences any C++ example should work using the python wrappers. I've already run into three issues I can't figure out doing this and would be very grateful if anyone reading this can help me out a bit (or point me in the right direction)!
Colorize Doesn't Colorize:
Using the following snippet adapted from the simple example in the repo:
# First import the library import numpy as np import cv2 import pyrealsense2 as rs2 c = rs2.colorizer() # Create a context object. This object owns the handles to all connected # realsense devices pipeline = rs2.pipeline() pipeline.start() while True: # This call waits until a new coherent set of frames is available on a # device. Calls to get_frame_data(...) and get_frame_timestamp(...) on a # device will return stable values until wait_for_frames(...) is called. frames = pipeline.wait_for_frames() color = frames.get_color_frame() depth = frames.get_depth_frame() if (not depth) or (not color): print("Color or Depth not available!") break depth_RGB = c.colorize(depth) depth_img = np.asanyarray(depth_RGB.get_data()) # Show the image in a new window cv2.namedWindow("Depth",cv2.WINDOW_NORMAL) cv2.resizeWindow("Depth",640,480) cv2.imshow("Depth",depth_img) cv2.waitKey(0)
I get an image that looks something like below. It's limited to a reduced ROI in the full depth sensor field of view, "squashed" vertically, and certainly not re-colorized into 3 channel RGB of BGR.
Can't Discard Null Frame References:
In the same script I have the issue that the color frame stream always returns null frame references and the depth frame stream sometimes does as well. When this happens the statement `if (not depth) or (not color): break` is unsuccessful at preventing get_data from throwing an exception with `RuntimeError: null pointer passed for argument "frame_ref"`
No Implementation of Align:
A look at python.cpp seems to suggest that the python bindings do not implement the equivalent of rs2::context.create_align(RS2_STREAM_COLOR) as shown in the align C++ example. Is that the case, is this planned for future implementation?
I'm getting the sense it might be a better idea to work with librealsense exclusively in C++ to write a subroutine for frame grabbing, alignment transformation, and processing/clipping that called from a python environment with numpy and the OpenCV python bindings. Does that sound right?
|Operating System Version||Ubuntu 16.04 LTS|
|Kernel Version||4.10.0-35-generic (UVC Patched)|