首页 > 编程知识 正文

佳能镜头畸变校正,相机人像畸变校正

时间:2023-05-06 10:32:04 阅读:207968 作者:3376

#include using namespace std;

using namespace cv;

int test(int argc, char** argv)

{

VideoCapture capture(0);

while(1)

{

Mat frame;

capture >> frame;

Size image_size;

image_size = frame.size();

flip(frame, frame, 1);

Mat distortion = frame.clone();

Mat R = Mat::eye(3, 3, CV_32FC1);

Mat camera_matrix = Mat(3,3,CV_32FC1);

Mat distortion_coefficients;

导入相机内参和畸变系数矩阵

Mat mapx = Mat(image_size, CV_32FC1);

Mat mapy = Mat(image_size, CV_32FC1);

FileStorage file_storage("out_camera_data.yml", FileStorage::READ);

file_storage["camera_matrix"] >> camera_matrix;

file_storage["distortion_coefficients"]>>distortion_coefficients;

file_storage.release();

initUndistortRectifyMap(camera_matrix, distortion_coefficients, R, camera_matrix,

image_size, CV_32FC1, mapx, mapy);

//第一个参数cameraMatrix为之前求得的相机的内参矩阵;

//第二个参数distCoeffs为之前求得的相机畸变矩阵;

//第三个参数R,可选的输入,是第一和第二相机坐标之间的旋转矩阵;

//第四个参数newCameraMatrix,输入的校正后的3X3摄像机矩阵;

//第五个参数size,摄像机采集的无失真的图像尺寸;

//第六个参数m1type,定义map1的数据类型,可以是CV_32FC1或者CV_16SC2;

//第七个参数map1和第八个参数map2,输出的X / Y坐标重映射参数

remap(frame, distortion, mapx, mapy, INTER_LINEAR);

//第一个参数src,输入参数,代表畸变的原始图像;

//第二个参数dst,矫正后的输出图像,跟输入图像具有相同的类型和大小;

//第三个参数map1和第四个参数map2,X坐标和Y坐标的映射;

//第五个参数interpolation,定义图像的插值方式;

//第六个参数borderMode,定义边界填充方式

imshow("原图", frame);

imshow("校正图", distortion);

if (waitKey(30) > 0) break;

}

return 0;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。