OpenCV-将相机矩阵和失真系数存储为Mat [英] OpenCV - store camera matrix and distortion coefficients as Mat
问题描述
我已经使用示例OpenCV程序从我的相机计算相机矩阵和失真系数,并生成了一个包含相关数据的xml文件。
I've used the sample OpenCV program to calculate the camera matrix and distortion coefficients from my camera and produced an xml file with the relevant data.
我试图通过 undistort
函数使用它,但是我不确定如何将值存储为 Mat
。 / p>
I'm trying to use it through the undistort
function but I'm not sure how to store the values as a 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,然后为每个值分配一个索引?
Do I need to try and specify a series of rows and columns to the Mat
var and then assign each value an index?
推荐答案
您可以在OpenCV文档中看到< a href = http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#undistort rel = noreferrer>取消注册,即:
You can see on OpenCV documentation for undistort that:
相机矩阵是3x3矩阵:
fx 0 cx
0 fy cy
0 0 1
您可以创建为:
Mat cameraMatrix = (Mat1d(3, 3) << fx, 0, cx, 0, fy, cy, 0, 0, 1);
distortionCoefficients 是矢量或4、5或8个参数:
distortionCoefficients is a vector or 4, 5, or 8 parameters:
k1, k2, p1, p2 [, k3 [, k4, k5, k6]]
您可以创建为:
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);
您可以在 OpenCV文档
这篇关于OpenCV-将相机矩阵和失真系数存储为Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!