OpenCV:对于相同的输入参数,SolvePnP提供不同的结果

问题描述 投票:2回答:1

我正在尝试使用python中的solvePnP估算对象的3D姿势。但是问题是,即使我保持相机和物体都静止不动,solvePnPrvectvec)的输出也会改变。世界坐标系以对象为中心,并随其移动。我正在传递4个图像点和相应的4个对象点。

呼叫SolvePnP:

retval, rvec, tvec = cv2.solvePnP(cam.object_points, cam.image_points, cam.camera_matrix, cam.dist_coefficients, None, None, False, cv2.SOLVEPNP_ITERATIVE)

输出1:

Image points: 
[[ 236.  243.]
 [  43.  368.]
 [ 404.  372.]
 [ 235.  357.]]
Object points: 
[[ 0.   0.   0. ]
 [ 6.5  0.   0. ]
 [ 0.   0.   6.5]
 [ 0.   6.5  0. ]]
R VECT==========
[[-0.56619693]
 [-2.27732794]
 [ 0.71053527]]
T VECT==========
[[ 0.54725923]
 [-0.45834745]
 [ 0.58522831]]

输出2:

Image points: 
[[ 236.  243.]
 [  43.  369.]
 [ 404.  372.]
 [ 235.  357.]]
Object points: 
[[ 0.   0.   0. ]
 [ 6.5  0.   0. ]
 [ 0.   0.   6.5]
 [ 0.   6.5  0. ]]
R VECT==========
[[ 0.33325838]
 [ 2.12767845]
 [ 0.98248134]]
T VECT==========
[[ -2.60687131]
 [  0.37989386]
 [ 23.85078678]]

对象点和图像点是相同的,但是solvePnP仍然给出几个不同的结果。以上结果是交替交替显示的。]

我应该如何解决?

python python-3.x opencv opencv3.0 opencv-solvepnp
1个回答
0
投票

您可以尝试查看solvePnpGeneric,它返回所有可能的解决方案。 resolvePnp可能在两个解决方案之间犹豫不决,并给您交替的结果。

solvePnpGeneric是在OpenCV 4.1.2中引入的,它允许访问不同的解决方案以及它们的重新投影误差。

© www.soinside.com 2019 - 2024. All rights reserved.