【发布时间】:2018-10-12 17:07:11
【问题描述】:
我正在尝试对 2 个 USB 摄像头进行立体校准以执行深度图,但我遇到了这个错误,我不知道如何解决。 我将非常感谢谁能提供帮助。
File "C:/Users/gaetano/stereoCalib.py", line 85, in <module>
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints,
gray.shape[::-1], None, None)
error: OpenCV(3.4.1) D:\Build\OpenCV\opencv-
3.4.1\modules\calib3d\src\calibration.cpp:3384: error: (-215) nimages > 0 in
function cv::calibrateCamera
(this error should have been solved using the following code)
#before here i have collect picture from both the camera, than
#grey conversion
i=0
while i < img_counter:
img = cv2.imread('colorRight_' + str(i) + '.jpg')
img2 = cv2.imread('colorLeft_' + str(i) + '.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
cv2.imwrite('greyRight_' + str(i) + '.jpg',gray)
cv2.imwrite('greyLeft_' + str(i) + '.jpg',gray2)
i += 1
nx = 9
ny = 6
chess_imagesL = glob.glob('greyLeft_*.jpg')
chess_imagesR = glob.glob('greyRight_*.jpg')
for i in range(len(chess_imagesL)):
# Read in the image
chess_board_imageL = mpimg.imread(chess_imagesL[i])
chess_board_imageR = mpimg.imread(chess_imagesR[i])
# Convert to grayscale
# gray = cv2.cvtColor(chess_board_image, cv2.COLOR_RGB2GRAY)
# Find the chessboard corners
ret, cornersL = cv2.findChessboardCorners(chess_board_imageL, (nx, ny),
None)
ret2, cornersR = cv2.findChessboardCorners(chess_board_imageR, (nx, ny),
None)
# If found, draw corners
if ret == True:
# Draw and display the corners
cv2.drawChessboardCorners(chess_board_imageL, (nx, ny), cornersL, ret)
cv2.drawChessboardCorners(chess_board_imageR, (nx, ny), cornersR, ret2)
result_nameL = 'boardL'+str(i)+'.png'
result_nameR = 'boardR'+str(i)+'.png'
cv2.imwrite(result_nameL, chess_board_imageL)
cv2.imwrite(result_nameR, chess_board_imageR)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
## prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*9,3), np.float32)
objp[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
objpointsL=[]
objpointsR=[]
imgpointsL=[]
imgpointsR=[]
for i in range(len(chess_imagesL)):
# Read in the image
chess_board_imageL = mpimg.imread(chess_imagesL[i])
chess_board_imageR = mpimg.imread(chess_imagesR[i])
ret, cornersL = cv2.findChessboardCorners(chess_board_imageL, (nx, ny),
None)
ret2, cornersR = cv2.findChessboardCorners(chess_board_imageR, (nx, ny),
None)
# If found, draw corners
if ret == True:
objpointsL.append(objp)
objpointsR.append(objp)
corners2L = cv2.cornerSubPix(gray,cornersL,(11,11),(-1,-1),criteria)
corners2R = cv2.cornerSubPix(gray,cornersR,(11,11),(-1,-1),criteria)
imgpointsL.append(corners2L)
imgpointsR.append(corners2R)
cv2.drawChessboardCorners(chess_board_imageL, (nx, ny), corners2L, ret)
cv2.drawChessboardCorners(chess_board_imageR, (nx, ny), corners2R, ret2)
result_nameL = 'boardL'+str(i)+'.png'
result_nameR = 'boardR'+str(i)+'.png'
cv2.imwrite(result_nameL, chess_board_imageL)
cv2.imwrite(result_nameR, chess_board_imageR)
出现问题的部分
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpointsL, imgpointsL,
gray.shape[::-1], None, None)
ret2, mtx2, dist2, rvecs2, tvecs2 = cv2.calibrateCamera(objpointsR,
imgpointsR, gray2.shape[::-1], None, None)
R = []
T = []
E = []
F = []
flags = cv2.CALIB_FIX_INTRINSIC
ret, mtx, dist, mtx2, dist2, R, T, E, F = cv2.stereoCalibrate(objpointsL,
imgpointsL ,imgpointsR, mtx, dist, mtx2, dist2, gray.shape[::-1], None,
None, None, None,flags = flags,
criteria = (cv2.TERM_CRITERIA_EPS, 30, 1e-6))
更新 cv2.solvePnP 中的错误
使用您建议的代码,cameracalibration 似乎有效。但我在下一步有问题,立体相机校准
文件“C:/Users/gaetano/Desktop/sonido/CALIPROVA2.py”,第 157 行,在 ret, R, T = cv2.solvePnP(objpointsL,imgpointsL,mtx,dist,R,T,0,0)
TypeError: objectPoints 不是 numpy 数组,也不是标量
R = []
T = []
E = []
F = []
flags = cv2.CALIB_FIX_INTRINSIC
ret, mtx, dist, mtx2, dist2, R, T, E, F = cv2.stereoCalibrate(objpointsL,
imgpointsL ,imgpointsR, mtxL, distL, mtxR, distR,
grayL.shape[::-1], None, None, None, None,
flags = flags,
criteria = (cv2.TERM_CRITERIA_EPS, 30, 1e-6))
ret, R, T = cv2.solvePnP(objpointsL,imgpointsL,mtx,dist,R,T,0,0)
print(R)
print(T)
调整大小
调整大小错误
SystemError: new style getargs format but argument is not a tuple
print(roi1)
print(roi2)
# crop the image
x, y, w, h = roi1
dst = dst[y:y + h, x:x + w]
#
dst2 = dst2[y:y + h, x:x + w]
dst = cv2.resize(dst, 0, dst, 2, 2, interpolation = cv2.INTER_LINEAR)
【问题讨论】:
-
你有空的
objpoints在你附加一些东西的那一行被注释了 -
感谢您的回答,但即使取消注释该行,错误仍然存在
-
我认为 solvepnp 需要一组点,所以也许像 objpointsL[0] 和 imgpointsL[0] 这样的东西会起作用。
标签: opencv stereo-3d cv2 calibration