Library usage¶
Detecting the markers requires three main entities:
the class
cctag::CCTag
modeling a single markerand the functions
cctag::cctagDetection()
to process the images and get the list of detected markers.the struc
cctag::Parameters
that control the detection algorithm through the various parameters that it exposes.
Detection¶
Here is a minimal sample of code that enable CCTag detection on an image:
1// set up the parameters
2const std::size_t nCrowns{3};
3cctag::Parameters params(nCrowns);
4// if you want to use GPU
5params.setUseCuda(true);
6
7// load the image e.g. from file
8cv::Mat src = cv::imread(image_filename);
9cv::Mat graySrc;
10cv::cvtColor(src, graySrc, CV_BGR2GRAY);
11
12// choose a cuda pipe
13const int pipeId{0};
14
15// an arbitrary id for the frame
16const int frameId{0};
17
18// process the image
19boost::ptr_list<ICCTag> markers{};
20cctagDetection(markers, pipeId, frameId, graySrc, params);
@TODO maybe explain what cuda pipe means
Process detected markers¶
Here is a simple example on how to process the detected markers.
The function drawMarkers
takes the list of detected markers and it overlay their information on the original image.
From the list of markers, if the detected marker is valid it draws the center of the marker, its ID and
the outer ellipse cctag::numerical::geometry::Ellipse
, all in green.
If the marker is not valid, draw the center and the ID in red.
1void drawMarkers(const boost::ptr_list<ICCTag>& markers, cv::Mat& image)
2{
3 // drawing settings
4 const int radius{10};
5 const int fontSize{3};
6 const int thickness{3};
7 const int fontFace{cv::FONT_HERSHEY_SIMPLEX};
8
9 for(const auto& marker : markers)
10 {
11 // center of the marker
12 const cv::Point center = cv::Point(marker.x(), marker.y());
13 const auto rescaledOuterEllipse = marker.rescaledOuterEllipse();
14
15 // check the status and draw accordingly, green for valid, red otherwise
16 if(marker.getStatus() == status::id_reliable)
17 {
18 const cv::Scalar color = cv::Scalar(0, 255, 0, 255);
19 // draw the center
20 cv::circle(image, center, radius, color, thickness);
21 // write the marker ID
22 cv::putText(image, std::to_string(marker.id()), center, fontFace, fontSize, color, thickness);
23 // draw external ellipse
24 cv::ellipse(image,
25 center,
26 cv::Size(rescaledOuterEllipse.a(), rescaledOuterEllipse.b()),
27 rescaledOuterEllipse.angle() * 180 / boost::math::constants::pi<double>(),
28 0,
29 360,
30 color,
31 thickness);
32 }
33 else
34 {
35 // the same for invalid markers but in red
36 const cv::Scalar color = cv::Scalar(0, 0, 255, 255);
37 cv::circle(image, center, radius, color, thickness);
38 cv::putText(image, std::to_string(marker.id()), center, fontFace, fontSize, color, thickness);
39 }
40 }
41}
Here is an example of possible result: