我有一张扭曲的图像,它的主要点不在中心。我想使用 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);
undistort 已经消除了扭曲,但我不确定图像的主要点是否移动到中心。我选择函数 cv::getDefaultNewCameraMatrix
以移动主要点。现在的问题是中心是否在它应该在的地方。
Undistort 使用函数:cv::initUndistortRectifyMap()
及其在 documentation 中的数学描述当我插入我的值时不会产生结果。
现在的问题是:我可以使用 GetDefaultNewCameraMatrix
来移动主点吗?还有别的办法吗?我应该使用哪个函数?
另外,我如何检查我的主点是否移动到中心?
感谢您的帮助!
最佳答案
how could I check if my principal point moved to the center?
您可以在已知位置创建具有已知图案的自己的图像(例如,中心交点在 主点上的网格)。然后,您通过 undistort
函数发送此模拟图像,以查看已知图案是否移动到了正确的位置。
如果你想更进一步,你可以使用 projectPoints
投影你自己的模拟图像,你期望的失真,然后 undistort
它。然后您就可以控制整个过程,并且可以准确地看到畸变系数和主点如何影响您的图像。
Can I use GetDefaultNewCameraMatrix in order to shift the principal point? Is there another way? Which function should I use?
我认为 GetDefaultNewCameraMatrix
是在这里使用的错误函数。它将覆盖到图像中心的原则点(例如 [200,200] 用于大小 [400,400] 的图像)。
如果矩阵 projection_parameters
已经包含主点(例如来自 calibrateCamera
函数),则按原样将其发送到 undistort
。
像这样:
cv::undistort(input_image, output_image,cv_camera_matrix, cv_camera_matrix, distortion_coefficients);
undistort
函数应该正确处理主点并相应地平移图像。这就是构建函数的目的。
关于c++ - 使用 cv::undistort 取消扭曲和居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51826151/