Python triangulatePoints()方法的奇怪行为

Python triangulatePoints()方法的奇怪行为,python,opencv,computer-vision,triangulation,Python,Opencv,Computer Vision,Triangulation,我正在尝试使用OpenCV中的triangulatePoints()方法重建3d对象 我为两台相机生成了投影矩阵,它们看起来很正常。 但是,对于不同的输入二维坐标,三角剖分方法返回相同的三维值。有什么不对劲 #代码 打印('投影矩阵:') 打印(P0,'\n',P1,'\n') points=np.array([ [[381,198],[433,418]], [[393,231],[435,453]], [[415,225],[465,454]], [[406,195],[169,420]] ]

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

我为两台相机生成了投影矩阵,它们看起来很正常。 但是,对于不同的输入二维坐标,三角剖分方法返回相同的三维值。有什么不对劲

#代码
打印('投影矩阵:')
打印(P0,'\n',P1,'\n')
points=np.array([
[[381,198],[433,418]],
[[393,231],[435,453]],
[[415,225],[465,454]],
[[406,195],[169,420]]
])
对于p in点:
打印('2D坐标:{},{}'。格式(p[0],p[1]))
s=np.数组(cv2.三角形点(P0,P1,
p[0],,
p[1]).T
打印('3D坐标:{}'。格式(s[0][:-1]/np.max(s[0][-1]))
打印()
#输出:
#投影矩阵:
[[587.42947475   0.         223.06652927   0.        ]
[  0.         587.42947475 236.78123179   0.        ]
[  0.           0.           1.           0.        ]] 
[5.87429475e+02 0.00000000 E+00 2.23066529e+02-1.09198390e+04]
[0.00000000e+005.87429475e+022.36781232e+020.00000000e+00]
[0.00000000 E+00 0.00000000 E+00 1.00000000 E+00 0.00000000 E+00]]
二维坐标:[381198],[433418]
三维坐标:[-1.00049629 0.0.]
二维坐标:[393 231],[435 453]
三维坐标:[-1.00049629 0.0.]
二维坐标:[415 225],[465 454]
三维坐标:[-1.00049629 0.0.]
二维坐标:[406195],[169420]
三维坐标:[-1.00049629 0.0.]

我找到了一个答案:有必要将图像点初始化中的数据类型指定为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  ]