Hello,
I am currently working on an algorithm to use ArUco Markers to calculate the exact position of my camera in real world coordinate system with the center of the ArUco Marker beeing the coordinate (0,0,0).
The problem is that that while I use a 20cm big marker. The calculated distance of my marker is quite high. And I dont seem to find a way to fix it.
Ive calibrated my camera beforehand with around 200 images of a charuco board.
tvec[0]: 0.245 m,
tvec[1]: 0.035 m,
tvec[2]: 0.809 m
The real distance to the marker is 0.84m (measured with a ruler)
Especially when rotation to the camera is applied the distance measurements are getting way worse. I am also calculating the rotations with the help of the rodrigues function and those seem pretty accurate.
Code for reference (shortened version):
port = 0
marker_length_in_m = 0.2
cap = cv2.VideoCapture(port + cv2.CAP_DSHOW)
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
para = aruco.DetectorParameters_create()
para.cornerRefinementMethod = cv2.aruco.CORNER_REFINE_SUBPIX
while True:
ret, frame = cap.read()
if kinectV2:
frame = cv2.flip(frame, 1) # Kinect V2 has the wrong orientation
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # grayscale for easier detection
corners, ids, rejectedImgPoints = aruco.detectMarkers( # detect markers to get corners and ids
gray, aruco_dict, parameters=para)
aruco.drawDetectedMarkers(frame, corners, ids)
rvecs_n, tvecs_n, _ObjectPoints = aruco.estimatePoseSingleMarkers(
corners=corners,
markerLength=marker_length_in_m,
cameraMatrix=mtx,
distCoeffs=dist,
rvecs=rvecs,
tvecs=tvecs)
if ids is not None:
aruco.drawAxis(frame, mtx, dist, rvecs_n, tvecs_n, marker_length_in_m)
cv2.imshow("frame", frame)
if cv2.waitKey(1) == ord('y'): # save on pressing 'y'
if ids is not None:
# estimation of pose via rotation vector and translation vector
rvecs_n, tvecs_n, _ObjectPoints = aruco.estimatePoseSingleMarkers(
corners=corners,
markerLength=marker_length_in_m,
cameraMatrix=mtx,
distCoeffs=dist,
rvecs=rvecs,
tvecs=tvecs)