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

The ObjectDetectionHandler class is responsible for managing all of the different detectors that Autonomy_Software uses for object and obstacle detection. (excluding AR tags) Whether it be for simple detection using a depth measure and blobs or detection using a custom model, the detectors are created and stored here. More...

#include <ObjectDetectionHandler.h>

Public Types

enum class  ObjectDetectors { OBJECTDETECTOR_START , eHeadMainCam , eRearCam , OBJECTDETECTOR_END }
 

Public Member Functions

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

Private Attributes

std::shared_ptr< ObjectDetectorm_pObjectDetectorMainCam
 
std::shared_ptr< ObjectDetectorm_pObjectDetectorRearCam
 
std::unique_ptr< RecordingHandlerm_pRecordingHandler
 

Detailed Description

The ObjectDetectionHandler class is responsible for managing all of the different detectors that Autonomy_Software uses for object and obstacle detection. (excluding AR tags) Whether it be for simple detection using a depth measure and blobs 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), 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-23

Member Enumeration Documentation

◆ ObjectDetectors

enum class ObjectDetectionHandler::ObjectDetectors
strong
44 {
45 OBJECTDETECTOR_START,
46 eHeadMainCam,
47 eRearCam,
48 OBJECTDETECTOR_END
49 };

Constructor & Destructor Documentation

◆ ObjectDetectionHandler()

ObjectDetectionHandler::ObjectDetectionHandler ( )

Construct a new ObjectDetectionHandler::ObjectDetectionHandler 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_pObjectDetectorMainCam = std::make_shared<ObjectDetector>(globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eHeadMainCam),
26 constants::OBJECTDETECT_MAINCAM_ENABLE_TRACKING,
27 constants::OBJECTDETECT_MAINCAM_MAX_FPS,
28 constants::OBJECTDETECT_MAINCAM_ENABLE_RECORDING,
29 constants::OBJECTDETECT_MAINCAM_DATA_RETRIEVAL_THREADS,
30 constants::ZED_MAINCAM_USE_GPU_MAT);
31
32 // Check if torch detection is enabled for main ZEDCam.
33 if (constants::OBJECTDETECT_MAINCAM_ENABLE_TORCH)
34 {
35 // Attempt to init torch detection.
36 if (m_pObjectDetectorMainCam->InitTorchDetection(constants::OBJECTDETECT_TORCH_MODEL))
37 {
38 // Set torch detection enabled.
39 m_pObjectDetectorMainCam->EnableTorchDetection(constants::OBJECTDETECT_MAINCAM_TORCH_CONFIDENCE, constants::OBJECTDETECT_MAINCAM_TORCH_NMS_THRESH);
40 }
41 }
42
43 // Initialize detector for rear ZEDCam.
44 m_pObjectDetectorRearCam = std::make_shared<ObjectDetector>(globals::g_pCameraHandler->GetZED(CameraHandler::ZEDCamName::eRearCam),
45 constants::OBJECTDETECT_REARCAM_ENABLE_TRACKING,
46 constants::OBJECTDETECT_REARCAM_MAX_FPS,
47 constants::OBJECTDETECT_REARCAM_ENABLE_RECORDING,
48 constants::OBJECTDETECT_REARCAM_DATA_RETRIEVAL_THREADS,
49 constants::ZED_REARCAM_USE_GPU_MAT);
50
51 // Check if torch detection is enabled for rear ZEDCam.
52 if (constants::OBJECTDETECT_REARCAM_ENABLE_TORCH)
53 {
54 // Attempt to init torch detection.
55 if (m_pObjectDetectorRearCam->InitTorchDetection(constants::OBJECTDETECT_TORCH_MODEL))
56 {
57 // Set torch detection enabled.
58 m_pObjectDetectorRearCam->EnableTorchDetection(constants::OBJECTDETECT_REARCAM_TORCH_CONFIDENCE, constants::OBJECTDETECT_REARCAM_TORCH_NMS_THRESH);
59 }
60 }
61
62 // Initialize recording handler for detectors.
63 m_pRecordingHandler = std::make_unique<RecordingHandler>(RecordingHandler::RecordingMode::eObjectDetectionHandler);
64}

◆ ~ObjectDetectionHandler()

ObjectDetectionHandler::~ObjectDetectionHandler ( )

