Aruco in opencv

So there isn’t great documentation on the python bindings as far as I can find. There are docs on the c++ bindings.  Trying to do this on a mac was a hellish uphill battle, and opencv in the virtual machine has been… hmm actually pretty okay? Well, I did this on my fresh new triple boot ubuntu flash drive.

Invaluable is to go into the python REPL and type

Then you can see what all the available functions are. They’re more or less self explanatory, especially since they are described in the opencv c++ tutorials.

I believe the python bindings are generated programmatically, and they are fairly systematic, but always a touch different from the c++ function calls. A big difference is typically the python calls don’t modify in place.

Anyway, to get you up, I cobbled together some really basic code. It can generate a tag and save it

And this is a basic program to detect the markers

They are sprinkled with the requisite garbage and cruft of me wiggling around with print statements to figure out what everything is.

It sounds like more of what I want is to use Aruco boards. They sound good. I’m looking into using this for maybe robot configuration sensing.


11 thoughts on “Aruco in opencv”

  1. I get the error ‘ImportError: No module named aruco’
    Please give some tips on how to install aruco.
    I use opencv 3.1 with Python 2.7

    1. Hi Raja,

      It’s been a while since I’ve been playing with this and I’ve run all sorts of commands screwing around with my python distro.
      import aruco
      seems to work now and not cv2.aruco. Perhaps this is from a previous attempt to install aruco or perhaps the opencv project organization has changed (I think when I made this post the aruco addition to opencv was pretty fresh and porbably unstable). I believe I did reinstall opencv the other day to play with OpenSfm. I think I might be using aruco for a new project soon, so I’ll make a new post then.

      Edit: Ah. I see. I actually read my own post. I got it working on my ubuntu partition. never mind then.

  2. I have opencv_contrib compiled in ubuntu along with opencv. When I try to run the code to generate a tag, I get the following error –
    Traceback (most recent call last):
    File “”, line 11, in
    aruco_dict = aruco.Dictionary_get(aruco.DICT_5X5_250)
    AttributeError: ‘module’ object has no attribute ‘Dictionary_get’

    How do I resolve this?

  3. I installed opencv3.2 and the issue is fixed. Now, somehow it is not detecting the marker. No errors as such. But marker is not detected.

  4. Hi you all !

    First thank you for your site and the explanations, it is very useful !
    So, I did install successfully opencv and opencv_contrib using ubuntu 14.04 and python3.5.
    I can import the modules cv2 and cv2.aruco succesfully but it seems like the submodue cv2.aruco is empty… I have no function included in the submodule cv2.aruco.
    Is here the output of help(cv2.aruco):

    Help on module cv2.aruco in cv2:


    DICT_4X4_100 = 1
    DICT_4X4_1000 = 3
    DICT_4X4_250 = 2
    DICT_4X4_50 = 0
    DICT_5X5_100 = 5
    DICT_5X5_1000 = 7
    DICT_5X5_250 = 6
    DICT_5X5_50 = 4
    DICT_6X6_100 = 9
    DICT_6X6_1000 = 11
    DICT_6X6_250 = 10
    DICT_6X6_50 = 8
    DICT_7X7_100 = 13
    DICT_7X7_1000 = 15
    DICT_7X7_250 = 14
    DICT_7X7_50 = 12

    Do you have an idea of what’s wrong?
    Thank you so much !


    1. Hi Raphael,

      Your problem really rings a bell. I think that is the state my Mac installation was at before I switched over to Ubuntu. Unfortunately it’s been long enough that my memory is kind of hazy and I’ve since reinstalled my OS on my mac. But if you installed opencv via apt get, I’d suggest installing from source. I think aruco is kind of an off the beaten path submodule.
      You need to use the cmake option
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules
      with that path replaced as appropriate.

      Here are two guides on installing

      I’m not an opencv developer, but you might also want to try posting on stack exchange or an opencv forum or email chain if building from source doesn’t work.

      Also: I’d suggest upgrading to 16.04. It isn’t necessarily a big deal.
      14.04 is getting long in the tooth. I upgraded recently after I spent hours trying to get another installation to work only to find out that the 14.04 version was deprecated and kind of broken

      1. Hi !

        Thank you so much for your answer ! I’ll look at what you sent me to see if I can find something useful !
        I hope to figure it out !!

        Thanks again,


Leave a Reply

Your email address will not be published. Required fields are marked *