【发布时间】:2020-11-18 23:30:29
【问题描述】:
我正在尝试使用 OpenCV 使鱼眼图像不失真。我从相机的内存中获得了相机矩阵和畸变系数。我假设它们是准确的。正如您在下面的代码中看到的,我使用的是cv::fisheye::undistortImage。我发现这个 GitHub Issue post 声称它应该可以工作,但是,未失真的图像框架看起来不正确!所以,很明显有些东西不起作用。
代码如下:
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/core/mat.hpp>
int main()
{
cv::Mat cameraMatrix = cv::Mat(3,3, CV_64F, double(0));
cv::Mat distortionCoeffs = cv::Mat(1,4, CV_64F, double(0));
cameraMatrix.at<double>(0, 0) = 286.7037963867188;
cameraMatrix.at<double>(0, 1) = 0;
cameraMatrix.at<double>(0, 2) = 413.3463134765625;
cameraMatrix.at<double>(1, 0) = 0;
cameraMatrix.at<double>(1, 1) = 286.7817993164062;
cameraMatrix.at<double>(1, 2) = 397.1785888671875;
cameraMatrix.at<double>(2, 0) = 0;
cameraMatrix.at<double>(2, 1) = 0;
cameraMatrix.at<double>(2, 2) = 1;
distortionCoeffs.at<double>(0,0) = -0.01078350003808737;
distortionCoeffs.at<double>(0,1) = 0.04842806980013847;
distortionCoeffs.at<double>(0,2) = -0.04542399942874908;
distortionCoeffs.at<double>(0,3) = 0.008737384341657162;
cv::Mat input_frame = cv::imread("fisheye_input.png");
cv::Mat output_frame;
cv::fisheye::undistortImage(input_frame,output_frame,cameraMatrix,distortionCoeffs, cv::noArray(), cv::Size(input_frame.cols,input_frame.rows));
cv::imshow("Input Image", input_frame);
cv::imshow("Output Image", output_frame);
cv::waitKey(-1);
return 0;
}
代码输出:
如果您想自己尝试一下,这里是原始鱼眼图像:
【问题讨论】:
-
This 一个似乎工作
标签: c++ opencv image-processing fisheye