Commit c21631ea authored by Thiago Santini's avatar Thiago Santini

Initial fisheye calibration working

WARNING: USE WITH CARE

It's not exactly trivial to calibrate the pupil labs wide angle with
the fisheye model, but this parameter set seems to do the trick.
The undistorted image looks acceptable, and the marker depth also seems
to check out (does the marker pose estimation takes the fisheye model into
account or is this just a coincidence?).

Calibrating that camera with a pinhole model yields acceptable undistorted
images, but the marker depth is very innacurate.

Further tests are pending.
parent 874e7056
......@@ -124,7 +124,7 @@ void CameraCalibration::undistortSample(const Mat &frame)
return;
Mat tmp;
if (fishEyeCB->isChecked())
fisheye::undistortImage(frame, tmp, cameraMatrix, distCoeffs);
remap(frame, tmp, map1, map2, CV_INTER_AREA);
else
remap(frame, tmp, map1, map2, CV_INTER_AREA);
imshow("Undistorted Image", tmp);
......@@ -222,13 +222,20 @@ void CameraCalibration::calibrate()
Mat rv, tv;
if (fishEyeCB->isChecked()) {
rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rv, tv);
int fisheyeFlags = 0;
fisheyeFlags |= fisheye::CALIB_RECOMPUTE_EXTRINSIC;
fisheyeFlags |= fisheye::CALIB_CHECK_COND;
fisheyeFlags |= fisheye::CALIB_FIX_SKEW;
rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rv, tv, fisheyeFlags);
fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, distCoeffs, imageSize, Matx33d::eye(), newCameraMatrix, 1, imageSize);
fisheye::initUndistortRectifyMap(cameraMatrix, distCoeffs, Matx33d::eye(),
newCameraMatrix, imageSize, CV_16SC2,
map1, map2);
} else {
rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rv, tv);
newCameraMatrix = getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize);
initUndistortRectifyMap( cameraMatrix, distCoeffs, Mat(),
newCameraMatrix, imageSize, CV_32FC1,
newCameraMatrix, imageSize, CV_16SC2,
map1, map2
);
}
......@@ -245,6 +252,7 @@ void CameraCalibration::store(const QString &fileName)
fs << "sampleCount" << sampleCount;
fs << "coverage" << coverage;
fs << "rms" << rms;
fs << "fisheye" << fishEyeCB->isChecked();
}
void CameraCalibration::load(const QString &fileName)
......@@ -261,11 +269,19 @@ void CameraCalibration::load(const QString &fileName)
fs["sampleCount"] >> sampleCount;
fs["coverage"] >> coverage;
fs["rms"] >> rms;
bool isFisheye;
fs["fisheye"] >> isFisheye;
calibrationSuccessful = true;
initUndistortRectifyMap( cameraMatrix, distCoeffs, Mat(),
if (isFisheye) {
fisheye::initUndistortRectifyMap(cameraMatrix, distCoeffs, Matx33d::eye(),
newCameraMatrix, imageSize, CV_16SC2,
map1, map2);
} else {
initUndistortRectifyMap( cameraMatrix, distCoeffs, Mat(),
newCameraMatrix, imageSize, CV_32FC1,
map1, map2
);
}
}
updateCalibrationStatus(calibrationSuccessful);
}
......@@ -63,11 +63,10 @@ public:
squareSizeMMDSB->setToolTip(squareSizeMMDSB->whatsThis());
formLayout->addRow( new QLabel("Square Size:"), squareSizeMMDSB );
fishEyeCB = new QCheckBox();
// TODO: should fisheye be the default?
fishEyeCB->setChecked(false);
fishEyeCB->setWhatsThis("Use fish eye camera model instead of pinhole. Untested.");
fishEyeCB->setWhatsThis("Use fish eye camera model instead of pinhole.\nThis features is on alpha so use with care.");
fishEyeCB->setToolTip(fishEyeCB->whatsThis());
// TODO: test fish eye. Until then, disable it
fishEyeCB->setEnabled(false);
formLayout->addRow( new QLabel("Fish Eye"), fishEyeCB );
dbgCB = new QCheckBox();
dbgCB->setChecked(true);
......
......@@ -94,7 +94,11 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame)
data.collectionMarker = Marker();
data.markers.clear();
// Note that the following is based on the COLLECTION MARKER size.
// Note that the following is based on the COLLECTION MARKER size.
/* TODO: check whether the pose estimation works with fisheye intrinsic parameters
* An initial (and short) test with a pupil labs wide angle camera at 720p seeemed
* to match the distance measured with a laser distance meter.
*/
if (ids.size() > 0) {
if (data.undistorted) {
Mat emptyCameraMatrix = (Mat_<double>(3,3) <<
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment