-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Point cloud generation from depth images #13434
Comments
Hi @Geada8 As your script is apparently not using pyrealsense2 (the RealSense Python wrapper), my first suspicion would be that the camera's infrared emitter component is not enabled. When the emitter is on, it projects light and an invisible pattern of infrared dots that helps to illuminate dimly lit scenes and analyze plain surfaces with no texture (like the walls and doors in your images) for depth information. Below is an example of pyrealsense2 code that enables the emitter component.
isl-org/Open3D#473 (comment) has an example of an Open3D pointcloud script that utilizes pyrealsense2. It would be necessary to install the RealSense pyrealsense2 wrapper to use this script if you have not done so already though. |
Unfortunately, the infrared emitter was already on and made no improvements. That code you mentioned uses older versions of Open3D, so even after some changes and help from ChatGPT, I wasn't able to make it work This part never worked:
The code I used when I started this issue works but with bad results so I tried adapting the one you mentioned to mix some things that I add that worked, but the problem kept happening and I wasn't able to create any point cloud. That adapted code probably is useless, but after many debugging steps, this is what I have:
Do you have any more suggestions? What can I do to improve my original results? |
There are few available references regarding creating a pointcloud with Open3D using a RealSense camera, unfortunately. #12090 is another reference that you could look at. |
Hi @Geada8 Do you require further assistance with this case, please? Thanks! |
I do not think I can improve the results this way any further, I am currently trying to implement point cloud registration with icp to remove some noise this way alongside the point cloud registration. If you have some code on that it would be apreciated, otherwise I'm good. |
In regard to using Open3D and ICP with a RealSense camera, isl-org/Open3D#362 should be a good entry point into the subject., with Python code at isl-org/Open3D#362 (comment) |
Hi @Geada8 Were the links in the comment above helpful to you, please? |
Hi @Geada8 Do you require further assistance with this case, please? Thanks! |
Case closed due to no further comments received. |
Issue Description
I'm trying to create a point cloud from depth images captured by a realsense camera, but the results are not very good.
Code
The code I'm using is the following:
import numpy as np
import cv2
import open3d as o3d
file_path = '...'
depth_image = cv2.imread(file_path, cv2.IMREAD_UNCHANGED)
if depth_image is None:
print(f"Error: Could not load depth image from {file_path}")
exit()
fx = 392.542 # Focal length x
fy = 392.542 # Focal length y
ppx = 323.578 # Principal point x
ppy = 240.324 # Principal point y
height, width = depth_image.shape
print("Depth min:", np.min(depth_image))
print("Depth max:", np.max(depth_image))
z = depth_image.astype(float) / 1000.0 # Convert from mm to meters, adjust if needed
x, y = np.meshgrid(np.arange(width), np.arange(height))
x_3d = (x - ppx) * z / fx
y_3d = (y - ppy) * z / fy
z_3d = z
points_3d = np.stack((x_3d, y_3d, z_3d), axis=-1).reshape(-1, 3)
points_3d = points_3d[z_3d.reshape(-1) > 0]
print(f"Total valid points: {points_3d.shape[0]}")
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points_3d)
o3d.io.write_point_cloud("pointcloud.ply", pcd)
print("Point cloud saved to pointcloud.ply")
o3d.visualization.draw_geometries([pcd], window_name="Point Cloud Visualization")
Results
Some examples of RGB images, depth and the corresponding point cloud :
Set 1
Set 2
Set 3
Set 4
Do you have any suggestions for what I can do to improve the results?
The text was updated successfully, but these errors were encountered: