Visual Localization
The pasive visual markers in this case are AprilTags. They are similar to QR codes and are used in applications such as robotics, augmented reality, and camera calibration.
To obtain the current position of the robot from the image we must obtain all of the translation and rotation matices of the following formula:
1.World2Marker
To get this matrix we must know which tag we have in the image and its position. We obtain the global positions from the file "apriltags_poses.yaw", and we can get the id tag from the image using the "pyapriltags.Detector()".
2.Marker2Camera
To get this matrix we must solve the Perspective-n-Point problem. We will use the "solvePnP()" function from Opencv. In order to use it we need:
- The four corners of the tag in the camera frame (obtained from "pyapriltags.Detector()").
- The four corners of the tag in the local frame (size of the april tag / 2).
We can use the translation components from the output of the function, but to get the rotation matrix we need use the "Rodrigues()" function from Opencv. After adding padding to both matrices and multipliying them we get the matrix "RT_Camera2Marker". We can obtain the one we need by computing the inverse matrix.
We also have to take into account the reference axis from the april tags are not the same as in gazebo:
To align them with the ones used in the simulation we must perform a rotation of -90 degrees in the z axis and the x axis to the matrix.
3.Camera2Robot
The last matrix is the easiest one, since we can get the information from the position of the camera in the robot sdf file.
In the cases where there are multiple AprilTags detections we simply perform the average position of the two we obtained.
If there are no AprilTags detections we update the position by calculating the difference between the last position we got and the odometry obtained from the sensor.
We can see two test executions in the next videos:







Comments
Post a Comment