I'm currently working on an assignment, consisting of camera calibration, stereo-calibration and finally stereo matching. For this I am allowed to use the available OpenCV samples and tutorials and adapt them to our needs. While the first two parts weren't much of a problem, a Question about the stereo matching part:
We should create a colored point cloud in .ply format from the disparity map of two provided images. I'm using this code as a template: https://github.com/opencv/opencv/blob/master/samples/cpp/stereo_match.cpp I get the intrinsic and extrinsic files from the first two parts of the assignment.
My question is, how to get the corresponding color for each 3D-point from the original images and the disparity map?
I'm guessing that each coordinate of the disparity map corresponds to a pixel both input-images share. But how to get those pixelvalues?
EDIT: I know that the value of each element of the disparity map represents the disparity the corresponding pixel between the left and right image. But how do I get the corresponding pixels from the coordinates of the disparity map? Example: my disparity value at coordinates (x, y) is 128. 128 represents the depth. But how do I know which pixel in the original left or right image this corresponds to?
Additional Questions I'm having further questions about StereoSGBM and which parameters make sense. Here are my (downscaled for upload) input-images:
left:
right
Which give me these rectified images:
left
right
From this I get this disparity image:
For the disparity image: this is the best result I could achieve using blocksize=3 and numDisparities=512. However I'm not at all sure if those parameters make any sense. Are these values sensible?
Example: my disparity value at coordinates (x, y) is 128. 128 represents the depth.
This is not correct. Depth is inversely proportional to disparity. You will have to do another set of calculations to obtain the depth from the disparity map obtained from opencv. The matching pixel locations you are looking for are usually not exposed in any APIs I have worked with. Do read up the semi global matching paper written by Hirshmueller to better understand how the matching actually happens. – cplusplusrat