我想知道使用Python2.7和OpenCV 3.3中的triangulatePoints
的立体摄像机的3D点。为此,我校准了立体摄像机,并将矩阵存储在文件夹中。我还使用cv2.stereoRectify
和cv2.initUndistortRectifyMap
对图像进行了校正。然后,我保存了这些图像以及投影矩阵P1和P2,并在两幅图像中找到了相应的点。左图像ptl = np.array([304,277])
中的点和右图像ptr = np.array([255,277])
中的对应点。在那之后,我尝试了points = cv2.triangulatePoints(P1,P2,ptl,ptr)
。代码为:
import cv2
import numpy as np
import matplotlib.pyplot as plt
cameraMatrixL = np.load('mtx_left.npy')
distCoeffsL = np.load('dist_left.npy')
cameraMatrixR = np.load('mtx_right.npy')
distCoeffsR = np.load('dist_right.npy')
R = np.load('R.npy')
T = np.load('T.npy')
# following matrices I saved which i got from stereoRectify
R1 = np.load('R1.npy')
R2 = np.load('R2.npy')
P1 = np.load('P1.npy')
P2 = np.load('P2.npy')
Q = np.load('Q.npy')
# upload alreday distorted and rectified images
imgL = cv2.imread('D:\python/triangulate in 3 D\left.png',0)
imgR = cv2.imread('D:\python/triangulate in 3 D/right.png',0)
ptl = np.array([304,277]) # point in left image
ptr = np.array([255,277]) # Corresponding point in right image
points = cv2.triangulatePoints(P1,P2,ptl,ptr)
print points
但是每当我运行这段代码时,我的结果都会改变(而且所有的结果都是错误的)。有一次结果看起来像这样
[[ 518845863]
[ 1667138857]
[-1189385102]
[ -661713]]
另一次的结果如下所示
[[-1766436066]
[ 0]
[ 0]
[-1299735447]]
有时候看起来像是
[[ 0]
[ 0]
[697559541]
[ 0]]
我不知道为什么结果会改变,即使我所有的参数都是一样的?此外,这些三维点是不正确的。如何纠正这些问题?
编辑:我观察到这段代码中的一件事,在运行之后它没有完成。它既不显示Process finished with exit code 0
,也不显示Process finished with exit code 1
__。当我按下红色的停止按钮时,Process finished with exit code 1
__就结束了。为什么会这样呢?我认为由于这一点,只有上述错误才会出现。为什么这段代码不能在Process finished with exit code 0
__上运行?
https://stackoverflow.com/questions/46163831
复制相似问题