gpt4 book ai didi

python - 使用 solvePnPRansac() - 姿势估计“解包的值太多”

转载 作者:太空狗 更新时间:2023-10-30 00:40:15 24 4
gpt4 key购买 nike

我正在尝试运行本教程中的代码 - Pose Estimation ,

调用 solvePnPRansac 函数后,出现以下错误:

rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)

ValueError: too many values to unpack

根据文档:

Python: cv2.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, minInliersCount[, inliers[, flags]]]]]]]]) → rvec, tvec, inliers

有人处理过这个问题吗?

(Python 2.7,OpenCV 3b)

最佳答案

异常表示返回的值超过 3 个。 OpenCV3 已经改变了很多方法签名,不幸的是没有真正记录它。我检查了 solvepnp.cpp,签名如下:

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 中:

solvePnPRansac(...)
solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, confidence[, inliers[, flags]]]]]]]])
-> retval, rvec, tvec, inliers

所以尝试一下可能会有所帮助:

_, rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)

或者如果您只想解压最后 3 个元素:

rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)[:-3]

关于python - 使用 solvePnPRansac() - 姿势估计“解包的值太多”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com