给自己留个记录。
参考了这片文章,标定的参数由matlab给出,再到opencv中进行验证。
验证时的代码有所改动,原博客中使用视频,我改为图片。
#include <iostream>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <opencv2/ml.hpp>
using namespace std;
using namespace cv;
using namespace cv::ml;
int main()
{
Mat frame = imread("/root/桌面/IMG_3348.jpg");
Mat frameCalibration;
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
cameraMatrix.at<double>(0, 0) = 3374.07818952427;//从0开始计数
cameraMatrix.at<double>(0, 1) = -2.78181259296951;
cameraMatrix.at<double>(0, 2) = 2019.19661037399;
cameraMatrix.at<double>(1, 1) = 3374.34656463011;
cameraMatrix.at<double>(1, 2) = 1501.95020619850;
cameraMatrix.at<double>(2, 2) = 1;//原博客中没有这个,我也不知道为啥,加上去掉好像没有区别
Mat distCoeffs = Mat::zeros(5, 1, CV_64F);
distCoeffs.at<double>(0, 0) = 0.173230511639020;
distCoeffs.at<double>(1, 0) = -0.645138161101467;
distCoeffs.at<double>(2, 0) = -0.00109294300160736;
distCoeffs.at<double>(3, 0) = -3.47866401740176e-06;
distCoeffs.at<double>(4, 0) = 0;
Mat view, rview, map1, map2;
Size imageSize;
imageSize = frame.size();
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
imageSize, CV_16SC2, map1, map2);
remap(frame, frameCalibration, map1, map2, INTER_LINEAR);
namedWindow("Origianl",0);
namedWindow("Calibration",0);
imshow("Origianl", frame);
imshow("Calibration", frameCalibration);
waitKey(0);
return 0;
}
网友评论