gpt4 book ai didi

python - triangulatePoints() 方法的奇怪行为

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:01 26 4
gpt4 key购买 nike

我正在尝试使用 OpenCV 中的 triangulatePoints() 方法来重建 3d 对象

我为两个相机生成了投影矩阵,它们看起来很正常。但是三角测量方法为不同的输入 2D 坐标返回相同的 3d 值。有什么问题吗?

#code
print('Projection matrices:')
print(P0,'\n',P1, '\n')


points = np.array([
[[381,198],[433,418]],
[[393,231],[435,453]],
[[415,225],[465,454]],
[[406,195],[169,420]]
])


for p in points:
print('2D coordinates: {}, {}'.format(p[0], p[1]))
s = np.array(cv2.triangulatePoints(P0, P1,
p[0],
p[1])).T


print('3D coordinates: {}'.format(s[0][:-1]/np.max(s[0][-1])))
print()


#Output:
#Projection matrices:
[[587.42947475 0. 223.06652927 0. ]
[ 0. 587.42947475 236.78123179 0. ]
[ 0. 0. 1. 0. ]]
[[ 5.87429475e+02 0.00000000e+00 2.23066529e+02 -1.09198390e+04]
[ 0.00000000e+00 5.87429475e+02 2.36781232e+02 0.00000000e+00]
[ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00]]

2D coordinates: [381 198], [433 418]
3D coordinates: [-1.00049629 0. 0. ]

2D coordinates: [393 231], [435 453]
3D coordinates: [-1.00049629 0. 0. ]

2D coordinates: [415 225], [465 454]
3D coordinates: [-1.00049629 0. 0. ]

2D coordinates: [406 195], [169 420]
3D coordinates: [-1.00049629 0. 0. ]

最佳答案

我找到了答案:有必要在图像点初始化中指定dtype为np.float32:


points = np.array([
[[381,198],[433,418]],
[[393,231],[435,453]],
[[415,225],[465,454]],
[[406,195],[169,420]]
], dtype=np.float32)

正确输出后:

2D coordinates: [381. 198.], [433. 418.]
3D coordinates: [ -76.17712 -33.213867 -265.16254 ]

2D coordinates: [393. 231.], [435. 453.]
3D coordinates: [-110.72584 -66.3086 -358.42117]

2D coordinates: [415. 225.], [465. 454.]
3D coordinates: [-105.021255 -54.279873 -300.12518 ]

2D coordinates: [406. 195.], [169. 420.]
3D coordinates: [14.564291 5.4381375 43.69199 ]

关于python - triangulatePoints() 方法的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57307575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com