Flat point cloud output from disparity map

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Flat point cloud output from disparity map

karnik
This post was updated on .
Screenshot of the disparity image, original left image and pcl output

Hi!

I've been trying to generate a point cloud from a pair of rectified stereo images. I first obtained the disparity map using opencv's sgbm implementation. I then converted it to a point cloud using the following code,

for (int u=0; u < left.rows; ++u)
                {
                        for (int v=0; v < left.cols; ++v)
                        {
                                if(disp.at<int>(u,v)==0)continue;
                                pcl::PointXYZRGB p;
                                p.x = v;
                                p.y = u;
                                p.z = (left_focalLength * baseLine * 0.01/ disp.at<int>(u,v));
                                std::cout << p.z << std::endl;
                                cv::Vec3b bgr(left.at<cv::Vec3b>(u,v));
                                p.b = bgr[0];
                                p.g = bgr[1];
                                p.r = bgr[2];
                                pc.push_back(p);
                        }
                }

left is the left image, disp is the output disparity image in cv_16s.
Is my disparity to pcl conversion correct or is it a problem with the disparity values?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Flat point cloud output from disparity map

Arka Sadhu
Is that cmu problem statement by any chance? 

I created a re-projection matrix for this. And then used that matrix in the reprojectImageTo3D (opencv function). Also you might want to change the CV_16S to float to get more precision.

On Sat, Jan 7, 2017 at 8:37 AM, karnik <[hidden email]> wrote:
<http://www.pcl-users.org/file/n4043689/13.png> Hi!

I've been trying to generate a point cloud from a pair of rectified stereo
images. I first obtained the disparity map using opencv's sgbm
implementation. I then converted it to a point cloud using the following
code,

for (int u=0; u < left.rows; ++u)
                {
                        for (int v=0; v < left.cols; ++v)
                        {
                                if(disp.at<int>(u,v)==0)continue;
                                pcl::PointXYZRGB p;
                                p.x = v;
                                p.y = u;
                                p.z = (left_focalLength * baseLine * 0.01/ disp.at<int>(u,v));
                                std::cout << p.z << std::endl;
                                cv::Vec3b bgr(left.at<cv::Vec3b>(u,v));
                                p.b = bgr[0];
                                p.g = bgr[1];
                                p.r = bgr[2];
                                pc.push_back(p);
                        }
                }

left is the left image, disp is the output disparity image in cv_16s.
Is my disparity to pcl conversion correct or is it a problem with the
disparity values?



--
View this message in context: http://www.pcl-users.org/Flat-point-cloud-output-from-disparity-map-tp4043689.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users



--
Arka Sadhu
Third Year Electrical 
Stab Web Manager
IIT Bombay

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Flat point cloud output from disparity map

karnik
Yes, it is

I originally started with your approach too but tried this out for its simplicity.
Any idea why this isn't working?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Flat point cloud output from disparity map

Arka Sadhu
Why have u multiplied by 0.01? Have you tried to see what z values you are getting? I think most z values are very close to each other. You might have some incorrect focal length or baseline. Try to change the factor of 0.01 I guess. 

On 07-Jan-2017 10:11, "karnik" <[hidden email]> wrote:
Yes, it is

I originally started with your approach too but tried this out for its
simplicity.
Any idea why this isn't working?



--
View this message in context: http://www.pcl-users.org/Flat-point-cloud-output-from-disparity-map-tp4043689p4043691.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Flat point cloud output from disparity map

karnik
I used opencv's calibrationMatrixValues function to get the values for focalLength and baseLine. It outputs them in mm so I scaled them to cm arbitarily
Loading...