opencv solvePnP抛出错误:(-215:Assert失败)源大小==目标大小&&源通道()==目标通道()在函数'cvConvertScale'中

gjmwrych  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(120)

我有一个盒子的4个世界坐标点和它们的图像点。我试图计算相机的姿势,但我得到了一个错误

File c:\Users\nmorsi200\AppData\Local\Temp\Prog6_4.py", line 292, in <module>
    cv.solvePnP(objectPoints,imagePoints,cameraMatrix,distCoeffs)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\core\src\convert_c.cpp:113: error: (-215:Assertion failed) src.size == dst.size && src.channels() == dst.channels() in function 'cvConvertScale

下面是我的代码:

imagePoints = np.float32([[[ 544 ,337 ],
        [ 886 ,337   ],
        [886 ,781],
        [ 544 ,781 ]]])

objectPoints = np.float32([[[ 430 ,-210,90 ],
        [ 430 ,-110 ,90  ],
        [580 ,-210,90],
        [ 886 ,-110,90 ]]])

cameraMatrix = np.float32([ 1.5968554012182622e+04, 0., 5.9163145834154648e+02, 0.,
       1.0919346214593939e+04, 8.3519145165493478e+02, 0., 0., 1. ])

distCoeffs = np.float32([ 3.1817705820413217e+01, -2.4334106040843017e+03,
       -5.7690325903983741e-01, -8.4352650966664180e-02,
       -1.9337299660588971e+04 ])

cv.solvePnP(objectPoints,imagePoints,cameraMatrix,distCoeffs)
uinbv5nw

uinbv5nw1#

你的相机矩阵是一个一维数组,而它 * 应该 * 是一个(3,3)形状的二维数组。OpenCV需要这个形状。它不接受平面数组。

cameraMatrix = np.float32([ ... ]).reshape((3,3))

相关问题