Tracking AR Tags with ar_track_alvar
As a part of my senior project on autonomous vehicles, I was tasked with finding out how to detect and track AR tags using a camera. The specific camera we used was the ZED stereo camera, but prior to testing it on that camera that I did not have immediate access to, I wanted to see if it would work on a regular webcam. I found that many resources online were incomplete, outdated, or didn’t specify how to use the package with RViz, the 3D visualizer for ROS. I wrote a short guide on how to do so for my other group members, and thought it would be helpful to post here.
We used the melodic distrubution of ROS which is compatible with Ubuntu 18.0.4 on Linux.
To start, install the package for your distribution:
Create your first marker. Here I created a marker with the id ‘123’
I’m using catkin workspaces which could be read about here. In catkin_ws/src I ran:
Back in /catkin_ws I ran
At this point you need to calibrate your camera. I followed this tutorial on how to calibrate a monocular camera. It would be a slightly different procedure if you were using a stereo camera.
For the calibration I didn’t have access to a larger paper size than a regular 8.5x11 so I simply printed out the checkerboard on that and measured the squares myself. My squares came out to be 0.025m long.
Before you run the calibration program made sure to run the two following commands: (Note: if usb_cam isn’t installed already, install it now!)
Now run the calibration program:
Once the GUI is open, move your sheet of paper around in front of the webcam, at different angles and distances. Do this until the calibrate button is highlighted and then after it finishes calibrating save and commit it. Now point the camera at your printed AR tags and run the following: (My marker size was 5cm and my webcam was #2 but change if you need)
This next command will let you see the id of the AR Tag being detected.
Here’s the part most tutorials left out. I needed to see if the camera could see where the tags were in relation to itself. This is done in RViz. To open up Rviz I ran:
Once there, make sure to point the camera at an AR tag.
- Add the Camera display to the sidebar, the camera stream should pop up
- Under Global Options, change the Fixed Frame to usb_cam
- Add the TF display to the sidebar
- You can now see the positions of the AR tags in relation to the camera!