0

I'm trying to use arUco marker detection in openCV to calculate the angle of a marker in comparison to the camera's plain.

what's important to me is what angle the marker is rotated in accordance to the camera X-Y plain.

EDIT: changed the pictures, now from my code, including axis for markers and calculated angle. Picture A: Picture A Picture B: Picture B Picture C: Picture C Picture D: Picture D picture A has the marker in front of the camera, and facing the camera. picture B has the marker offset from the center of the camera, but still facing towards the camera's plain (so yaw angle should be 0 deg) picture C has the marker rotated in 45 deg, and directly in front of the camera picture D has the marker rotated in 45 deg angle, and offset from the center of the camera.

The end calculation has to result in a yaw angle of 0 degrees in pictures A and B, and 45 degrees in pictures C and D

for that purposes I tried the following code:

corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict)
rvec, tvec, x = aruco.estimatePoseSingleMarkers(corners, 0.04, cameraMatrix, distCoeffs)
rmat, jacobian = cv2.Rodrigues(rvec)
world_angle = acos(rmat[0][0]) * 57.296

I appear to get the wrong angle. when I recreate the scenes in pictures A and B I get an angle of 20 degrees, and it stays wrong until around a 30 degrees of yaw. But on the other hand, for yaw angles > 45 degrees I get a correct answer.

Am I doing the calculation correctly? or is there some bug in the code? Thanks.

Dan Sheinin
  • 59
  • 10
  • Can you add an image of your detected marker, possible with the axes drawn over the image? Are you keeping the marker at the vertical center of the image? – Kani Sep 08 '19 at 16:05
  • @Kani I added requested pictures. I'm trying to keep the marker at the vertical center of the image, but I can't commit to that. So solution that will include vertical shift will be better, but I'll appreciate one that uses markers on vertical center. – Dan Sheinin Sep 09 '19 at 06:12
  • It seems like the Picture A is weird. If it is directly aiming at the camera, axis should not be drawn like that. Blue line is for too long to be pointing towards the camera. It should be like [this](https://i.imgur.com/e8yyNJK.png). My suspicion is the camera calibration. I am running your calculation (you can see the yaw angle on the terminal in the image background. – Kani Sep 09 '19 at 15:16
  • that might be important, and worth taking a look at. What is the best way you know to calibrate the camera? in my case, I tried to use grid board to calibrate, but each picture I tried to use has returned different distance coeffs and camera matrix – Dan Sheinin Sep 10 '19 at 07:43
  • Did you only use one image for the calibration? You might find [this](https://github.com/fdcl-gwu/aruco-markers) useful. – Kani Sep 11 '19 at 01:51

0 Answers0