【问题标题】:OpenCV - store camera matrix and distortion coefficients as MatOpenCV - 将相机矩阵和失真系数存储为 Mat
【发布时间】:2016-03-05 13:07:33
【问题描述】:

我使用示例 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 指定一系列行和列,然后为每个值分配一个索引?

【问题讨论】:

  • 所以你需要知道如何创建一个包含一些值的矩阵?或者如何从 xml 中加载一个矩阵?
  • 我只需要知道如何将这些值应用到它们各自的变量中,以便在undistort 函数中使用。第一种方法就足够了。
  • 检查herehere 参数的顺序(如果你还没有)。然后您可以创建一个矩阵,如:Mat cameraMatrix = (Mat1d(3, 3) << fx, 0, cx, 0, fx, cx, 0, 0, 1);
  • 谢谢,我需要为distortionCoefficients提供什么参数来代替(3,3)
  • (1, N),其中N 是 4、5 或 8

标签: c++ opencv matrix camera-calibration


【解决方案1】:

您可以在 undistort 的 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);

distortionCoefficients 是一个向量或 4、5 或 8 个参数:

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 documentation上找到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 2013-06-09
    • 2013-12-26
    • 2012-07-17
    • 2013-10-15
    相关资源
    最近更新 更多