我使用OpenCV的相机校准示例代码来校准相机。然后想要纠正一些图像上的失真。我用这段代码来消除失真。它有效,但鱼眼视图仍然存在。如何在没有鱼眼的情况下消除失真后得到图像?输入图像没有鱼眼。
以下是代码:
#include <opencv\cxcore.h>
#include <opencv2/calib3d.hpp>
#include <conio.h>
#include<math.h>
#include<windows.h>
#include <fstream>
#include<vector>
#include <stdlib.h>
#include<dirent.h>
#include<string.h>
#include <algorithm> // for std::copy
using namespace std;
using namespace cv;
int main(){
Mat src, gray;
//remove distortion in the image (after calibration)
Mat undistorted;
//Size1280x720;
Size imageSize(1280,720);
cv::Mat image=imread("C:/Test/4.png");
Mat view, rview, map1, map2;
Mat cameraMatrix = (Mat1d(3, 3) << 8.5033354550764898e+002, 0, 640, 0, 8.5033354550764898e+002, 360, 0, 0, 1);
Mat distCoeffs = (Mat1d(1, 5) << -0.3, 2.8770882755049054e-001, 0, 0, -1.4405356460809188e-001);
initUndistortRectifyMap(
cameraMatrix, distCoeffs, Mat(),
getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0), imageSize,
CV_16SC2, map1, map2);
// apply mapping functions
cv::remap(image, undistorted, map1, map2, INTER_LINEAR); // interpolation type
imshow("gg",undistorted);
while(uchar(waitKey(1))!='Q');
return 0;
}
有任何帮助吗?谢谢!