# OpenCV使用Matlab生成的畸变系数做图像修正

Matlab中是CamPoints = undistortPoints(distortedCamPoints, params);

Matlab相机标定函数生成的cameraParam即上面的params是一个很大的变量，把相机有关的所有参数都包含在内了。问题是这个函数无法通过Matlab coder导出。

pixelX = x * focal length x + principal point x

pixelY = y * focal length y + principal point y

vector<Point2f>  distortPoints, unDistortPoints;
distortPoints.push_back(Point2f(711.13, 631.42));

Mat cameraMatrix = Mat::eye(3, 3, CV_32F);
cameraMatrix.at<float>(0, 0) = 7.8818e+03;
cameraMatrix.at<float>(0, 1) = 0;
cameraMatrix.at<float>(0, 2) = 1.3083e+03;
cameraMatrix.at<float>(1, 1) = 7.89e+03;
cameraMatrix.at<float>(1, 2) = 1.1996e+03;

Mat distCoeffs = Mat::zeros(5, 1, CV_32F);
distCoeffs.at<float>(0, 0) = -0.2363;              //k1, radial distortion
distCoeffs.at<float>(1, 0) = -0.9046;              //k2, radial distortion
distCoeffs.at<float>(2, 0) = 0;                        //p1, tangential distortion
distCoeffs.at<float>(3, 0) = 0;                        //p2, tangential distortion
distCoeffs.at<float>(4, 0) = 0;                        //k3, radial distortion

undistortPoints(distortPoints, unDistortPoints, cameraMatrix, distCoeffs);
unDistortPoints[0].x = unDistortPoints[0].x * cameraMatrix.at<float>(0, 0) + cameraMatrix.at<float>(0, 2);
unDistortPoints[0].y = unDistortPoints[0].y * cameraMatrix.at<float>(1, 1) + cameraMatrix.at<float>(1, 2);

12-01
06-07
04-22
06-07 2万+
03-28 8965
01-13 2895
01-14 842
10-14 1627
06-12 5568
09-21 2万+
10-27 1万+
07-27 4347