Python 2.7 Python2.7/OpenCV 3.3:cv2.initUnderstrotyMap中的错误。不显示未失真的校正图像
我想扭曲和矫正我的立体图像。为此,我在Python 2.7中使用了Opencv 3.3。我使用的代码是:Python 2.7 Python2.7/OpenCV 3.3:cv2.initUnderstrotyMap中的错误。不显示未失真的校正图像,python-2.7,opencv3.0,stereo-3d,remap,cv2,Python 2.7,Opencv3.0,Stereo 3d,Remap,Cv2,我想扭曲和矫正我的立体图像。为此,我在Python 2.7中使用了Opencv 3.3。我使用的代码是: import cv2 import numpy as np 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
import cv2
import numpy as np
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')
imgleft = cv2.imread('D:\python\camera calibration and 3d const\left\left60.png',0)
imgright = cv2.imread('D:\python\camera calibration and 3d const\Right/right60.png',0)
R1,R2,P1,P2,Q,validPixROI1, validPixROI2 = cv2.stereoRectify(cameraMatrixL,distCoeffsL,cameraMatrixR,distCoeffsR,(640,480),R,T,alpha=1)
print Q
# distort images
undistort_map1, rectify_map1 = cv2.initUndistortRectifyMap(cameraMatrixL, distCoeffsR, R1, P1, (640,480), cv2.CV_16SC2)
undistort_map2, rectify_map2 = cv2.initUndistortRectifyMap(cameraMatrixR, distCoeffsR, R2, P2, (640,480), cv2.CV_16SC2)
undistor_output1 = cv2.remap(imgleft, undistort_map1, rectify_map1, cv2.INTER_LINEAR)
undistor_output2 = cv2.remap(imgright, undistort_map2, rectify_map2, cv2.INTER_LINEAR)
cv2.imshow('undistor_output1',undistor_output1)
cv2.imshow('undistor_output2',undistor_output2)
while (True):
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我分别校准了我的相机,然后将这些获得的矩阵用于cv2。StereoRective
以获得R1、R2、P1、P2、Q
矩阵,我在cv2中使用了这些矩阵。但我没有得到正确的无失真图像。
看起来是这样的:
我的矩阵是:
Q
[[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 -3.23097469e+02]
[ 0.00000000e+00 1.00000000e+00 0.00000000e+00 -2.40008609e+02]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -7.47885268e+00]
[ 0.00000000e+00 0.00000000e+00 -1.53249612e-02 0.00000000e+00]]
cameraMartix Left
[[ 807.24668269 0. 326.78961645]
[ 0. 620.70299534 259.9187458 ]
[ 0. 0. 1. ]]
camearMatrix Right
[[ 567.37537971 0. 278.76995505]
[ 0. 558.21417195 216.22972643]
[ 0. 0. 1. ]]
Rotation
[[ 0.99973813 -0.02260904 0.00353613]
[ 0.02269951 0.99934817 -0.02807079]
[-0.00289917 0.0281437 0.99959968]]
Tranlation
[[-93.46968934]
[ -1.48741179]
[ 24.98692133]]
我读了很多答案,但没有什么能解决我的问题
*
*
这个问题的解决方案是什么
谢谢。在尝试了很多东西之后,我找到了这个特殊问题的解决方案。通过比较使用Python OpenCV和Matlab获得的摄像机旋转矩阵和失真矩阵,我发现使用Python和Matlab获得的矩阵之间存在很大差异。因此,我再次校准我的相机,并使用Python和OpenCV进行立体校准。下图显示了旧矩阵(从Python获得)和新矩阵(再次使用Python校准后获得)之间的差异
在该图中,我们可以看到,与新情况下左右摄像机的失真系数矩阵相比,旧情况下左右摄像机的失真系数矩阵(dist coeff.right old and left old)
(dist coeff.right new and left new)
,存在很大差异。对于右摄像头,旧系数分别为83.85和-19.18,而不是0.78和-0.61。类似地,对于左摄像机,旧系数分别为123.7和-1641.4,而不是-0.38和0.73。此外,旧的左摄像头矩阵的第一个元素(1,1)是807.24,与右摄像头旧矩阵相比差异很大。新的左摄像头矩阵的元素值为552.41,我认为这是正确的。当我使用所有这些新矩阵并将alpha值更改为0(alpha=0)
时,我得到了以下结果。
对于stereoCalbirate
我使用了以下输入
retVal, cm1, dc1, cm2, dc2, r, t, e, f = cv2.stereoCalibrate(objpoints, imgpointsL, imgpointsR, cm1, dc1, cm2, dc2, (640, 480), None, None, cv2.CALIB_FIX_INTRINSIC, criteria)
其中
criteria=(cv2.TERM\u criteria\u EPS+cv2.TERM\u criteria\u MAX\u ITER,100,0.001)
第一次和第二次校准之间有什么变化?我使用alpha值为0(alpha=0),而不是alpha值为1(alpha=1)。但alpha不是stereoCalibrate中的参数。我的立体声(和照相机)校准输出类似的失真系数,具有较大的k3值。我想知道您采取了哪些不同的措施来获得新校准的合理k3值