Commit 67a7f208 authored by Nicolas PALARD's avatar Nicolas PALARD

🎉 ArUco marker generator

parents
cmake_minimum_required (VERSION 3.2)
project (aruco-generator VERSION 0.1)
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/module)
find_package(OpenCV REQUIRED core opencv_imgcodecs opencv_highgui opencv_imgproc opencv_videoio opencv_aruco)
if (NOT OpenCV_FOUND)
message(FATAL_ERROR "Could not find OpenCV")
endif()
find_package(cxxopts REQUIRED)
set(ARUCO_GENERATOR
src/generator.cpp)
add_executable(aruco-generator ${ARUCO_GENERATOR})
target_link_libraries(aruco-generator ${OpenCV_LIBS})
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/aruco.hpp>
#include <cxxopts.hpp>
using namespace cv;
int markerId = -1;
int markerSize = 50;
int margin = 1;
Ptr<aruco::Dictionary> DICTIONARY = aruco::getPredefinedDictionary(aruco::DICT_ARUCO_ORIGINAL);
static int parseCommandLine(cxxopts::Options options, int argc, char** argv)
{
auto result = options.parse(argc, argv);
if (result.count("h")) {
std::cout << options.help({"", "Group"});
return EXIT_FAILURE;
}
if (result.count("i")) {
markerId = result["i"].as<int>();
}
else {
std::cerr << "Error: -i option required." << std::endl;
return EXIT_FAILURE;
}
if (result.count("m")) {
margin = result["m"].as<int>();
}
if (result.count("s")) {
markerSize = result["s"].as<int>();
}
return EXIT_SUCCESS;
}
int main(int argc, char** argv) {
cxxopts::Options options("aruco-detection-server", "Aruco markers detection server.");
options.add_options()
("i, id", "Marker ID", cxxopts::value<int>())
("s, size", "Marker size", cxxopts::value<int>())
("m, margin", "N margin bits", cxxopts::value<int>())
("h, help", "Print this help message.");
if (parseCommandLine(options, argc, argv)) {
return EXIT_FAILURE;
}
std::string name = std::to_string(markerId)+ ".png";
Mat marker;
aruco::drawMarker(DICTIONARY, markerId, markerSize, marker, margin);
imwrite(name, marker);
std::cerr << "Succesfully generated " << markerId << ".png." << std::endl;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment