详细解释opencv中的畸变校正数学模型







include <opencv2/opencv.hpp>
include
int main() {
// 1. 模拟标定得到的内参和畸变系数(你的小视场场景)
cv::Mat cameraMatrix = (cv::Mat_
800.0, 0.0, 320.0, // fx=800, cx=320
0.0, 800.0, 240.0, // fy=800, cy=240
0.0, 0.0, 1.0);
// 畸变系数:k1=0.01(低阶径向),k2=k3=p1=p2=0(你的极简模式)
cv::Mat distCoeffs = (cv::Mat_
// 2. 待校正的畸变像素点(模拟边缘点)
cv::Point2f distortedPoint(400, 300); // 畸变后的像素点
cv::Point2f undistortedPoint;
// 3. OpenCV内置校正函数(底层就是上述迭代求解)
cv::undistortPoints(
distortedPoint, undistortedPoint,
cameraMatrix, distCoeffs,
cv::noArray(), cameraMatrix // 最后一个参数:直接映射到无畸变像素坐标
);
// 输出结果
std::cout << "畸变像素点:" << distortedPoint << std::endl;
std::cout << "校正后像素点:" << undistortedPoint << std::endl;
// 4. 整幅图像校正(实际应用)
cv::Mat distortedImage = cv::imread("distorted_img.jpg"); // 畸变图像
cv::Mat undistortedImage;
cv::undistort(distortedImage, undistortedImage, cameraMatrix, distCoeffs);
cv::imwrite("undistorted_img.jpg", undistortedImage);
return 0;
}


浙公网安备 33010602011771号