• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    C++
  • License
    BSD 3-Clause "New...
  • Created over 6 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Working examples/tutorial for detection and pose estimation of ArUco markers with C++, including instructions to build and install OpenCV from source.

ArUco Markers

‼️ IMPORTANT: This assumes you are using OpenCV4. If you need to use OpenCV3, please checkout the cv3 branch before installing dependencies. As there are some breaking changes in OpenCV libraries, some parts of the OpenCV4 codes are not compatible with OpenCV3.

This repository includes codes that can be used to work with the augmented reality library, ArUco. A few programs in the repository, including the codes to create the markers and to calibrate the cameras, are copies of the examples included with the OpenCV libraries with minor changes, which are added so that everything is in one place.

Contents

  1. Installing OpenCV
    1. Installing v4.5.3 (recommended)
    2. Installing the Latest
  2. Generating Markers
  3. Detecting the Markers
  4. Camera Calibration
  5. Pose Estimation
  6. Draw a Cube

Installing OpenCV

You can install the standalone ArUco library by downloading the source files which can be found in the above website and building and installing them. But it is highly recommended to install ArUco library packed in OpenCV library. The instruction below are for installing OpenCV with ArUco library.

You can install OpenCV using the master branch of their repository, OR using the submodules added to this repository. Building and installing OpenCV with the provided submodules guarantees that the other codes on this repository work without issues. So it is recommended to install from the submodules.

Installing v4.5.3 (recommended)

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev

git submodule update --init
cd libraries/opencv
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make -j4  # if you have more/less cores on your computer, substitute 4 with the number of cores
          # use command "nproc" to find the number of cores
sudo make install

Installing the Latest

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

# If you need a specific version, you should checkout that version on 
# both the repositories before executing the below commands.

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
make -j4  # if you have more/less cores on your computer, substitute 4 with the number of cores
          # use command "nproc" to find the number of cores
sudo make install

Generating Markers

To detect the markers using a camera, first you need to print the markers. The ArUco library comes with few functions to generate the markers, and they are copied to this repository for the ease of finding them.

cd create_markers
mkdir build && cd build
cmake ../
make

# Create a single marker.
# For details about the parameters, run just ./generate_marker
./generate_marker --b=1 -d=16 --id=108 --ms=400 --si marker.jpg

# Create a marker board.
# For details about the parameters, run just ./generate_board
./generate_board --bb=1 -h=2 -w=4 -l=200 -s=100 -d=16 --si board.jpg

The generated marker should look like this:

The generated board should look like this:

Detecting the Markers

First, print the generated markers. Connect a camera to the computer and run below commands:

cd detect_markers
mkdir build && cd build
cmake ../
make

./detect_markers

All the detected markers would be drawn on the image.

Β 

Camera Calibration

To accurately detect markers or to get accurate pose data, a camera calibration needs to be performed.

Run below commands to perform the camera calibration:

cd camera_calibration
mkdir build && cd build
cmake ../
make

# Below command is accurate only if you used the same parameters when you generated the markers.
# If you changed any of them, change below arguments accordingly.
./camera_calibration -d=16 -dp=../detector_params.yml -h=2 -w=4 -l=<side length of a single marker (in meters)> -s=<separation between two consecutive markers in the grid (in meters)> ../../calibration_params.yml

# If you want to calibrate with an already saved video, use `-v` flag.
./camera_calibration -v=/path/to/your/video.avi -d=16 -dp=../detector_params.yml -h=2 -w=4 -l=<side length of a single marker (in meters)> -s=<separation between two consecutive markers in the grid (in meters)> ../../calibration_params.yml

Then points the camera at the marker at different orientations and at different angles, and save those images by pressing key C. These instructions should appear on the screen. Around 30 images should be good enough.

Pose Estimation

To estimate the translation and the rotation of the ArUco marker, run below code:

cd pose_estimation

mkdir build && cd build
cmake ../
make

