相机标定:
解决方案:
1.使用opencv自带程序进行标定
2.使用matlab进行标定
问题分析:
1.使用camera_calibration样例程序进行标定。一边采集一边标定。实际测试误差非常大,无法使用。
2.使用matlab进行单目标定或双目标定。傻瓜式操作,像素误差小,实际测试效果非常好!
相机矫正测试代码
#include <iostream>
#include <sstream>
#include <string>
#include <ctime>
#include <cstdio>
#include <opencv2/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat cameraMatrix{589.731393699140, 0., 351.418746830309, 0., 589.625032910833, 238.750288368969, 0., 0., 1.};
cameraMatrix = cameraMatrix.reshape(0, 3);
cout << cameraMatrix.cols << endl;
cout << cameraMatrix.rows << endl;
Mat distCoeffs{-0.403335580708005, 0.179421396179879, 0., 0., 0.};
distCoeffs = distCoeffs.reshape(0, 5);
//*********************畸变矫正**************************
// 导入要矫正的图片
Mat test_image = imread("/home/user/code/cvcode/calib3d/camera_calibration/images/original.jpg");
Mat show_image;
undistort(test_image, show_image, cameraMatrix, distCoeffs, cameraMatrix);
imshow("result", show_image);
waitKey(-1);
}
参考:
linux安装matlab: https://blog.csdn.net/m0_37775034/article/details/80876362
matlab双目标定:
https://blog.csdn.net/weixin_43956351/article/details/94394892
https://blog.csdn.net/H_____H/article/details/103392167
opencv calibration: https://blog.csdn.net/Thomson617/article/details/103987952