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
TagDetectionHandler Class Reference

The TagDetectionHandler class is responsible for managing all of the different detectors that Autonomy_Software uses for AR tag detection. Whether it be for detection using OpenCV's ArUco or detection using a custom model, the detectors are created and stored here. More...

#include <TagDetectionHandler.h>

Public Types

enum class  TagDetectors { TAGDETECTOR_START , eHeadMainCam , eRearCam , TAGDETECTOR_END }
 

Public Member Functions

 TagDetectionHandler ()
 Construct a new TagDetectionHandler::TagDetectionHandler object.
 
 ~TagDetectionHandler ()
 Destroy the TagDetectionHandler::TagDetectionHandler object.
 
void StartAllDetectors ()
 Signals all detectors to start their threads.
 
void StartRecording ()
 Signal the RecordingHandler to start recording video feeds from the TagDetectionHandler.
 
void StopAllDetectors ()
 Signals all detectors to stop their threads.
 
void StopRecording ()
 Signal the RecordingHandler to stop recording video feeds from the TagDetectionHandler.
 
std::shared_ptr< TagDetectorGetTagDetector (TagDetectors eDetectorName)
 Accessor for TagDetector detectors.
 
cv::Mat RequestDetectionOverlayFrame (TagDetectors eDetector=TagDetectors::eHeadMainCam)
 Requests a snapshot of the current tag detection overlay. Blocks execution until the frame is ready.
 

Private Attributes

std::shared_ptr< TagDetectorm_pTagDetectorMainCam
 
std::shared_ptr< TagDetectorm_pTagDetectorRearCam
 
std::unique_ptr< RecordingHandlerm_pRecordingHandler
 

Detailed Description

The TagDetectionHandler class is responsible for managing all of the different detectors that Autonomy_Software uses for AR tag detection. Whether it be for detection using OpenCV's ArUco or detection using a custom model, the detectors are created and stored here.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-07

Member Enumeration Documentation

◆ TagDetectors

enum class TagDetectionHandler::TagDetectors
strong
44 {
45 TAGDETECTOR_START,
46 eHeadMainCam,
47 eRearCam,
48 TAGDETECTOR_END
49 };

Constructor & Destructor Documentation

◆ TagDetectionHandler()

TagDetectionHandler::TagDetectionHandler ( )

Construct a new TagDetectionHandler::TagDetectionHandler object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-10-07
23{
24 // Initialize detector for main ZEDCam.
25 m_pTagDetectorMainCam = std::make_shared<TagDetector>(globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eHeadMainCam),
26 constants::TAGDETECT_MAINCAM_CORNER_REFINE_MAX_ITER,
27 constants::TAGDETECT_MAINCAM_CORNER_REFINE_METHOD,
28 constants::TAGDETECT_MAINCAM_MARKER_BORDER_BITS,
29 constants::TAGDETECT_MAINCAM_DETECT_INVERTED_MARKER,
30 constants::TAGDETECT_MAINCAM_USE_ARUCO3_DETECTION,
31 constants::TAGDETECT_MAINCAM_ENABLE_TRACKING,
32 constants::TAGDETECT_MAINCAM_MAX_FPS,
33 constants::TAGDETECT_MAINCAM_ENABLE_RECORDING,
34 constants::TAGDETECT_MAINCAM_DATA_RETRIEVAL_THREADS,
35 constants::ZED_MAINCAM_USE_GPU_MAT);
36
37 // Check if torch detection is enabled for main ZEDCam.
38 if (constants::TAGDETECT_MAINCAM_ENABLE_TORCH)
39 {
40 // Attempt to init torch detection.
41 if (m_pTagDetectorMainCam->InitTorchDetection(constants::TAGDETECT_TORCH_MODEL))
42 {
43 // Set torch detection enabled.
44 m_pTagDetectorMainCam->EnableTorchDetection(constants::TAGDETECT_MAINCAM_TORCH_CONFIDENCE, constants::TAGDETECT_MAINCAM_TORCH_NMS_THRESH);
45 }
46 }
47
48 // Initialize detector for rear ZEDCam.
49 m_pTagDetectorRearCam = std::make_shared<TagDetector>(globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eRearCam),
50 constants::TAGDETECT_REARCAM_CORNER_REFINE_MAX_ITER,
51 constants::TAGDETECT_REARCAM_CORNER_REFINE_METHOD,
52 constants::TAGDETECT_REARCAM_MARKER_BORDER_BITS,
53 constants::TAGDETECT_REARCAM_DETECT_INVERTED_MARKER,
54 constants::TAGDETECT_REARCAM_USE_ARUCO3_DETECTION,
55 constants::TAGDETECT_REARCAM_ENABLE_TRACKING,
56 constants::TAGDETECT_REARCAM_MAX_FPS,
57 constants::TAGDETECT_REARCAM_ENABLE_RECORDING,
58 constants::TAGDETECT_REARCAM_DATA_RETRIEVAL_THREADS,
59 constants::ZED_REARCAM_USE_GPU_MAT);
60
61 // Check if torch detection is enabled for rear ZEDCam.
62 if (constants::TAGDETECT_REARCAM_ENABLE_TORCH)
63 {
64 // Attempt to init torch detection.
65 if (m_pTagDetectorRearCam->InitTorchDetection(constants::TAGDETECT_TORCH_MODEL))
66 {
67 // Set torch detection enabled.
68 m_pTagDetectorRearCam->EnableTorchDetection(constants::TAGDETECT_REARCAM_TORCH_CONFIDENCE, constants::TAGDETECT_REARCAM_TORCH_NMS_THRESH);
69 }
70 }
71
72 // Initialize recording handler for detectors.
73 m_pRecordingHandler = std::make_unique<RecordingHandler>(RecordingHandler::RecordingMode::eTagDetectionHandler);
74}

