我是 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))
帮助执行此操作,以及有关我哪里出错的信息将不胜感激。还有很多东西要学!