How can I convert cordinates from rectified stereo to original coordinates in opencv?

asked 2018-03-15 16:26:19 -0500

stiv-yakovenko gravatar image

I am using this code to rectify stereo pair of images:

stereoRectify(cm, Mat(), cm, Mat(),imageSize,
    0.9, imageSize, &validROI[0], &validROI[1]);

initUndistortRectifyMap(cm, Mat(), R1, P1, imageSize, CV_16SC2, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cm, Mat(), R2, P2, imageSize, CV_16SC2, rmap[1][0], rmap[1][1]);
remap(v1.img, rimg1, rmap[0][0], rmap[0][1], INTER_LINEAR);
remap(v2.img, rimg2, rmap[1][0], rmap[1][1], INTER_LINEAR);

Rectification works successfully.

Now I need to match each pixel (x,y) in rectified image rimg1 to initial pixel (x0,y0) in v1.img. How can I do it? Where can I get formulae, how to use P1 and R1? Thanx!

edit retag flag offensive close merge delete