Skip to content

A basic c++ library for performing april grid detections and pose estimations using OpenCV

License

Notifications You must be signed in to change notification settings

JHartzer/aprilgrid

Repository files navigation

aprilgrid

A basic C++ library for performing April grid detections and pose estimations using OpenCV

AprilGrid Detections

Build

mkdir build -p
cd build
cmake ../
cmake --build . --config Release
sudo make install

Build documentation

cmake --build . --config Release -j --target documentation

Test

./aprilgrid-cpp-test

Using this Library

This library aims to mimic the OpenCV logical steps for fiducial board detection and pose estimation. The AprilGrid object is constructed by defining the tag dictionary as well as information about the grid structure and dimensions.

auto april_grid = AprilGrid(cv::Size(6, 6), 0.1, 2, 3, cv::aruco::DICT_APRILTAG_36h11, 0);

Board Pose Estimation

Given an image, detect all April tags from the current image.

std::vector<std::vector<cv::Point2f>> corners;
std::vector<int> ids;
april_grid.detectAprilTags(image, corners, ids);

The tag corners and IDs are used to create points representing the board in both the board and image coordinate spaces.

std::vector<cv::Point3f> obj_points;
std::vector<cv::Point2f> img_points;
april_grid.matchImagePoints(corners, ids, obj_points, img_points);

The points in these two coordinate spaces are used to find the rotation and translation vectors for the board.

cv::Vec3d r_vec, t_vec;
cv::solvePnP(obj_points, img_points, camera_matrix_, dist_coeffs_, r_vec, t_vec);

Finally, this library provides two drawing functions to visualize the tag detection and reprojection errors.

cv::Mat image_out;
cv::cvtColor(image, image_out, cv::COLOR_GRAY2BGR);
AprilGrid::drawDetectedTags(image_out, ids, img_points);
AprilGrid::drawReprojectionErrors(image_out, ids, obj_points, img_points, r_vec, t_vec, camera_matrix_, dist_coeffs_);
cv::drawFrameAxes(image_out, camera_matrix_, dist_coeffs_, r_vec, t_vec, 5.0);

Board Image Generation

Additionally, it is possible to generate board images for printing using the draw function.

auto april_grid = AprilGrid(cv::Size(6, 6), 0.1, 2, 3, cv::aruco::DICT_APRILTAG_36h11, 0);
cv::Mat image_out;
unsigned int width{400};
april_grid.draw(width, image_out);

About

A basic c++ library for performing april grid detections and pose estimations using OpenCV

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published