Python OpenCVcalibrateCamera: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,[7.8,7.35,[2.6,[10.4,...])

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

[[ 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)

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

解决方法

答案很简单:

objpoints=[]
objpoints.append(points)

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

好吧,我的神志清醒了:)