◆ ~TagDetectionHandler()

TagDetectionHandler::~TagDetectionHandler ( )

Destroy the TagDetectionHandler::TagDetectionHandler object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-07
84{
85 // Signal and wait for cameras to stop.
86 this->StopAllDetectors();
87}
void StopAllDetectors()
Signals all detectors to stop their threads.
Definition TagDetectionHandler.cpp:125
Here is the call graph for this function:

Member Function Documentation

◆ StartAllDetectors()

void TagDetectionHandler::StartAllDetectors ( )

Signals all detectors to start their threads.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-10-07
97{
98 // Start ZED maincam detector.
99 m_pTagDetectorMainCam->Start();
100
101 // Start ZED rearcam detector.
102 m_pTagDetectorRearCam->Start();
103}
Here is the caller graph for this function:

◆ StartRecording()

void TagDetectionHandler::StartRecording ( )

Signal the RecordingHandler to start recording video feeds from the TagDetectionHandler.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-12-31
113{
114 // Start recording handler.
115 m_pRecordingHandler->Start();
116}
Here is the caller graph for this function:

◆ StopAllDetectors()

void TagDetectionHandler::StopAllDetectors ( )

Signals all detectors to stop their threads.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-10-07
126{
127 // Stop recording handler.
128 m_pRecordingHandler->RequestStop();
129 m_pRecordingHandler->Join();
130
131 // Stop main ZED detectors.
132 m_pTagDetectorMainCam->RequestStop();
133 m_pTagDetectorMainCam->Join();
134
135 // Stop rear ZED detectors.
136 m_pTagDetectorRearCam->RequestStop();
137 m_pTagDetectorRearCam->Join();
138}
Here is the caller graph for this function:

◆ StopRecording()

void TagDetectionHandler::StopRecording ( )

Signal the RecordingHandler to stop recording video feeds from the TagDetectionHandler.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-01-01
148{
149 // Stop recording handler.
150 m_pRecordingHandler->RequestStop();
151 m_pRecordingHandler->Join();
152}

◆ GetTagDetector()

std::shared_ptr< TagDetector > TagDetectionHandler::GetTagDetector ( TagDetectors  eDetectorName)

Accessor for TagDetector detectors.

Parameters
eDetectorName- The name of the detector to retrieve. An enum defined in and specific to this class.
Returns
std::shared_ptr<TagDetector> - A pointer to the detector pertaining to the given name.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-10-07
164{
165 // Determine which tag detector should be returned.
166 switch (eDetectorName)
167 {
168 case TagDetectors::eHeadMainCam: return m_pTagDetectorMainCam; break;
169 case TagDetectors::eRearCam: return m_pTagDetectorRearCam; break;
170 default: return m_pTagDetectorMainCam; break;
171 }
172}
Here is the caller graph for this function:

◆ RequestDetectionOverlayFrame()

cv::Mat TagDetectionHandler::RequestDetectionOverlayFrame ( TagDetectors  eDetector = TagDetectors::eHeadMainCam)

Requests a snapshot of the current tag detection overlay. Blocks execution until the frame is ready.

Parameters
eDetector- The detector to request the frame from.
Returns
cv::Mat - The frame with detection overlays.
Author
Targed (ltkli.nosp@m.onel.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)
Date
2026-01-04
184{
185 cv::Mat cvFrame;
186 std::shared_ptr<TagDetector> pDetector = this->GetTagDetector(eDetector);
187
188 if (pDetector && pDetector->GetIsReady())
189 {
190 std::future<bool> fuFrame = pDetector->RequestDetectionOverlayFrame(cvFrame);
191
192 if (fuFrame.wait_for(std::chrono::seconds(1)) == std::future_status::ready)
193 {
194 fuFrame.get();
195 }
196 else
197 {
198 LOG_WARNING(logging::g_qSharedLogger, "TagDetectionHandler: Timed out waiting for overlay snapshot.");
199 }
200 }
201 else
202 {
203 LOG_WARNING(logging::g_qSharedLogger, "TagDetectionHandler: Requested snapshot from invalid or unready detector.");
204 }
205
206 return cvFrame;
207}
std::shared_ptr< TagDetector > GetTagDetector(TagDetectors eDetectorName)
Accessor for TagDetector detectors.
Definition TagDetectionHandler.cpp:163
Here is the call graph for this function:

The documentation for this class was generated from the following files: