Depth from Disparity

Hello,

i have 2 images from the same calibrated camera. I could rectify the images using the following snippet:

Mat H1, H2;
stereoRectifyUncalibrated(image_points[0], image_points[1], F, image1.size(), H1, H2);

warpPerspective(image1, image1_rectified, H1, image1.size());
warpPerspective(image2, image2_rectified, H2, image2.size());


image_points[0] and image_points[1] are the corresponding image points from image1 and image2 (calculated with SURF and then matched).

I also can calculate the disparity map with the two rectified images using StereoSGBM.

The next and last step would be to use

reprojectImageTo3D(image_disparity, XYZ, Q);


but i don't have the reprejection matrix Q.

Can someone describe me how to obtain this parameter?
I have the intrinsic camera matrix.

edit retag close merge delete

just to clarify:

i have 2 images from a calibrated camera.

that is, 2 images from the same camera ?

( 2017-03-06 05:41:54 -0500 )edit

yes, it is

( 2017-03-06 05:49:48 -0500 )edit

Sort by ยป oldest newest most voted

with a stereo cam setup, you would use stereoRectify() which would also return the Q matrix

lacking that, you could still try to build a synthetic Q mat (you can extract f from your camera intrinsic Mat)

more

1

Why i can't use stereoRectify() with my single camera setup? I mean it's like a stereo cam setup, just with the same camera. I just need to know the R, and t parameter for this funtion.

The Q mat what you linked looks a bit different than the one in the book "Learning OpenCV 3". There it says the Q mat looks like:

Q = [1, 0, 0,     -cx;
0, 1, 0,     -cy;
0, 0, 0,      f;
0, 0, -1/Tx, (cx-c'x)/Tx]

( 2017-03-06 06:16:09 -0500 )edit

what is Tx ?

( 2017-03-06 06:34:31 -0500 )edit

probably the "position" of the "first" camera

( 2017-03-06 06:37:29 -0500 )edit