12#ifndef ARUCO_DETECTION_HPP
13#define ARUCO_DETECTION_HPP
15#include "../../AutonomyLogging.h"
16#include "../../util/vision/ImageOperations.hpp"
17#include "../../util/vision/TagDetectionUtilty.hpp"
23#include <opencv2/opencv.hpp>
55 LOG_ERROR(logging::g_qSharedLogger,
"PreprocessFrame() requires a BGR image.");
96 std::vector<int> vIDs;
97 std::vector<std::vector<cv::Point2f>> cvMarkerCorners, cvRejectedCandidates;
100 cvArucoDetector.
detectMarkers(cvFrame, cvMarkerCorners, vIDs, cvRejectedCandidates);
103 std::vector<tagdetectutils::ArucoTag> vDetectedTags;
104 vDetectedTags.reserve(vIDs.size());
107 for (
long unsigned int unIter = 0; unIter < vIDs.size(); unIter++)
111 stDetectedTag.nID = vIDs[unIter];
113 stDetectedTag.pBoundingBox = std::make_shared<cv::Rect2d>(
cv::boundingRect(cvMarkerCorners[unIter]));
114 stDetectedTag.eDetectionMethod = tagdetectutils::TagDetectionMethod::eOpenCV;
115 stDetectedTag.szClassName =
"OpenCVTag";
116 stDetectedTag.cvImageResolution = cvFrame.
size();
119 vDetectedTags.push_back(stDetectedTag);
123 return vDetectedTags;
141 if (!cvDetectionsFrame.
empty() && (cvDetectionsFrame.
channels() == 1 || cvDetectionsFrame.
channels() == 3))
144 for (
long unsigned int nIter = 0; nIter < vDetectedTags.size(); ++nIter)
147 if (vDetectedTags[nIter].eDetectionMethod == tagdetectutils::TagDetectionMethod::eOpenCV)
152 std::string szText =
"TAG " + std::to_string(vDetectedTags[nIter].nID);
166 LOG_ERROR(logging::g_qSharedLogger,
167 "ArucoDetect: Unable to draw markers on image because it is empty or because it has {} channels. (Should be 1 or 3)",
void detectMarkers(InputArray image, OutputArrayOfArrays corners, OutputArray ids, OutputArrayOfArrays rejectedImgPoints=noArray()) const
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Size getTextSize(const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
Rect boundingRect(InputArray array)
Namespace containing functions related to ArUco operations on images.
Definition ArucoDetection.hpp:36
std::vector< tagdetectutils::ArucoTag > Detect(const cv::Mat &cvFrame, const cv::aruco::ArucoDetector &cvArucoDetector)
Detect ArUco tags in the provided image.
Definition ArucoDetection.hpp:93
void DrawDetections(cv::Mat &cvDetectionsFrame, const std::vector< tagdetectutils::ArucoTag > &vDetectedTags)
Given a vector of tagdetectutils::ArucoTag structs draw each tag corner and ID onto the given image.
Definition ArucoDetection.hpp:138
void PreprocessFrame(const cv::Mat &cvInputFrame, cv::Mat &cvOutputFrame)
Preprocess images for specifically for the Aruco Detect() method. This method creates a copy of the c...
Definition ArucoDetection.hpp:49
Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original Aru...
Definition TagDetectionUtilty.hpp:59