Wednesday, August 13, 2014

Convert Point Cloud to Range Image to OpenCV Mat


source :
http://www.pcl-users.org/Convert-point-cloud-to-range-image-td4035137.html

Good tutorial

http://pointclouds.org/documentation/tutorials/project_inliers.php

Question:

HI,everyone, I'm trying to convert a 3d point cloud to a opencv mat. So here is my plan: 

1.convert the point cloud to a range image 

2.convert the range image to mat image 
Yet, I'm facing some problems, when I generate the range image by the example code with a terrain point cloud, it only gives me a very small window and nothing show up (other pcd file works). Is it because the pcd file too large? 

And is there any other way to convert the point cloud to opencv mat. Now I'm only caring about x,y data. So it's like a projection of point cloud and convert to a mat image. 


Thanks so much for your help~




Solution


If that is what you need it is exactly what you can do with the project 
inliers filter. 
http://docs.pointclouds.org/trunk/classpcl_1_1_project_inliers.html

just project the point cloud on the xy-Plane there is a tutorial for that: 
http://pointclouds.org/documentation/tutorials/project_inliers.php

after that you can the bounds of the plane by using pcl::getMinMax3D. 
Now you can define a top left and a bottom right corner (defining a rect) and 
compute a scale factor to match your image size. Say you want a 1000x1000px 
Image use 1000 / rect.width for x scale factor and 1000 / rect.height as y 
scale factor after that you can iterate over all points and set the 
corresponding pixels in the mat. cv::Mat::at(pt.x*scaleX, pt.y * scaleY) = 
pt.z After that you might have to to some interpolation to fill in the missing 
pixels and you have your opencv image. 

2 comments:

  1. Were you able to resolve the problem of not being able to display the range image? I am having the same problem.

    Ultimately, I would like to do the same thing you were attempting to do. Were you ever successful?

    ReplyDelete
  2. Its an incredible joy perusing your post. It's brimming with data I am searching for and I want to post a remark. Extraordinary post, an incredible site. Much obliged for the data! Best pointcloud Vancouver, BC

    ReplyDelete