ArUco Markers: usage in Computer Vision using OpenCV — python

Murali mahadeva B S
3 min readAug 7, 2020

--

ArUco stands for Augmented Reality University of Cordoba.

ArUco markers were originally developed in 2014 by S.Garrido-Jurado.

ArUco markers with different sizes

ArUco marker is a binary square with black background and a white generated pattern. These markers can be generated in whatever size. These markers have unique id ranging from 0 to 999. If you are still wondering, what these markers are? and how can they be used?. It’ll be clear in a minute. These markers are used in computer vision. Lets see how.

As you know already, these markers have unique ID. You can trigger different actions for different markers in a camera powered system. Consider, you want a door to open when you show ID 1 to the camera. And close the door when ID 2 is shown to the camera.

ArUco marker generation

These markers are easy to detect due to the black border they have. These markers can be easily detected even from a far away distance. This is the site to generate ArUco markers. You can choose different dictionary types which has different numbers of grids.

Dictionary types available
Different Grid numbers

Side note: You can also generate these markers using Opencv.

Detecting ArUco markers

Software Requirements

  1. Python
  2. Opencv
  3. aruco library
  4. numpy

Running the Code

Install Python and other listed libraries. Run the code below on any IDE. If not working that may be because, you are using other webcam other than you default one. Change the VideoCapture number in the code and try. 0 is for default camera. Use 1 if you are using additional camera.

Aruco marker detection

I have used ArUco marker with ID 0 and dictionary 6X6. I showed ArUco marker from my mobile to the webcam generated from the website mentioned above. Marker is being detected and it is drawing a green boundary around the marker.

If you print the ids variable from the line 11 in the code, it will print the ID of the marker. Based on the ID you can program to do different stuff with other IDs.

You can use multiple markers at the same time and it will return you list of marker IDs.

Embedding an Image over a marker

You can get the pixel co-ordinates from the corners variable from the above code (line number 11). It prints out a list of values

[array([[[203., 116.],
[309., 132.],
[301., 233.],
[192., 222.]]], dtype=float32)]

By indexing you can extract the pixel co-ordinates of each corners of the marker. First value is of X axis and second value is of Y axis.

top_left=int(corners[0][0][0])
top_right=int(corners[0][0][1])
bottom_right=int(corners[0][0][2])
bottom_left=int(corners[0][0][3])

Above code is to embed an image over the marker. Image will be tilted with the marker. Image will stick to the marker, you can move the marker as well. X1, X2, X3, X4 are the corners (X,Y) pixel values of the marker. Load a sample image, using numpy (python computational library) map the pixel values of sample image over ArUco marker.

Youtube video Homography demo

I have used marker on my mobile phone in the above demo video.

You can even combine multiple markers and do the same. Use 4 markers to form a frame. Calculate the center pixel value of each marker. Now each marker represents a single corner of the frame formed. Embed an image within this frame formed by 4 markers. Same as above case right.

You can do lot more with these markers. Welcome to the world of computer vision...

Stay Curious… Stay Creative…

Leave a clap if this content was of some use to you

--

--

No responses yet