I need a program to estimate the pose of an ArUco
marker, and, as far as I know, I can code it with two different functions: cv2.solvePnp()
or cv2.aruco.estimatePoseSingleMarker(
). Which one is better? I read about them, and it seems easier to use cv2.aruco.estimatePoseSingleMarker()
, but is it as accurate as cv2.solvePnP()
?
Thanks
I am a graduating student, and I need this information because I am doing a research with a teacher.
estimatePoseSingleMarkers no longer exists as of version 4.7. Here, I replaced the function for you using SolvePnP:
def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
'''
This will estimate the rvec and tvec for each of the marker corners detected by:
corners, ids, rejectedImgPoints = detector.detectMarkers(image)
corners - is an array of detected corners for each detected marker in the image
marker_size - is the size of the detected markers
mtx - is the camera matrix
distortion - is the camera distortion matrix
RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
'''
marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
[marker_size / 2, marker_size / 2, 0],
[marker_size / 2, -marker_size / 2, 0],
[-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
trash = []
rvecs = []
tvecs = []
for c in corners:
nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
rvecs.append(R)
tvecs.append(t)
trash.append(nada)
return rvecs, tvecs, trash