#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<imgproc/imgproc.hpp>
#include<iostream>
using namespace cv;
using namespace std;
const int imageWidth = 2592;
const int imageHeight = 1944;//影像的尺寸
Size imageSize = Size(imageWidth, imageHeight);
Mat image;
Mat dst;
Mat cameraMatrix;
Mat distCoeffs;
Mat new_Matrix;
Mat view, rview, map1, map2;
double fx = 3.711083918716881e+03, fy = 3.746783973239024e+03, cx = 1.277862448956563e+03, cy= 1.074499653803534e+03;
double k1k2Distortion[2] = { -0.137182602576044 ,0.373025683414344 };
double p1p2p3Distortion[3] = { -0.005182048337687,-0.001036776592359,0 };
void paramterslnit();//將引數轉換為系數陣
void paramterslnit() {
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);//相機的內引數矩陣,不垂直因子為0;
cameraMatrix.at<double>(0, 0) = 3.711083918716881e+03;//fx
cameraMatrix.at<double>(0, 1) = 0;
cameraMatrix.at<double>(0, 2) = 1.277862448956563e+03;//cx;
cameraMatrix.at<double>(1, 0) = 0;
cameraMatrix.at<double>(1, 1) = 3.746783973239024e+03;//fy;
cameraMatrix.at<double>(1, 2) = 1.074499653803534e+03;//cy;
cameraMatrix.at<double>(2, 0) = 0;
cameraMatrix.at<double>(2, 1) = 0;
cameraMatrix.at<double>(2, 2) = 1;
Mat distCoeffs = Mat::zeros(1, 5, CV_64F);
distCoeffs.at<double>(0, 0) = k1k2Distortion[0];//k1;
distCoeffs.at<double>(0, 1) = k1k2Distortion[1];//k2;
distCoeffs.at<double>(0, 2) = p1p2p3Distortion[0];//p1;
distCoeffs.at<double>(0, 3) = p1p2p3Distortion[1];//p2;
distCoeffs.at<double>(0, 4) = p1p2p3Distortion[2];//k3;
}
int main() {
paramterslnit();
image= imread("1.png");
Size imageSize;
imageSize = image.size();
undistort(image, dst, cameraMatrix, distCoeffs, new_Matrix);
namedWindow("distort image", 0);
imshow("distort image", image);
namedWindow("undistort image", 0);
imshow("undistort image", dst);
imwrite("undistort image", dst);
waitKey(0);
system("pause");
return 0;
}
如上所示,這是我的代碼,影像的畸變矯正我用的是undistort函式,一運行就出現“未經處理的例外”問題,程式控制臺出現以下OpenCV(4.1.0) Error: Assertion failed (data) in cv::Mat_<double>::operator (), file c:\build\master_winpack-build-win64-vc15\opencv\modules\core\include\opencv2\core\mat.inl.hpp, line 1889,呼叫堆疊后的視窗如下
,不知道是什么原因,求大神賜教啊
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/256051.html
標籤:OpenCV
上一篇:ROS創建功能包
下一篇:matlab 向量長度必須一致
