0

J'ai un problème avec une fonction appelée cv2.solvePnP de OpenCV. Cette fonction est utilisée pour obtenir une estimation de pose d'un échiquier. Après le code suivant, je reçois une erreur:Python: solvePnP() pas assez de valeurs pour décompresser?

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) 

L'erreur dit:

ret, rotationVectors, translationVectors, inliers = cv2.solvePnP(objp, corners2, matrix, distortion) ValueError: not enough values to unpack (expected 4, got 3)

Répondre

1

De l'opencv2 documentation:

Python: cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) → retval, rvec, tvec¶ 

Donc, il n'y a que 3 valeurs à déballer.
Donc, vous devriez être en mesure de fixer avec:

ret, rotationVectors, translationVectors = 
      cv2.solvePnP(objp, corners2, matrix, distortion) 

Comme solvePnP() ne retourne retval, rvec et tvec.

+1

C'est tellement étrange. Dans la documentation du tutoriel, il y a cette variable inliers qui est utilisée pour recevoir les valeurs de la fonction. Mais j'ai travaillé comme tu m'as dit. Merci peyo! –