gpt4 book ai didi

Python openCV 2.4.3 cv2.SolvePnP 错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:28 31 4
gpt4 key购买 nike

我是 Python、OpenCV 和 Numpy 的新手。我一直在尝试实现 C++ 代码的 python 版本,它确定相机相对于已知标记的相对姿势。该代码使用了 cv2.SolvePnP 函数,我一直无能为力才能运行它。我在网上搜索过,但除了对这个功能的类似混淆之外什么也没发现。似乎无论我以何种形式传递我的数据,功能都不愉快。我一直在使用的测试用例是:

## target image points

tPoints = np.zeros((4,2),dtype=np.float64)
tPoints[0,0] = 384.3331
tPoints[0,1] = 162.23618
tPoints[1,0] = 385.27521
tPoints[1,1] = 135.21503
tPoints[2,0] = 409.36746
tPoints[2,1] = 165.64435

## actual marker point set

mPoints = np.zeros((4,3),dtype=np.float64)
mPoints[0,0] = -88.0
mPoints[0,1] = 88.0
mPoints[0,2] = 0
mPoints[1,0] = -88.0
mPoints[1,1] = -88.0
mPoints[1,2] = 0
mPoints[2,0] = 88.0
mPoints[2,1] = -88.0
mPoints[2,2] = 0
mPoints[3,0] = 88.0
mPoints[3,1] = 88.0
mPoints[3,2] = 0

camMatrix = np.zeros((3,3),dtype=np.float64 )
camMatrix[0][0] = 519.0
camMatrix[0][2] = 320.0
camMatrix[1][1] = 522.0
camMatrix[1][2] = 240.0
camMatrix[2][2] = 1.0

retval, rvec, tvec = cv2.solvePnP(objectPoints = tPoints, imagePoints = mPoints, cameraMatrix = camMatrix, distCoeffs = None)

返回的错误是:

cv2.error: C:\slave\WinInstallerMegaPack\src\opencv\modules\calib3d\src\solvepnp.cpp:52: >error: (-215) npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), >ipoints.checkVector(2, CV_64F))

帮助执行此操作,以及有关我哪里出错的信息将不胜感激。还有很多东西要学!

最佳答案

您为 solvePnP 提供的参数形状不正确。 objectPoints 应该是 Nx3,imagePoints 应该是 Nx2。如果我切换 tPointsmPoints 在您的示例中分配给这些参数的方式,它不会引发异常。

关于Python openCV 2.4.3 cv2.SolvePnP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14689455/

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