Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-create-tag-image.cpp
1
2#include <visp3/core/vpConfig.h>
4#include <visp3/detection/vpDetectorAprilTag.h>
6#include <visp3/core/vpXmlParserCamera.h>
7#include <visp3/core/vpImageTools.h>
8#include <visp3/gui/vpDisplayFactory.h>
9#include <visp3/io/vpImageIo.h>
10
11void usage(const char **argv, int error);
12
13void usage(const char **argv, int error)
14{
15 std::cout << "Synopsis" << std::endl
16 << " " << argv[0]
17 << " [--output, -o <filename>]"
18 << " [--tag-size <size>]"
19 << " [--tag-family <family>]"
20 << " [--tag-id <id>]"
21#if defined(VISP_HAVE_DISPLAY)
22 << " [--display, -d]"
23#endif
24 << " [--help, -h]" << std::endl
25 << std::endl;
26 std::cout << "Description" << std::endl
27 << " Create AprilTag or ArUco marker image." << std::endl
28 << std::endl
29 << " --output, -o <filename>" << std::endl
30 << " Output image." << std::endl
31 << " Default: tag.png" << std::endl
32 << std::endl
33 << " --tag-size <size>" << std::endl
34 << " Tag size in pixels." << std::endl
35 << " Default: 400" << std::endl
36 << std::endl
37 << " --tag-family <family>" << std::endl
38 << " Apriltag family. Supported values are:" << std::endl
39 << " 0: TAG_36h11" << std::endl
40 << " 1: TAG_36h10 (DEPRECATED)" << std::endl
41 << " 2: TAG_36ARTOOLKIT (DEPRECATED)" << std::endl
42 << " 3: TAG_25h9" << std::endl
43 << " 4: TAG_25h7 (DEPRECATED)" << std::endl
44 << " 5: TAG_16h5" << std::endl
45 << " 6: TAG_CIRCLE21h7" << std::endl
46 << " 7: TAG_CIRCLE49h12" << std::endl
47 << " 8: TAG_CUSTOM48h12" << std::endl
48 << " 9: TAG_STANDARD41h12" << std::endl
49 << " 10: TAG_STANDARD52h13" << std::endl
50 << " 11: TAG_ARUCO_4x4_50" << std::endl
51 << " 12: TAG_ARUCO_4x4_100" << std::endl
52 << " 13: TAG_ARUCO_4x4_250" << std::endl
53 << " 14: TAG_ARUCO_4x4_1000" << std::endl
54 << " 15: TAG_ARUCO_5x5_50" << std::endl
55 << " 16: TAG_ARUCO_5x5_100" << std::endl
56 << " 17: TAG_ARUCO_5x5_250" << std::endl
57 << " 18: TAG_ARUCO_5x5_1000" << std::endl
58 << " 19: TAG_ARUCO_6x6_50" << std::endl
59 << " 20: TAG_ARUCO_6x6_100" << std::endl
60 << " 21: TAG_ARUCO_6x6_250" << std::endl
61 << " 22: TAG_ARUCO_6x6_1000" << std::endl
62 << " 23: TAG_ARUCO_7x7_50" << std::endl
63 << " 24: TAG_ARUCO_7x7_100" << std::endl
64 << " 25: TAG_ARUCO_7x7_250" << std::endl
65 << " 26: TAG_ARUCO_7x7_1000" << std::endl
66 << " 27: TAG_ARUCO_MIP_36h12" << std::endl
67 << " Default: 0 (36h11)" << std::endl
68 << std::endl
69 << " --tag-id <id>" << std::endl
70 << " Marker id. " << std::endl
71 << " Default: 0" << std::endl
72 << std::endl
73#if defined(VISP_HAVE_DISPLAY)
74 << " --display, -d" << std::endl
75 << " Display generated marker." << std::endl
76 << " Default: disabled" << std::endl
77 << std::endl
78#endif
79 << " --help, -h" << std::endl
80 << " Print this helper message." << std::endl
81 << std::endl;
82
83 if (error) {
84 std::cout << "Error" << std::endl
85 << " "
86 << "Unsupported parameter " << argv[error] << std::endl;
87 }
88}
89
90int main(int argc, const char **argv)
91{
92#if defined(VISP_HAVE_APRILTAG)
93
94#ifdef ENABLE_VISP_NAMESPACE
95 using namespace VISP_NAMESPACE_NAME;
96#endif
97
99
100 std::string opt_filename = "tag.png";
101 bool opt_display_tag = false;
102 unsigned int opt_pix_size = 400;
103 int opt_tag_id = 0;
104
105 for (int i = 1; i < argc; ++i) {
106 if (((std::string(argv[i]) == "--output") || (std::string(argv[i]) == "-o")) && (i + 1 < argc)) {
107 opt_filename = std::string(argv[++i]);
108 }
109 else if (std::string(argv[i]) == "--tag-size" && i + 1 < argc) {
110 opt_pix_size = static_cast<unsigned int>(atoi(argv[++i]));
111 }
112 else if (std::string(argv[i]) == "--tag-family" && i + 1 < argc) {
113 opt_tag_family = static_cast<vpDetectorAprilTag::vpAprilTagFamily>(atoi(argv[++i]));
114 }
115 else if (std::string(argv[i]) == "--tag-id" && i + 1 < argc) {
116 opt_tag_id = atoi(argv[++i]);
117 }
118#if defined(VISP_HAVE_DISPLAY)
119 else if ((std::string(argv[i]) == "--display") || (std::string(argv[i]) == "-d")) {
120 opt_display_tag = true;
121 }
122#endif
123 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
124 usage(argv, 0);
125 return EXIT_SUCCESS;
126 }
127 else {
128 usage(argv, i);
129 return EXIT_FAILURE;
130 }
131 }
132
133 std::cout << "Create marker" << std::endl;
134 std::cout << " Family: " << opt_tag_family << std::endl;
135 std::cout << " Id : " << opt_tag_id << std::endl;
136 std::cout << " Size : " << opt_pix_size << " x " << opt_pix_size << " pixels" << std::endl;
137
138 vpDetectorAprilTag detector(opt_tag_family);
139
140 vpImage<unsigned char> Ismall, I(opt_pix_size, opt_pix_size);
141 if (detector.getTagImage(Ismall, opt_tag_id)) {
143
144 std::cout << "Saved in: " << opt_filename << std::endl;
145 vpImageIo::write(I, opt_filename);
146
147 if (opt_display_tag) {
148 vpDisplay *display = vpDisplayFactory::allocateDisplay(I, -1, -1, "Created marker");
151 std::cout << "Click in the image to quit..." << std::endl;
153 delete display;
154 }
155 }
156
157 return EXIT_SUCCESS;
158
159#else
160 (void)argc;
161 (void)argv;
162#endif
163 return EXIT_SUCCESS;
164}
@ TAG_36h11
AprilTag 36h11 pattern (recommended).
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void resize(const vpImage< Type > &I, vpImage< Type > &Ires, unsigned int width, unsigned int height, const vpImageInterpolationType &method=INTERPOLATION_NEAREST, unsigned int nThreads=0)
Definition of the vpImage class member functions.
Definition vpImage.h:131
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.