I am new to Python, OpenCV, and Numpy. I have been attempting to implement a python version of C++ code which determines the relative pose of a camera to a known marker. The code uses the cv2.SolvePnP function, which I have been at wits end to get to run. I have searched the web, but find nothing but similar confusion for this function. It seems that no matter what form I pass my data, the function is unhappy. The test case I've been using is:
## 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)
The error returned is:
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))
Help getting this to execute, as well as information as to where I am going wrong will be greatly appreciated. Lots still to learn!