2
votes

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);
                        }
                }][1]

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?

I've included a screenshot of the disparity map, point cloud and original left image.

Thank you!

screenshot

1

1 Answers

0
votes

I'm not confident with this language, but I noticed a thing:
Assuming that this line convert disparty to depth (Z)

p.z = (left_focalLength * baseLine * 0.01/ disp.at<int>(u,v));

What is 0.01? If this calculation gives you a range of depths (Z) from 1 to 10, this factor reduces your range from 0.01 to 0.1. Depth is always close to zero and you have a flat image (flat image = constant depth).

PS I do not see in your code X,Y conversion from u,v pixel values with Z value. Something like

X = u*Z/f