Package: aruco-markers
aruco_markersThearuco_markerspackage is a compact Python toolkit designed to manage ArUCo markers.
It serves as a streamlined interface for the OpenCV aruco module and offers a range of capabilities through both a command line interface and a simplified library interface.
For more information, refer to the accompanying documentation.Code:https://github.com/cmower/aruco_markersDocumentation:https://cmower.github.io/aruco_markers/PyPI:https://pypi.org/project/aruco-markers/Issues:https://github.com/cmower/aruco_markers/issuesInstallFrom PyPIpip install aruco_markersFrom sourceIn a new terminal:Clone repository:(ssh)$ git clone git@github.com:cmower/aruco_markers.git, or(https)$ git clone https://github.com/cmower/aruco_markers.gitChange directory:$ cd aruco_markersEnsurepipis up-to-date:$ python -m pip install --upgrade pipInstall from source:$ pip install .Thearuco_markerslibraryAll the functionality of the library can be accessed viaimportaruco_markersFull documentation for all the classes/functions provided can be foundhere.Command line interfaceSeveral features of the library are exposed to the command line via thearucocommand.
When running these commands, several directories will be created.
The top level directory is~/aruco_markers_data.
All the data created by these commands are stored here, specified in the following sub-sections.The available commands arecollect: Collect data with checkerboard to calibrate a camera.calibrate: Calibrate a camera.generate: Generate marker tags.detect: Detect marker poses from camera feed.server: Start a camera server.The use of these commands are described below.
In addition, you can access the documentation for ecah command by appending--help.
For example$ aruco generate --help
usage: aruco generate [OPTIONS]

Generate marker tags.

optional arguments:
  -h, --help            Show this help message and exit.
  -d DICT, --dict DICT  The dictionary for the ArUCo marker. The default is 'DICT_ARUCO_ORIGINAL'.
  -i ID, --id ID        Identifier of the marker. It has to be a valid id in the specified dictionary. The default is '100'.
  -s SIDEPIXELS, --sidepixels SIDEPIXELS
                        Size of the ArUCo tag. The default is '200'.
  -w WIDTH, --width WIDTH
                        Width of the marker in millimeters. The default is '50'.
  -p PAD, --pad PAD     Padding around marker in millimeters. The image is positioned on an A4 pdf. The default is '20'.
  -l LABEL, --label LABEL
                        Add an optional label to the marker. The default is ''.
  --noshow              Display the marker. If unspecified the tag is shown.
  --save                Save the marker. Tags are saved in ~/aruco_markers/tags; this directory is created when it does not already exist.
  --addhalfmarks        Add marks at the half-way marks on the pdf. If unspecified no marks are added.Similarly for each of the other commands.Generating markersYou can generate markers using thearuco generatecommand.
When the--saveflag is included in the command line input, the marker data is saved in the~/aruco_markers_data/tagsdirectory.
Two files are created, an image of the marker as a PNG and a printable PDF.
The PDF includes the tag and meta information as human-readable text.For example, try running$ aruco generate --dict DICT_ARUCO_ORIGINAL --id 100 --save --noshowThe expected output is as follows (noteHOMEDIRwill be relaced with what ever your home directory is set as).Created HOMEDIR/aruco_markers_data
Created HOMEDIR/aruco_markers_data/tags
Saved
  HOMEDIR/aruco_markers_data/tags/marker_dict_DICT_ARUCO_ORIGINAL_id_100_sidepixels_200_borderbits_1_width_500_pad_20.png
  HOMEDIR/aruco_markers_data/tags/marker_dict_DICT_ARUCO_ORIGINAL_id_100_sidepixels_200_borderbits_1_width_500_pad_20.pdfNote, if you have already runaruco generatebefore, then it is possible you will not see the lines acknowledging a directories creation (i.e. those starting withCreated).The PNG file created should match the marker displayed at the top of this readme, i.e.here.The full list of available dictionaries are as follows.DICT_4X4_50DICT_4X4_100DICT_4X4_250DICT_4X4_1000DICT_5X5_50DICT_5X5_100DICT_5X5_250DICT_5X5_1000DICT_6X6_50DICT_6X6_100DICT_6X6_250DICT_6X6_1000DICT_7X7_50DICT_7X7_100DICT_7X7_250DICT_7X7_1000DICT_ARUCO_ORIGINALDICT_APRILTAG_16h5DICT_APRILTAG_25h9DICT_APRILTAG_36h10DICT_APRILTAG_36h11When creating markers, it's often the case you want to affix the printed marker onto an object.
