Commit cd6ca352 authored by Thiago Santini's avatar Thiago Santini

Adds rectified undistortion

parent e1518c6b
......@@ -124,9 +124,9 @@ void CameraCalibration::undistortSample(const Mat &frame)
return;
Mat tmp;
if (fishEyeCB->isChecked())
cv::fisheye::undistortImage(frame, tmp, newCameraMatrix, distCoeffs);
fisheye::undistortImage(frame, tmp, cameraMatrix, distCoeffs);
else
cv::undistort(frame, tmp, newCameraMatrix, distCoeffs);
remap(frame, tmp, map1, map2, CV_INTER_AREA);
imshow("Undistorted Image", tmp);
this->activateWindow();
this->setFocus();
......@@ -222,11 +222,15 @@ void CameraCalibration::calibrate()
Mat rv, tv;
if (fishEyeCB->isChecked()) {
rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rv, tv, 0);
fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, distCoeffs, imageSize, Matx33d::eye(), newCameraMatrix, 1);
rms = fisheye::calibrate(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rv, tv);
fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, distCoeffs, imageSize, Matx33d::eye(), newCameraMatrix, 1, imageSize);
} 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,
map1, map2
);
}
calibrationSuccessful = true;
}
......@@ -258,6 +262,10 @@ void CameraCalibration::load(const QString &fileName)
fs["coverage"] >> coverage;
fs["rms"] >> rms;
calibrationSuccessful = true;
initUndistortRectifyMap( cameraMatrix, distCoeffs, Mat(),
newCameraMatrix, imageSize, CV_32FC1,
map1, map2
);
}
updateCalibrationStatus(calibrationSuccessful);
}
......@@ -132,8 +132,11 @@ public:
cv::Mat cameraMatrix;
cv::Mat newCameraMatrix;
cv::Mat distCoeffs;
cv::Size imageSize;
cv::Rect covered;
int sampleCount;
double coverage;
double rms;
bool calibrationSuccessful;
signals:
......@@ -172,8 +175,7 @@ private:
QFutureWatcher<void> watcher;
std::vector<std::vector<cv::Point2f> > imagePoints;
cv::Size imageSize;
cv::Rect covered;
cv::Mat map1, map2;
void processSample(const cv::Mat &frame);
void undistortSample(const cv::Mat &frame);
......@@ -207,8 +209,6 @@ private:
}
}
double rms;
private slots:
void startCalibration();
void finishCalibration();
......
......@@ -104,7 +104,7 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame)
Mat emptyDistCoeffs = (Mat_<double>(1,4) << 0, 0, 0, 0);
estimatePoseSingleMarkers(corners, cfg.collectionMarkerSizeMeters, emptyCameraMatrix, emptyDistCoeffs, rvecs, tvecs);
} else
estimatePoseSingleMarkers(corners, cfg.collectionMarkerSizeMeters, cameraMatrix, distCoeffs, rvecs, tvecs);
estimatePoseSingleMarkers(corners, cfg.collectionMarkerSizeMeters, cameraMatrix, distCoeffs, rvecs, tvecs);
}
for (unsigned int i=0; i<ids.size(); i++) {
......@@ -167,9 +167,9 @@ void FieldImageProcessor::sanitizeCameraParameters(Size size)
FileStorage fs( QString(gCfgDir + "/" + id + "Calibration.xml").toStdString(), FileStorage::READ);
fs["cameraMatrix"] >> cameraMatrix;
fs["distCoeffs"] >> distCoeffs;
fs["imageSize"] >> imageSize;
bool haveCameraParameters = false;
fs["distCoeffs"] >> distCoeffs;
fs["imageSize"] >> imageSize;
bool haveCameraParameters = false;
if (!cameraMatrix.empty() && !distCoeffs.empty())
haveCameraParameters = true;
......@@ -200,7 +200,7 @@ void FieldImageProcessor::sanitizeCameraParameters(Size size)
cameraMatrix,
distCoeffs,
Mat(),
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 0, imageSize),
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize),
imageSize,
CV_32FC1,
map1,
......
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