Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

convert depth image to pcd

Open hua-wu-que opened this issue 8 years ago • 12 comments

i wonder if there is an existing function that can convert a depth image into point cloud format (.pcd), given the camera intrinsic matrix?

hua-wu-que avatar Jul 27 '18 17:07 hua-wu-que

Yes. Please check this tutorial: http://open3d.org/docs/tutorial/Basic/rgbd_images/redwood.html In short, what you looking for is something like:

    color_raw = read_image("../../TestData/RGBD/color/00000.jpg")
    depth_raw = read_image("../../TestData/RGBD/depth/00000.png")
    rgbd_image = create_rgbd_image_from_color_and_depth(
        color_raw, depth_raw); 
    pcd = create_point_cloud_from_rgbd_image(rgbd_image, PinholeCameraIntrinsic(
            PinholeCameraIntrinsicParameters.PrimeSenseDefault))
    draw_geometries([pcd])

syncle avatar Jul 27 '18 17:07 syncle

great! but could i create a pcd without the rgb image?

hua-wu-que avatar Jul 27 '18 17:07 hua-wu-que

Oh, I see the point. Then try using create_point_cloud_from_depth_image. The modified example code will be

    depth_raw = read_image("../../TestData/RGBD/depth/00000.png")
    pcd = create_point_cloud_from_rgbd_image(depth_raw, PinholeCameraIntrinsic(
            PinholeCameraIntrinsicParameters.PrimeSenseDefault))
    draw_geometries([pcd])

Definition is here. https://github.com/IntelVCL/Open3D/blob/35be432d45bf47bbcdf920c62d7d9d446ac6d36d/src/Core/Geometry/PointCloudFactory.cpp#L100-L104.

syncle avatar Jul 27 '18 17:07 syncle

This is exactly the function i am looking for! Thank you!

hua-wu-que avatar Jul 27 '18 18:07 hua-wu-que

Yes. Please check this tutorial: http://open3d.org/docs/tutorial/Basic/rgbd_images/redwood.html In short, what you looking for is something like:

    color_raw = read_image("../../TestData/RGBD/color/00000.jpg")
    depth_raw = read_image("../../TestData/RGBD/depth/00000.png")
    rgbd_image = create_rgbd_image_from_color_and_depth(
        color_raw, depth_raw); 
    pcd = create_point_cloud_from_rgbd_image(rgbd_image, PinholeCameraIntrinsic(
            PinholeCameraIntrinsicParameters.PrimeSenseDefault))
    draw_geometries([pcd])

i tried the same code but its giving me black and white pcd? ... can you explain why ? ... i want to create colored pcd using rgb and depth image taken with RealSense D415

Resays avatar Sep 16 '19 06:09 Resays

@Resays

i tried the same code but its giving me black and white pcd? ... can you explain why ?

create_from_color_and_depth() converts an RGB image to an intensity image.

i want to create colored pcd ...

After creating a black and white pcd, change pcd's colors:

rgb_vector = np.reshape( rgb_image, [-1, 3])
pcd.colors = o3d.utility.Vector3dVector(rgb_vector)

makashy avatar Oct 02 '19 11:10 makashy

Note that you can pass convert_rgb_to_intensity=False to create_from_color_and_depth() to avoid converting to intensity values.

griegler avatar Oct 02 '19 11:10 griegler

You're right, but then how should PointCloud.create_from_rgbd_image() be configured to create a point cloud from the RGB-D? It creates 0 points when I pass convert_rgb_to_intensity=False to create_from_color_and_depth().

makashy avatar Oct 02 '19 12:10 makashy

Hi i am getting error pcd = create_point_cloud_from_rgbd_image(depth_raw, PinholeCameraIntrinsic( ^ IndentationError: unexpected indent

Harsha0279 avatar Jun 18 '20 06:06 Harsha0279

Thanks for the pointer @griegler. I hit the same problem recently, and I found that it's a bit counter intuitive to get an intensity pointcloud by default given a pair of RGB and depth images. As you mentioned, I added convert_rgb_to_intensity=False as an arg and finally I got a colorized pointcloud I wanted.

Is it possible to make the colored pointcloud by default with a flag to convert that to intensity? If not, I think ~~more specific documentation on the API~~ (the page I checked is an older version of Open3d) or the tutorial will be extremely helpful.

zachfang avatar Aug 23 '20 21:08 zachfang

@theNded what are your thoughts on that?

griegler avatar Aug 24 '20 07:08 griegler

@syncle When I try it I get an error, could you please help how to fix?

    pcd = o3d.geometry.PointCloud.create_from_depth_image(original_depth_frame, color_intrinsics)
    pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
    print(np.asarray(pcd.points)[1, :])  
    o3d.visualization.draw_geometries([pcd])

Also, when using o3d, I get this error:

    create_from_depth_image(): incompatible function arguments. The following argument types are supported:
        1. (depth: open3d::geometry::Image, intrinsic: open3d.cuda.pybind.camera.PinholeCameraIntrinsic, extrinsic: numpy.ndarray[float64[4, 4]] = array([[1., 0., 0., 0.],
           [0., 1., 0., 0.],
           [0., 0., 1., 0.],
           [0., 0., 0., 1.]]), depth_scale: float = 1000.0, depth_trunc: float = 1000.0, stride: int = 1, project_valid_depth_only: bool = True) -> open3d.cuda.pybind.geometry.PointCloud

Also, documented my question in Stackoverflow: https://stackoverflow.com/questions/65930029/visualizing-the-pointcloud-from-realsense-api-or-open3d-library

monacv avatar Jan 28 '21 02:01 monacv