使用 cv::不扭曲不失真和居中图像

Undistort and center image using cv::undistort

本文关键字:图像 cv 使用 失真      更新时间:2023-10-16

我有一个失真的图像,它的主点不在中心。我想使用 opencv 函数cv::undistort来摆脱失真。此外,我想将图像的主体移动到图像中心[size_x/2,size_y/2]的中心。

我目前所做的是:

//Creating the camera matrix with the parameters of the calibration algorithm (they are correct)
cv::Mat cv_camera_matrix = cv::Mat::zeros(3, 3, CV_64F);
cv_camera_matrix.at<double>(0,0) = projection_parameters[0]; //* incoming_image_ptr_mono8->image.cols;
cv_camera_matrix.at<double>(1,1) = projection_parameters[1]; //* incoming_image_ptr_mono8->image.rows;
cv_camera_matrix.at<double>(0,2) = projection_parameters[2]; //* incoming_image_ptr_mono8->image.cols;
cv_camera_matrix.at<double>(1,2) = projection_parameters[3]; //* incoming_image_ptr_mono8->image.rows;
cv_camera_matrix.at<double>(2,2) = 1;
//filling up of an array with the generated distortion parameters of the calibration algorithm (they are correct)
cv::Mat distortion_coefficients = cv::Mat::zeros(1, 4, CV_64F);
distortion_coefficients.at<double>(0,0) = undistortion_parameters[0];
distortion_coefficients.at<double>(0,1) = undistortion_parameters[1];
distortion_coefficients.at<double>(0,2) = undistortion_parameters[2];
distortion_coefficients.at<double>(0,3) = undistortion_parameters[3];
cv::undistort(input_image, output_image,cv_camera_matrix, cv::getDefaultNewCameraMatrix(cv_camera_matrix,input_image.size(),true),distortion_coefficients);

不失真已经消除了失真,但我不确定图像的主体点是否移动到中心。我选择函数cv::getDefaultNewCameraMatrix以转移主要点。现在的问题是,中心是否在它应该在的地方。

Undistort 使用函数:cv::initUndistortRectifyMap()当我插入我的值时,它在文档中的数学描述不会产生结果。

现在的问题是:我可以使用GetDefaultNewCameraMatrix来转移主要点吗?还有别的办法吗?我应该使用哪个功能?

另外,我如何检查我的主点是否移动到中心?

感谢您的帮助!

我如何检查我的主要点是否移动到中心?

您可以在已知位置(例如,在主点具有中心交点的网格(使用已知图案创建自己的图像。然后,通过undistort函数发送此模拟图像,以查看已知模式是否移动到正确的位置。

如果你想更进一步,你可以用你期望的失真投影你自己的模拟图像projectPoints,然后undistort它。然后,您可以控制整个过程,并且可以准确看到失真系数和原则点如何影响图像。

我可以使用 GetDefaultNewCameraMatrix 来移动主要点吗?还有别的办法吗?我应该使用哪个功能?

我认为GetDefaultNewCameraMatrix在这里使用的功能是错误的。它将覆盖图像中心的原则点(例如,对于大小为 [400,400] 的图像,则为 [200,200](。

如果矩阵projection_parameters已经包含原则点(例如,来自calibrateCamera函数(,则按原样将其发送到undistort

喜欢这个:

cv::undistort(input_image, output_image,cv_camera_matrix, cv_camera_matrix, distortion_coefficients);

undistort函数应正确处理原则点并相应地翻译图像。这就是构建函数的目的。