Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
TagDetectionUtilty.hpp
1
13#ifndef TAG_DETECTION_UTILITY_HPP
14#define TAG_DETECTION_UTILITY_HPP
15
17
18#include <type_traits>
19
20#include "../../vision/aruco/ArucoDetection.hpp"
21#include "../../vision/aruco/TagDetector.h"
22#include "../../vision/aruco/TensorflowTagDetection.hpp"
23
25
27
28
36{
37
50 inline void LoadDetectedTags(std::vector<arucotag::ArucoTag>& vDetectedArucoTags,
51 std::vector<tensorflowtag::TensorflowTag>& vDetectedTensorflowTags,
52 const std::vector<TagDetector*>& vTagDetectors,
53 bool bUnique = false)
54 {
55 // Number of tag detectors.
56 size_t siNumTagDetectors = vTagDetectors.size();
57
58 // Initialize vectors to store detected tags temporarily.
59 std::vector<std::vector<arucotag::ArucoTag>> vDetectedArucoTagBuffers(siNumTagDetectors);
60 std::vector<std::vector<tensorflowtag::TensorflowTag>> vDetectedTensorflowTagBuffers(siNumTagDetectors);
61
62 // Initialize vectors to store detected tags futures.
63 std::vector<std::future<bool>> vDetectedArucoTagsFuture;
64 std::vector<std::future<bool>> vDetectedTensorflowTagsFuture;
65
66 // Request tags from each detector.
67 for (size_t siIdx = 0; siIdx < siNumTagDetectors; ++siIdx)
68 {
69 // Check if this tag detector is ready.
70 if (vTagDetectors[siIdx]->GetIsReady())
71 {
72 // Request detected Aruco tags from detector.
73 vDetectedArucoTagsFuture.emplace_back(vTagDetectors[siIdx]->RequestDetectedArucoTags(vDetectedArucoTagBuffers[siIdx]));
74 // Request detected Tensorflow tags from detector.
75 vDetectedTensorflowTagsFuture.emplace_back(vTagDetectors[siIdx]->RequestDetectedTensorflowTags(vDetectedTensorflowTagBuffers[siIdx]));
76 }
77 }
78
79 // Ensure all requests have been fulfilled.
80 // Then transfer tags from the buffer to vDetectedArucoTags and vDetectedTensorflowTags for the user to access.
81 for (size_t siIdx = 0; siIdx < vDetectedArucoTagsFuture.size(); ++siIdx)
82 {
83 // Wait for the request to be fulfilled.
84 vDetectedArucoTagsFuture[siIdx].get();
85 vDetectedTensorflowTagsFuture[siIdx].get();
86
87 // Loop through the detected Aruco tags and add them to the vDetectedArucoTags vector.
88 for (const arucotag::ArucoTag& tTag : vDetectedArucoTagBuffers[siIdx])
89 {
90 vDetectedArucoTags.emplace_back(tTag);
91 }
92
93 // Loop through the detected Tensorflow tags and add them to the vDetectedTensorflowTags vector.
94 for (const tensorflowtag::TensorflowTag& tTag : vDetectedTensorflowTagBuffers[siIdx])
95 {
96 vDetectedTensorflowTags.emplace_back(tTag);
97 }
98 }
99
100 if (bUnique)
101 {
102 // Remove all Aruco tags with a duplicate ID.
103 std::set<int> setIds;
104 size_t szIdx = 0;
105 while (szIdx < vDetectedArucoTags.size())
106 {
107 // Tag was detected by another tag detector.
108 if (setIds.count(vDetectedArucoTags[szIdx].nID))
109 {
110 vDetectedArucoTags.erase(vDetectedArucoTags.begin() + szIdx);
111 }
112 else
113 {
114 setIds.insert(vDetectedArucoTags[szIdx].nID);
115 ++szIdx;
116 }
117 }
118 }
119 }
120
121
133 inline bool FindArucoTagByID(int nID, arucotag::ArucoTag& stIdentifiedArucoTag, const std::vector<TagDetector*>& vTagDetectors)
134 {
135 // Load all detected tags in the rover's vision.
136 std::vector<arucotag::ArucoTag> vDetectedArucoTags;
137 std::vector<tensorflowtag::TensorflowTag> vDetectedTensorflowTags;
138 LoadDetectedTags(vDetectedArucoTags, vDetectedTensorflowTags, vTagDetectors, true);
139
140 // Find the tag with the corresponding id.
141 for (const arucotag::ArucoTag& tTag : vDetectedArucoTags)
142 {
143 // Is this the tag being searched for.
144 if (tTag.nID == nID)
145 {
146 stIdentifiedArucoTag = tTag;
147 return true;
148 }
149 }
150
151 // The tag was not found by the tag detectors.
152 return false;
153 }
154
155 // LEAD: Commented this out since TensorflowTag has no ID. Can this be removed or reimplemented in another way?
156 // /******************************************************************************
157 // * @brief Find a tag in the rover's vision with the specified ID, using Tensorflow detection.
158 // *
159 // * @param nID - The ID of the tag being looked for.
160 // * @param tIdentifiedTag - Reference to save the identified tag.
161 // * @param vTagDetectors - Vector of pointers to tag detectors that will be used to request their detected tags.
162 // * @return true - The tag was found.
163 // * @return false - The tag was not found.
164 // *
165 // * @author JSpencerPittman (jspencerpittman@gmail.com)
166 // * @date 2024-03-08
167 // ******************************************************************************/
168 // inline bool FindTensorflowTagByID(int nID, tensorflowtag::TensorflowTag& stIdentifiedTag, const std::vector<TagDetector*>& vTagDetectors)
169 // {
170 // // Load all detected tags in the rover's vision.
171 // std::vector<tensorflowtag::TensorflowTag> vDetectedTags;
172 // LoadDetectedTensorflowTags(vDetectedTags, vTagDetectors, true);
173
174 // // Find the tag with the corresponding id.
175 // for (const tensorflowtag::TensorflowTag& tTag : vDetectedTags)
176 // {
177 // // Is this the tag being searched for.
178 // if (tTag.nID == nID)
179 // {
180 // stIdentifiedTag = tTag;
181 // return true;
182 // }
183 // }
184
185 // // The tag was not found by the tag detectors.
186 // return false;
187 // }
188} // namespace tagdetectutils
189
190#endif
Namespace containing functions to assist in tag detection.
Definition TagDetectionUtilty.hpp:36
bool FindArucoTagByID(int nID, arucotag::ArucoTag &stIdentifiedArucoTag, const std::vector< TagDetector * > &vTagDetectors)
Find a tag in the rover's vision with the specified ID, using OpenCV detection.
Definition TagDetectionUtilty.hpp:133
void LoadDetectedTags(std::vector< arucotag::ArucoTag > &vDetectedArucoTags, std::vector< tensorflowtag::TensorflowTag > &vDetectedTensorflowTags, const std::vector< TagDetector * > &vTagDetectors, bool bUnique=false)
Aggregates all detected tags from each provided tag detector for both OpenCV and Tensorflow detection...
Definition TagDetectionUtilty.hpp:50
Represents a single ArUco tag. Stores all information about a specific tag detection.
Definition ArucoDetection.hpp:44
Represents a single ArUco tag. Stores all information about a specific tag detection.
Definition TensorflowTagDetection.hpp:43