Destroy the ObjectDetectionHandler::ObjectDetectionHandler 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
74{
75 // Signal and wait for cameras to stop.
76 this->StopAllDetectors();
77}
void StopAllDetectors()
Signals all detectors to stop their threads.
Definition ObjectDetectionHandler.cpp:115
Here is the call graph for this function:

Member Function Documentation

◆ StartAllDetectors()

void ObjectDetectionHandler::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
87{
88 // Start ZED maincam detector.
89 m_pObjectDetectorMainCam->Start();
90
91 // Start ZED rearcam detector.
92 m_pObjectDetectorRearCam->Start();
93}
Here is the caller graph for this function:

◆ StartRecording()

void ObjectDetectionHandler::StartRecording ( )

Signal the RecordingHandler to start recording feeds from the detectors.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-05-05
103{
104 // Start recording for all detectors.
105 m_pRecordingHandler->Start();
106}
Here is the caller graph for this function:

◆ StopAllDetectors()

void ObjectDetectionHandler::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
116{
117 // Stop recording handler.
118 m_pRecordingHandler->RequestStop();
119 m_pRecordingHandler->Join();
120
121 // Stop ZED maincam detector.
122 m_pObjectDetectorMainCam->RequestStop();
123 m_pObjectDetectorMainCam->Join();
124
125 // Stop ZED rearcam detector.
126 m_pObjectDetectorRearCam->RequestStop();
127 m_pObjectDetectorRearCam->Join();
128}
Here is the caller graph for this function:

◆ StopRecording()

void ObjectDetectionHandler::StopRecording ( )

Signal the RecordingHandler to stop recording feeds from the detectors.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-05-05
138{
139 // Stop recording handler.
140 m_pRecordingHandler->RequestStop();
141 m_pRecordingHandler->Join();
142}

◆ GetObjectDetector()

std::shared_ptr< ObjectDetector > ObjectDetectionHandler::GetObjectDetector ( ObjectDetectors  eDetectorName)

Accessor for ObjectDetector detectors.

Parameters
eDetectorName- The name of the detector to retrieve. An enum defined in and specific to this class.
Returns
std::shared_ptr<ObjectDetector> - 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
154{
155 // Determine which object detector should be returned.
156 switch (eDetectorName)
157 {
158 case ObjectDetectors::eHeadMainCam: return m_pObjectDetectorMainCam; break;
159 case ObjectDetectors::eRearCam: return m_pObjectDetectorRearCam; break;
160 default: return m_pObjectDetectorMainCam; break;
161 }
162}
Here is the caller graph for this function:

◆ RequestDetectionOverlayFrame()

cv::Mat ObjectDetectionHandler::RequestDetectionOverlayFrame ( ObjectDetectors  eDetector = ObjectDetectors::eHeadMainCam)

Requests a snapshot of the current 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-01
174{
175 // Create an empty frame to store the result
176 cv::Mat cvFrame;
177
178 // Get the specific detector (e.g., Head Main Cam)
179 std::shared_ptr<ObjectDetector> pDetector = this->GetObjectDetector(eDetector);
180
181 // Check if the detector is valid and running
182 if (pDetector && pDetector->GetIsReady())
183 {
184 // Request the frame. This returns a "future" (a promise that data will come later)
185 std::future<bool> fuFrame = pDetector->RequestDetectionOverlayFrame(cvFrame);
186
187 // Wait for the detector thread to fulfill the promise
188 if (fuFrame.wait_for(std::chrono::seconds(1)) == std::future_status::ready)
189 {
190 // Retrieve the result (this ensures any exceptions are handled, though rare here)
191 fuFrame.get();
192 }
193 else
194 {
195 LOG_WARNING(logging::g_qSharedLogger, "ObjectDetectionHandler: Timed out waiting for overlay snapshot.");
196 }
197 }
198 else
199 {
200 LOG_WARNING(logging::g_qSharedLogger, "ObjectDetectionHandler: Requested snapshot from invalid or unready detector.");
201 }
202
203 // Return the frame (it will be empty if anything failed, which the State Machine handles)
204 return cvFrame;
205}
std::shared_ptr< ObjectDetector > GetObjectDetector(ObjectDetectors eDetectorName)
Accessor for ObjectDetector detectors.
Definition ObjectDetectionHandler.cpp:153
Here is the call graph for this function:

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