In such cases, knowing the mid-points of the rectangle is helpful, as manual measurements can be inaccurate.
To simplify this process, you can use the--addhalfmarksflag in thearuco generatecommand while generating markers.
The following is an example of how the output would look like when running this command.Calibrating a cameraCalibrating a camera can be performed using thearuco collectandaruco calibratecommand.
Running this command will take you through several steps in order to calibrate the camera.PrerequisitesYou will require a checkerboard to complete the calibration process.
A good resource for getting printable checkerboards can be foundhere.
It is a good idea to attach the printed checkerboard to a flat surface.You can also find a checkerboard in thedoc/directory calledCheckerboard-A4-25mm-8x6.pdf.
This is a 8-by-6 checkerboard, where each square has length 25mm when printed on A4.Collect dataTo gather data for calibration, execute thearuco collectcommand.
When the checkerboard is detected correctly, a result similar to the one depicted in the above figure should appear.
Press the ESC key to stop collecting data.To obtain accurate estimated parameters from the calibration process, it is advisable to move the checkerboard to different depths and orientations on the screen.
Keep in mind that a considerable amount of data could be collected, so make sure that your PC has sufficient storage capacity.
The quantity of data required is uncertain, but collecting more data will generally result in more precise estimated parameters.
Nevertheless, processing more data will take more time.
Ensuring sufficient coverage of depths and orientations is important.In this particular example, I used theCheckerboard-A4-25mm-8x6.pdffound in thedoc/directory for the checkerboard.
Since I am using my laptop's webcam, the camera index is0(which is the default value).
I began the data collection process by executing the following command.$ aruco collect --width 8 --height 6 --squaresize 25Run$ aruco collect --helpif you need more clarity on the command line input variables.You should expect terminal output similar to the following.$ aruco collect --width 8 --height 6 --squaresize 25
Press ESC to quit.
Created HOMEDIR/aruco_markers_data
Created HOMEDIR/aruco_markers_data/calibrate
Created HOMEDIR/aruco_markers_data/calibrate/CAMERANAME
Data collection completed for the 'CAMERANAME' camera.
Data saved in HOMEDIR/aruco_markers_data/calibrate/CAMERANAMEIn the above,HOMEDIRis your home directory, i.e. where ever~/is on you PC, andCAMERANAMEis the camera name used for data collection.
This should correspond to the camera you intend to calibrate (if you have more than one camera attached to your PC).
Note theCAMERANAME, it will be required in the calibration step next.All the raw images that contain the checkerboard are collected into a zip file calleddata.zip.
You can run the collection process several times, and the new data is appended to the zip file (the collectiondoes notoverwrite previously collected data).Calibrate cameraOnce you have collected data (as described in the previous section), you can directly perform the calibration.
All you require is the name of the camera (this was ouput to the terminal during the data collection, seeCAMERANAMEin previous section).In my example, I ran the following.$ aruco calibrate --cameraname CAMERANAMEThe terminal output should look similar to the following.$ aruco calibrate --cameraname CAMERANAME
Processing checkerboard images ...
Loaded (1/60) checkerboard_cameraname_CAMERANAME_width_8_height_6_squaresize_25.0_stamp_UNIQUETIMESTAMP.png
  Processing ... success!

...

Loaded (60/60) checkerboard_cameraname_CAMERANAME_width_8_height_6_squaresize_25.0_stamp_UNIQUETIMESTAMP.png
  Processing ... success!
Done!
Calibrating camera ... done!
Calibration took 1.0067 seconds
Camera matrix:
 [[617.49438628   0.         318.25186084]
 [  0.         617.0481798  263.17630606]
 [  0.           0.           1.        ]]

Distorion Cooeficients:
 [[-3.22848626e-01  2.43430897e+00 -2.73404118e-04  3.06017375e-03
  -7.64518705e+00]]
Saved HOMEDIR/aruco_markers_data/calibrate/CAMERANAME/camera_parameters.dat
Completed calibration successfully.In the above, 60 files were successfully processed.Note, each file name is given a unique time stamp so files are not overwritten.
The duration of the calibration process is reported and also the estimated parameters.
You do not need to note these since they are saved in thecamera_parameters.datfile.If you have a lot of data and the processing is taking too long, you can downsample the data by specifying the--maxfiles MAXFILESflag.
This will randomly sampleMAXFILESfiles from the file names (uniform distribution) and then perform the calibration.View pose detection from a camera feedAfter calibrating a camera, you can use thearuco detectcommand to display the position of a marker.
This function is primarily intended for debugging and serves as a demonstration of detector configuration.
However, if the camera has not been calibrated beforehand, this command will throw an error.When you runaruco detectyou should see something similar to the figure above.
I ran this example by running the following in terminal.$ aruco detect --dict DICT_4X4_50 --markerindex 0Note, the marker I use in this example has a length of 5cm.
This information is required if you want to use the pose estimation.ServerYou can run a server that will broadcast images to a UDP network.
Simply run the following$ aruco serverSeveral listeners can recieve the feeds from this server.
The information flow is as follows.To see this in action try running the example scriptexample/server_listener.py.Note, this script can be run multiple times in separate terminals.Marker pose estimationIf you opt for thearuco_markerspackage, you can use the command line interface to produce tags and calibrate cameras.
However, if you require additional features, you can customize the class/method structure available in the library.
Several methods are provided to that enable you to easily load camera parameters, and estimate marker poses.Please see the examples, that show how to implement a simple pose estimator intoROS 1/ROS 2.
This example assumes you have calibrated your camera by runningaruco collect, andaruco calibrateprior to running this script.Build documentationThe documentation is hostedhere.
However, if you would like to build the documentation yourself, follow these steps.In a new terminal:Clone repository:(ssh)$ git clone git@github.com:cmower/aruco_markers.git, or(https)$ git clone https://github.com/cmower/aruco_markers.gitChange directory:$ cd aruco_markers/docGenerate the main page:$ python gen_mainpage.pyInstall doxygen:$ sudo apt install doxygenBuild documentation:$ doxygenView documentation:In a browser, openhtml/index.htmlBuild pdf (requires LaTeX)$ cd latex$ makeOpen the file calledrefman.pdfSupported camerasGenerally, any camera that is accessible by the OpenCVVideoCaptureclass is supported.
Others includeTheZED-MiniRGBD camera.CitingIf you usearuco_markersin your work, please consider citing the following.@software{Mower2023title="aruco_markers:ACompactPythonPackageforhandlingArUComarkers",author="ChristopherE.Mower",year="2023",url={https://github.com/cmower/aruco_markers},}ContributingIf you have any issues with the library, or find inaccuracies in the documentation pleaseraise an issue.
I am happy to consider new features if youfork the libraryand submit a pull request.