- Notifications
You must be signed in to change notification settings - Fork973
Description
Hello,
I would like to determine the pose of my board.
I used all provided functions from the library (opencv in python)
Actual behaviour
I was able to detect the marker + id and the corners correctly.
But when I use the functioncv2.aruco.estimatePoseCharucoBoard(...) it returns me not the correct pose ( in my understanding).
I would have expected, that the z-axis will point to the camera and the board is placed in the x-y plane.
By drawing the pose of the complete board and also the poses of the single markers I was able to visualize the mistake.
Code and image results are attached.
Steps to reproduce
OpenCV => opencv-contrib-python 4.5.5.64
Env: Python 3.8
Here my code:
import numpy as npimport cv2from cv2 import arucofrom PIL import Imagefile = "img_left.png"img = Image.open(file) np_img = np.array(img)np_img_3c = np.stack([np_img, np_img, np_img], axis=-1)np_img_result = np.copy(np_img_3c)"setup"arucoDict = aruco.Dictionary_get(aruco.DICT_6X6_250)arucoParams = aruco.DetectorParameters_create()"create the charuco board"calibration_board = aruco.CharucoBoard_create(squaresX=5, squaresY=7, squareLength=0.072, markerLength=0.062, dictionary=arucoDict)img_board = calibration_board.draw((200*3,200*3))cv2.imwrite('sample_board.png',img_board)"camera parameters"fx = 1632.677490234375 fy = 1632.677490234375 cx = 640. cy = 480.cameraMatrix = np.array([[fx, 0, cx], [0, fy, cy], [0.,0.,1.]])distorsionCoeff = np.array([0.0, 0.0, 0.0, 0.0])"detect markers"(marker_corners, marker_ids, rejected) = aruco.detectMarkers(np_img_3c, arucoDict, parameters=arucoParams)"draw detected markers"img2 = aruco.drawDetectedMarkers(np_img_result, marker_corners, marker_ids)detected = Image.fromarray(img2)detected.save("1_detected_markers.png")"interpolate corners"_, charuco_corners, charuco_ids = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, np_img_3c, calibration_board, cameraMatrix=cameraMatrix, distCoeffs=distorsionCoeff)"draw detected corners"img1 = aruco.drawDetectedCornersCharuco(np_img_result, charuco_corners, charuco_ids, (255, 0, 0))img_corners = Image.fromarray(img1)img_corners.save("2_detected_corners.png")"get pose of board"valid, rvec, tvec = aruco.estimatePoseCharucoBoard(charuco_corners, charuco_ids, calibration_board, cameraMatrix, distorsionCoeff, np.empty(1), np.empty(1), useExtrinsicGuess=False)img_result = cv2.drawFrameAxes(np.copy(np_img_3c), cameraMatrix, distorsionCoeff, rvec, tvec, 0.08)img_calib_result = Image.fromarray(img_result)img_calib_result.save("3_calib_pose.png")"get pose of single markers"rvecs, tvecs, objPoints = aruco.estimatePoseSingleMarkers(marker_corners, markerLength=0.062, cameraMatrix=cameraMatrix, distCoeffs=distorsionCoeff)img_single_pose = np.copy(np_img_3c)for i in range(len(rvecs)): img_single_pose = cv2.drawFrameAxes(img_single_pose, cameraMatrix, distorsionCoeff, rvecs[i], tvecs[i], 0.05)img_single_pose = Image.fromarray(img_single_pose)img_single_pose.save("4_calib_single_pose.png")Find attached the result:
Detection of markers and coners works:
Resulting pose and single marker pose

In my understanding the z-axis (blue) should point to the camera. Am I right?
Hope you can help me.
Best regard,
Patrick