用solvePnPRansac()分解出太多值-姿势估计 [英] 'Too many values to unpack' with solvePnPRansac() - Pose Estimation
问题描述
我正在尝试运行本教程中的代码-姿势估计,
I'm trying to run the code from this tutorial - Pose Estimation,
,调用solvePnPRansac
函数后,出现以下错误:
and I get the following error, after calling solvePnPRansac
function:
rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)
ValueError:太多值无法解包
ValueError: too many values to unpack
根据文档:
Python:cv2.solvePnPRansac(objectPoints,imagePoints,cameraMatrix,distCoeffs [,rvec [,tvec [,useExtrinsicGuess [,erationsCount [,reprojectionError [,minInliersCount [,inliers [,标志]]]]]]]]])]]]→] rvec,tvec,inliers
Python: cv2.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, minInliersCount[, inliers[, flags]]]]]]]]) → rvec, tvec, inliers
有人处理这个问题吗?
(Python 2.7,OpenCV 3b)
(Python 2.7 , OpenCV 3b)
推荐答案
该异常表明返回了3个以上的值.不幸的是,OpenCV3更改了许多方法签名,但没有真正对其进行文档化.我检查了solvepnp.cpp
,签名显示为:
The exception says that there are more than 3 values returned. OpenCV3 has changed a lot of method signatures, unfortunately without really documenting it. I inspected the solvepnp.cpp
and the signature reads:
bool cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
InputArray _cameraMatrix, InputArray _distCoeffs,
OutputArray _rvec, OutputArray _tvec, bool useExtrinsicGuess,
int iterationsCount, float reprojectionError, double confidence,
OutputArray _inliers, int flags)
这似乎表明没有任何变化.但是,在python中:
which seems to indicate that nothing has changed. However, in python:
solvePnPRansac(...)
solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, confidence[, inliers[, flags]]]]]]]])
-> retval, rvec, tvec, inliers
尝试一下可能会有所帮助:
So it might help to try out:
_, rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)
或者如果您只想解压缩最后三个元素:
or in case you just want to unpack the last 3 elements:
rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)[:-3]
这篇关于用solvePnPRansac()分解出太多值-姿势估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!