C++ OpenCV-将相机矩阵和失真系数存储为Mat

C++ OpenCV-将相机矩阵和失真系数存储为Mat,c++,opencv,matrix,camera-calibration,C++,Opencv,Matrix,Camera Calibration,我使用示例OpenCV程序从我的相机计算相机矩阵和失真系数,并生成一个包含相关数据的xml文件 我试图通过undistort函数使用它,但我不确定如何将值存储为Mat Mat cameraMatrix; Mat distortionCoefficients; undistort(image, newImage, cameraMatrix, distortionCoefficients); 我试过: Mat cameraMatrix = 1.7514028018776246e+03 0. 1.2

我使用示例OpenCV程序从我的相机计算相机矩阵和失真系数,并生成一个包含相关数据的xml文件

我试图通过
undistort
函数使用它,但我不确定如何将值存储为
Mat

Mat cameraMatrix;
Mat distortionCoefficients;
undistort(image, newImage, cameraMatrix, distortionCoefficients);
我试过:

Mat cameraMatrix = 1.7514028018776246e+03 0. 1.2635000000000000e+03 0. 1.7514028018776246e+03 9.2750000000000000e+02 0. 0. 1.;
Mat distortionCoefficients = 1.3287735059062630e-01 -6.8376776294978103e-01 0. 0. 8.1215478360827675e-01;

我是否需要尝试为
Mat
var指定一系列行和列,然后为每个值分配一个索引?

您可以在OpenCV文档中看到:

摄像机矩阵是一个3x3矩阵:

 fx   0  cx
  0  fy  cy
  0   0   1 
您可以创建为:

Mat cameraMatrix = (Mat1d(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
Mat distortionCoefficients = (Mat1d(1, 4) << k1, k2, p1, p2);
Mat distortionCoefficients = (Mat1d(1, 5) << k1, k2, p1, p2, k3);
Mat distortionCoefficients = (Mat1d(1, 8) << k1, k2, p1, p2, k3, k4, k5, k6);
您可以创建为:

Mat cameraMatrix = (Mat1d(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
Mat distortionCoefficients = (Mat1d(1, 4) << k1, k2, p1, p2);
Mat distortionCoefficients = (Mat1d(1, 5) << k1, k2, p1, p2, k3);
Mat distortionCoefficients = (Mat1d(1, 8) << k1, k2, p1, p2, k3, k4, k5, k6);

Mat-扭曲效率=(Mat1d(1,4)因此您需要知道如何创建具有某些值的矩阵?或者如何从xml加载矩阵?我只需要知道如何将这些值应用于各自的变量,以便在
undistort
函数中使用。第一种方法就足够了。请检查和以了解参数的顺序(如果您还没有)。然后您可以创建一个矩阵,如:
Mat cameraMatrix=(Mat1d(3,3)谢谢,我需要为
(3,3)
失真效率提供哪些参数?
(1,N)
,其中
N
是4、5或8