40 inline void LoadDetectedTags(std::vector<tagdetectutils::ArucoTag>& vDetectedArucoTags,
const std::vector<std::shared_ptr<TagDetector>>& vTagDetectors)
43 size_t siNumTagDetectors = vTagDetectors.size();
46 std::vector<std::vector<tagdetectutils::ArucoTag>> vDetectedArucoTagBuffers(siNumTagDetectors);
49 std::vector<std::future<bool>> vDetectedArucoTagsFuture;
52 std::vector<bool> vSpawnedFuture(siNumTagDetectors,
false);
55 for (
size_t siIdx = 0; siIdx < siNumTagDetectors; ++siIdx)
58 if (vTagDetectors[siIdx]->GetIsReady())
61 vDetectedArucoTagsFuture.emplace_back(vTagDetectors[siIdx]->RequestDetectedArucoTags(vDetectedArucoTagBuffers[siIdx]));
62 vSpawnedFuture[siIdx] =
true;
68 for (
size_t siIdx = 0; siIdx < siNumTagDetectors; ++siIdx)
71 if (vSpawnedFuture[siIdx])
74 vDetectedArucoTagsFuture[nFutureIdx].get();
80 vDetectedArucoTags.emplace_back(tTag);
103 const int nTargetTagID =
static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ANY))
106 std::vector<tagdetectutils::ArucoTag> vDetectedArucoTags;
109 std::string szIdentifiedTags =
"";
112 double dBestArucoAreaPercentage = 0.0;
113 double dBestTorchAreaPercentage = 0.0;
116 std::chrono::system_clock::time_point tmCurrentTime = std::chrono::system_clock::now();
125 double dTagTotalAge = std::fabs(std::chrono::duration_cast<std::chrono::milliseconds>(tmCurrentTime - stCandidate.tmCreation).count() / 1000.0);
128 if (stCandidate.pBoundingBox ==
nullptr)
134 double dArea = stCandidate.pBoundingBox->area();
135 double dAreaPercentage = (dArea / (stCandidate.cvImageResolution.width * stCandidate.cvImageResolution.height)) * 100.0;
138 if (dAreaPercentage < constants::BBOX_MIN_SCREEN_PERCENTAGE || dTagTotalAge < constants::BBOX_MIN_LIFETIME_THRESHOLD)
144 if (stCandidate.eDetectionMethod == tagdetectutils::TagDetectionMethod::eOpenCV)
146 szIdentifiedTags +=
"\tArUco ID: " + std::to_string(stCandidate.nID) +
" Tag Age: " + std::to_string(dTagTotalAge) +
147 "s Tag Screen Percentage: " + std::to_string(dAreaPercentage) +
"%\n";
150 if (stCandidate.nID == nTargetTagID || nTargetTagID ==
static_cast<int>(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ANY))
153 if (dAreaPercentage > dBestArucoAreaPercentage)
155 stArucoBestTag = stCandidate;
156 dBestArucoAreaPercentage = dAreaPercentage;
161 else if (stCandidate.eDetectionMethod == tagdetectutils::TagDetectionMethod::eTorch)
163 szIdentifiedTags +=
"\tTorch Class: " + stCandidate.szClassName +
" Tag Age: " + std::to_string(dTagTotalAge) +
164 "s Tag Screen Percentage: " + std::to_string(dAreaPercentage) +
"%\n";
167 if (dAreaPercentage > dBestTorchAreaPercentage)
169 stTorchBestTag = stCandidate;
170 dBestTorchAreaPercentage = dAreaPercentage;
176 if (stArucoBestTag.nID != -1 || stTorchBestTag.dConfidence != 0.0)
178 LOG_DEBUG(logging::g_qSharedLogger,
"TagDetectionChecker: Identified tags:\n{}", szIdentifiedTags);
182 stArucoTarget = stArucoBestTag;
183 stTorchTarget = stTorchBestTag;
185 return static_cast<int>(vDetectedArucoTags.size());
int IdentifyTargetMarker(const std::vector< std::shared_ptr< TagDetector > > &vTagDetectors, tagdetectutils::ArucoTag &stArucoTarget, tagdetectutils::ArucoTag &stTorchTarget, const int nTargetTagID=static_cast< int >(manifest::Autonomy::AUTONOMYWAYPOINTTYPES::ANY))
Identify a target marker in the rover's vision, using OpenCV detection.
Definition TagDetectionChecker.hpp:100
void LoadDetectedTags(std::vector< tagdetectutils::ArucoTag > &vDetectedArucoTags, const std::vector< std::shared_ptr< TagDetector > > &vTagDetectors)
Aggregates all detected tags from each provided tag detector for both OpenCV and YOLO detection.
Definition TagDetectionChecker.hpp:40