首页 > 解决方案 > Python OpenCV calibrateCamera:objectPoints 应包含 Point3f 类型点的向量向量

问题描述

我想从一些编码标记的图片坐标和对象坐标计算相机校准参数。

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(points, centers, gray.shape[::-1], None, None)

但我收到以下错误:

objectPoints should contain vector of vectors of points of type Point3f in function 'cv::collectCalibrationData'

这让我很困惑,因为对象点是这样实现的:

points=np.float32([[7.8, 4.9, 0], [5.2, 4.9, 0], [7.8, 7.35, 0], [5.2, 7.35, 0], [2.6, 7.35, 0],[10.4, 0, 0],...])

根据控制台打印和 np.shape 的尺寸,它们似乎是 mx3-matrix

[[ 7.8   4.9   0.  ]
 [ 5.2   4.9   0.  ]
 [ 7.8   7.35  0.  ]
 [ 5.2   7.35  0.  ]
 [ 2.6   7.35  0.  ]
 [10.4   0.    0.  ]
...]

(20, 3)

我的图像点是从一些 Aruco 标记计算出来的,看起来像这样:

[[2639.   1826.5 ]
 [2265.5  1820.5 ]
 [2638.75 1480.  ]
 [2269.   1475.25]
 [1898.   1470.5 ]
 [3024.   2551.25]
...]
(20, 2)

我知道共面对象点并不真正适合这项任务。我刚刚开始创建一些虚拟数据来弄清楚所有内容的语法:) 在此先感谢

标签: pythonopencvcamera-calibration

解决方案


答案很简单:

objpoints=[]
objpoints.append(points)

然后用 objpoints 而不是点调用 cv2.calibrateCamera

好吧,我的理智走了:)


推荐阅读