Python: solvePnP( ) 没有足够的值来解包?
Python: solvePnP( ) not enough values to unpack?
我在使用 OpenCV 中名为 cv2.solvePnP
的函数时遇到问题。此函数用于获取棋盘的姿态估计。在以下代码之后我得到一个错误:
for fname in glob.glob('Images/Calibragem/img1*.jpg'):
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findChessboardCorners(gray, (9,6), None)
if ret==True:
corners2=cv2.cornerSubPix(gray,corners,(11,11),(-1,-1), criteria)
#finds the vectors of rotation and translation
ret, rotationVectors, translationVectors, inliers =
cv2.solvePnP(objp, corners2, matrix, distortion)
#projects the 3D points in the image
imgpts,jac = cv2.projectPoints(axis,rotationVectors,translationVectors,matrix,distortion)
imgAxis=drawAxis(img,corners2,imgpts)
cv2.imshow('imgAxis', imgAxis)
cv2.imwrite('imgAxis.png',imgAxis)
错误说:
ret, rotationVectors, translationVectors, inliers = cv2.solvePnP(objp, corners2, matrix, distortion)
ValueError: not enough values to unpack (expected 4, got 3)
Python: cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) → retval, rvec, tvec¶
所以只有 3 个值需要解包。
所以你应该能够修复:
ret, rotationVectors, translationVectors =
cv2.solvePnP(objp, corners2, matrix, distortion)
仅作为 solvePnP() returns retval
、rvec
和 tvec
.
我在使用 OpenCV 中名为 cv2.solvePnP
的函数时遇到问题。此函数用于获取棋盘的姿态估计。在以下代码之后我得到一个错误:
for fname in glob.glob('Images/Calibragem/img1*.jpg'):
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findChessboardCorners(gray, (9,6), None)
if ret==True:
corners2=cv2.cornerSubPix(gray,corners,(11,11),(-1,-1), criteria)
#finds the vectors of rotation and translation
ret, rotationVectors, translationVectors, inliers =
cv2.solvePnP(objp, corners2, matrix, distortion)
#projects the 3D points in the image
imgpts,jac = cv2.projectPoints(axis,rotationVectors,translationVectors,matrix,distortion)
imgAxis=drawAxis(img,corners2,imgpts)
cv2.imshow('imgAxis', imgAxis)
cv2.imwrite('imgAxis.png',imgAxis)
错误说:
ret, rotationVectors, translationVectors, inliers = cv2.solvePnP(objp, corners2, matrix, distortion) ValueError: not enough values to unpack (expected 4, got 3)
Python: cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) → retval, rvec, tvec¶
所以只有 3 个值需要解包。
所以你应该能够修复:
ret, rotationVectors, translationVectors =
cv2.solvePnP(objp, corners2, matrix, distortion)
仅作为 solvePnP() returns retval
、rvec
和 tvec
.