Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create color point cloud from disparity #12901

Closed
Toaster0617 opened this issue May 7, 2024 · 5 comments
Closed

How to create color point cloud from disparity #12901

Toaster0617 opened this issue May 7, 2024 · 5 comments
Labels

Comments

@Toaster0617
Copy link

Required Info
Camera Model {D400}
Firmware Version (Open RealSense Viewer --> Click info)
Operating System & Version Win10
Platform PC
SDK Version { legacy / 2... }
Language {python/opencv}
Segment {Robot/VR}

Hi. I'm quite new to using pyrealsense2 library. I having trouble in convert disparity to color point cloud using opencv function (eg. reprojectImageTo3D function).

I've already get my disparity value by using method in #8572 but my disparity value lies between 0 to 65535. So did I need to scale or convert my result so that it can be used for generate color point cloud by using opencv?

Here is the image I get
dis

@MartyG-RealSense
Copy link
Collaborator

Hi @Toaster0617 You could convert the RealSense 16-bit uint16_t 'pixel depth value' (which ranges from 0 to 65535) to OpenCV's range of 0-255 by converting the depth value to the OpenCV format CV_16UC1. The #8572 case that you quoted has an example of such a conversion in one of its scripts, at #8572 (comment)

disparity = data.view(np.uint16).reshape((imageH, imageW))

If disparity values are not vital to your project then an alternative approach for obtaining a colorized point cloud with OpenCV code could be the librealsense SDK's opencv_pointcloud_viewer.py pyrealsense2 example program.

https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/opencv_pointcloud_viewer.py

image

@Toaster0617
Copy link
Author

@MartyG-RealSense Thanks for your help! Does this mean that I only need to convert my data format to 16-bit and scale it to 0-255?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 7, 2024

My understanding is that after RealSense data is converted from 16-bit uint16_t to an OpenCV format such as CV_16UC1 then its scale is automatically adjusted without you having to rescale the depth values yourself.

@Toaster0617
Copy link
Author

@MartyG-RealSense Thanks for your response! I can solve my problem now!

@MartyG-RealSense
Copy link
Collaborator

Case closed due to solution achieved and no further comments received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants