isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
10.81k stars 2.24k forks source link

Convert 3D point cloud to image #1912

Open relnet1 opened 4 years ago

relnet1 commented 4 years ago

Hi, i have a XYZ point cloud and i want it to convert to image. For example to take all point in Z range form 0 to 0.5 m and make a image with pixel size 0,5mm. If there is no point make pixel white and is there is a point make pixel black. Is it posible to do it with Open3D (Sorry for my bad english)

yxlao commented 4 years ago

First, visualize the point cloud: http://www.open3d.org/docs/release/tutorial/Basic/pointcloud.html#Visualize-point-cloud.

Then, frames can be captured by capture_screen_float_buffer: http://www.open3d.org/docs/release/python_api/open3d.visualization.Visualizer.html?highlight=capture_screen_float_buffer.

If you'd like to do it in the background, try headless rendering: http://www.open3d.org/docs/release/tutorial/Advanced/headless_rendering.html?highlight=headless

GnnrMrkr commented 4 years ago

Did the upper method work for you?

Alternatively, if you need an image with a certain resolution, camera parameters, or distortion coefficients, you can use another method:

First, create an (empty or white) array of the corresponding size. Then, project your whole point cloud into uv/image coordinates by using OpenCVs cv.projectPoints(). Then you can iterate over your array and check each cell if there is a point in it. If yes: Paint that pixel black. (Also, you could average all points and create a depth map like this.)

This method should give you some more flexibility to adjust your parameters (like the pixel size). I just implemented something similar, so feel free to ask if you have any further struggles on that.

relnet1 commented 4 years ago

Hi, Yes, the first answer was very helpful. The method did exactly was I asked for. However, I am still struggling with it. I need image for some operations (Hough transform) and then remove point from original point cloud. So I am need information about coordinates (which point is in which pixel). I have tried OpenCV, but I am really beginner, I cant get it working.

qaler commented 3 years ago

Do you want to create a 2D image or 3D image (volume) from point cloud?

miroslavradojevic commented 3 years ago

The answer above does the job However I could not get to fix the color in the exported rendering, so that points are not colored based on colormap along X,Y, or Z values. I would like to make all points fixed color and independent of the X,Y or X value of the point. Here is the snippet:

pcd = o3d.io.read_point_cloud("file.pcd", format="pcd")
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.get_render_option().point_color_option = o3d.visualization.PointColorOption.Color
vis.get_render_option().point_size = 3.0
vis.add_geometry(pcd)
vis.capture_screen_image("file.jpg", do_render=True)
vis.destroy_window()

Changing the options for vis.get_render_option().point_color_option cannot make it render in single color and coordinate-independent. Does anyone have an advice? @yxlao

vinodrajendran001 commented 2 years ago

Did the upper method work for you?

Alternatively, if you need an image with a certain resolution, camera parameters, or distortion coefficients, you can use another method:

First, create an (empty or white) array of the corresponding size. Then, project your whole point cloud into uv/image coordinates by using OpenCVs cv.projectPoints(). Then you can iterate over your array and check each cell if there is a point in it. If yes: Paint that pixel black. (Also, you could average all points and create a depth map like this.)

This method should give you some more flexibility to adjust your parameters (like the pixel size). I just implemented something similar, so feel free to ask if you have any further struggles on that.

Can I get an example python code snippet for this approach?

jyh100 commented 2 years ago

See the pointcloud2orthoimage tool https://www.yuhanjiang.com/research/FM/PC/P2I