Commit f4b4ff45 authored by Thiago Santini's avatar Thiago Santini

Small improvement to camera calibration

parent 4314e5a5
......@@ -220,26 +220,31 @@ void CameraCalibration::calibrate()
calculateBoardCorners(objectPoints[0]);
objectPoints.resize(imagePoints.size(),objectPoints[0]);
Mat rv, tv;
if (fishEyeCB->isChecked()) {
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_16SC2,
map1, map2
);
try {
Mat rv, tv;
if (fishEyeCB->isChecked()) {
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_16SC2,
map1, map2
);
}
calibrationSuccessful = true;
} catch (cv::Exception &e) {
qWarning() << "Calibration failed:" << e.what();
calibrationSuccessful = false;
}
calibrationSuccessful = true;
}
void CameraCalibration::store(const QString &fileName)
......
......@@ -471,7 +471,8 @@ void CameraWidget::onCameraCalibrationFinished(bool success)
return;
// TODO: at some point we might consider storing this with a unique camera ID instead of this generic one
QString fileName = gCfgDir + "/" + id + "Calibration.xml";
QMetaObject::invokeMethod(cameraCalibration, "store", Qt::QueuedConnection, Q_ARG(QString, fileName));
// Do the store here with a direct call to guarantee it will be done before the updateConfig
QMetaObject::invokeMethod(cameraCalibration, "store", Qt::DirectConnection, Q_ARG(QString, fileName));
QMetaObject::invokeMethod(imageProcessor, "updateConfig", Qt::QueuedConnection);
}
......
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