-1

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

stereoRectify(cm, Mat(), cm, Mat(),imageSize,
    RT_d,tt,R1,R2,P1,P2,Q,CALIB_ZERO_DISPARITY,
    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!

Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206

1 Answers1

0

I've found out that you need to switch storage mode:

initUndistortRectifyMap(cm, Mat(), R1, P1, imageSize, CV_32FC1, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cm, Mat(), R2, P2, imageSize, CV_32FC1, rmap[1][0], rmap[1][1]);

and then you can get mapping that easy:

auto x0 = rmap[0][0].at<float>(Point(x, y));
auto y0 = rmap[0][1].at<float>(Point(x, y));
Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206