0

I have first calibrated my cameras using the sample code in the opencv package (stereo_calib.cpp). Now I want to use this to rectify the images for stereo matching. I started out rectifying one image but i can't get it to work simply because initUndistortRectifyMap returns a map containing nothing. I can't find out what I'm doing wrong.

Mat ciml, cimr, iml, imr, imlCalibrated, imrCalibrated;
vector<KeyPoint> keyl, keyr, keyInPlane, keyMatched;

//-- Load Images and convert to gray scale
string filenamel = "img/imL2.png";
string filenamer = "img/imR2.png";

ciml = imread(filenamel, 0);
cvtColor(iml, ciml, CV_GRAY2BGR);
cimr = imread(filenamer, 0);
cvtColor(imr, cimr, CV_GRAY2BGR);
Size imageSize = iml.size();

//-- Load calibration matrices
FileStorage fs_in, fs_ex;
fs_in.open( "intrinsics.yml", FileStorage::READ );
fs_ex.open( "extrinsics.yml", FileStorage::READ );
Mat rmap[2][2], cameraMatL, cameraMatR, coeffMatL, coeffMatR, R1, R2, P1, P2;
fs_ex["R1"] >> R1;  fs_ex["R2"] >> R2;
fs_ex["P1"] >> P1;  fs_ex["P2"] >> P2;
fs_in["M1"] >> cameraMatL;  fs_in["M2"] >> cameraMatR;
fs_in["D1"] >> coeffMatL;   fs_in["D2"] >> coeffMatR;
cout << "camera Matrix: " << endl << cameraMatL << endl << endl;

//-- Find remap values
initUndistortRectifyMap(cameraMatL, coeffMatL, R1, P1, imageSize, CV_16SC2, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cameraMatR, coeffMatR, R2, P2, imageSize, CV_16SC2, rmap[1][0], rmap[1][1]);

ANSWER: It was very simple since the images didn't load the image size was zero and so the map was an empty matrix. Will post answer as soon as I can.

TobyHijzen
  • 129
  • 2
  • 15
  • Do you get 0x0 sized images in rmap or the value of the pixels in the map are 0? Note that the map(s) generated by initUndistortRectifyMap are to be used as parameters in function remap. This will do the actual distortion you want to see. I am not sure you have to use the second rmap parameter if you use the format CV_16SC2. – Bálint Fodor Mar 04 '13 at 12:11
  • I got 0x0 sized images. Because the images didn't load. Thanks for the help. Sorry to have asked such a simple question I just kept looking over the answer. – TobyHijzen Mar 04 '13 at 12:21

1 Answers1

1

It was very simple since the images didn't load the image size was zero and so the map was empty.

TobyHijzen
  • 129
  • 2
  • 15