Python: solvePnP() недостаточно значений для распаковки?
У меня проблема с функцией под названием cv2.solvePnP
от OpenCV. Эта функция используется для оценки позы шахматной доски. После следующего кода я получаю ошибку:
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, вращение Vectors, translationVectors, inliers = cv2.solvePnP(objp, corners2, matrix, distortion) ValueError: недостаточно значений для распаковки (ожидается 4, получено 3)
1 ответ
Решение
Python: cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) → retval, rvec, tvec¶
Таким образом, есть только 3 значения для распаковки.
Так что вы должны быть в состоянии исправить с помощью:
ret, rotationVectors, translationVectors =
cv2.solvePnP(objp, corners2, matrix, distortion)
Как решает только executePnP() retval
, rvec
а также tvec
,