./pose_estimation -l=<side length of a single marker (in meters)>

# or, if you are trying this on an already saved video
./pose_estimation -l=<side length of a single marker (in meters)> -v=<path to the video>

Below image shows the output of this code. The distances shown in the left top corner are in meters with axes as same as those defined in OpenCV model, i.e., x-axis increases from left to right of the image, y-axis increases from top to bottom of the image, and the z-axis points outwards the camera, with the origin on the top left corner of the image. The axes drawn on the markers represent the orientation of the marker with the Red-Green-Blue axes order.

Β 

Draw a Cube

To estimate pose and draw a cube over the ArUco marker, run below code:

cd draw_cube

mkdir build && cd build
cmake ../
make

./draw_cube -l=<side length of a single marker (in meters)>

# or, if you are trying this on an already saved video
./draw_cube -l=<side length of a single marker (in meters)> -v=<path to the video>

Below GIF shows the output of this code.

Β 

More Repositories

1

uav_geometric_control

Geometric controllers developed at FDCL for UAVs
C++
111
star
2

uav_simulator

Python - Gazebo Simulation Environment for a UAV with Geometric Control
Python
101
star
3

FFTSO3

Fast Fourier transform on SO(3)
C++
26
star
4

gazebo_uav_control

A basic example of using Gazbo+ROS with C++ to control a quadrotor UAV using basic PID control
C++
15
star
5

dkf-comparison

Matlab codes for comparing delayed Kalman filters, with application to the state estimation of a UAV.
MATLAB
11
star
6

Matrix-Fisher-Gaussian-Code

Attitude-Gyro bias estimation using matrix Fisher-Gaussian distributions
MATLAB
11
star
7

Matrix-Fisher-Gaussian

Distribution and filtering on SO(3) x Euclidean space
MATLAB
10
star
8

gym-rotor

OpenAI Gym environments for Quadrotor UAV
Python
10
star
9

decoupled-yaw-controller-comparison

Codes used for generating the results in the paper "Geometric Adaptive Controls of a Quadrotor UAV with Decoupled Attitude Dynamics"
MATLAB
9
star
10

FWUAV

Quasi-steady aerodynamics and control for flapping wing UAV on a Lie group
MATLAB
8
star
11

cpp-plots

Examples for plotting with C++, including real-time plots
C++
5
star
12

arduino-vn100

Reading VectorNav VN100 IMU data through an Arduino as binary messages, dealing with checksum.
C++
4
star
13

marl-quad-control

Python
3
star
14

2016_AAS_matlab

Matlab code for 2016 AAS paper
MATLAB
2
star
15

hybrid-system-uncertainty-propagation

MATLAB
2
star
16

scientific_python

Intro to scientific Python programming
TeX
2
star
17

swiftnav-multi

Python and C codes for reading multiple SBP messages from SwiftNav Piksi Multi, and update settings or reset Multi without the Swift Console.
Python
2
star
18

aruco_generator

Generate GIANT Aruco Images
TeX
1
star
19

2016_AAS_abstract

Low-Thrust trajectory design near asteroids using invariant manifolds and reachability sets
TeX
1
star
20

MAE3145_library

Library of some astro functions for MAE3145
Python
1
star
21

IJCAS_template

Example document for submissions to Springer IJCAS - Fixes all of their mistakes (those that are possible)
TeX
1
star
22

ros-install

Bash file used to install ROS
Shell
1
star
23

fdcl_nn

C++
1
star
24

2016_ACC_matlab

Matlab code used for simulation and analysis in the 2016 ACC paper
MATLAB
1
star
25

python-vectornav

Read binary messages from VectorNav on MacOS devices (or other officially not supported devices) in Python
Python
1
star
26

gazebo_mass_pid_control

A basic example of using PID control to mave a mass to a desired position using Gazebo with C++
C++
1
star
27

gym-rotor-modularRL

Python
1
star