I'm trying calculate depth map from disparity map in OpenCV, and then use this to create a point cloud with pcl.
I have a set of images from L and R which i use to calibrate cameras (using **calibrateCamera**, **stereoCalibrate**, **stereoRectify** and **initUndistortRectifyMap**). At this point i have two rectified images with parallel epipolar lines (a point in the L image is at the same y value of the same point in the R image).
At this point with **StereoSGBM** I find the disparity map (that tell me for every pixel in one image what is the difference between its position in the other image). Now i want from this disparity map find the depth map that tell me the z value of a point. Being in my case a pure translation i can (almost in theory) calculate it directly through the formula:
> Disparity = (Baseline * focal) / depth
so
> depth = (Baseline * focal) / disparity
Now I'm having some troubles with these parameters. Disparity is the value saved in my disparity map (in mm, pixels or what?)
I know that **calibrateCamera** returns a CameraMatrix with is a 3x3 with some infos like f_x f_y and c_x c_y. I know also that **stereoRectify** returns a transactional vector in which i can find my baseline.
Now what i want to do is to scan every pixel of the disparity map and calculate its correspondent value of the depth map and then use it to create a point cloud of the scene.
My question is how to find in openCV the true values of baseline and focal to use in the simple formula above. And what the metrics are?
Focal is in mm or pixel? What element of the translational vector baseline is?
And last question, if instead of using this formula I call **reprojectImageTo3d** is the result the same?
Thank you very much for the help
↧