Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top