![]() |
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.
|
Run's Aruco detection & camera pose estimation in a multithreading environment. Given a camera, tag detection using OpenCV's ArUco library and a custom trained model for detecting general tags will be continuously ran on the camera frames. More...
#include <TagDetector.h>
Public Member Functions | |
TagDetector (std::shared_ptr< BasicCamera > pBasicCam, const int nArucoCornerRefinementMaxIterations=30, const int nArucoCornerRefinementMethod=cv::aruco::CORNER_REFINE_NONE, const int nArucoMarkerBorderBits=1, const bool bArucoDetectInvertedMarkers=false, const bool bUseAruco3Detection=false, const bool bEnableTracking=false, const int nDetectorMaxFPS=30, const bool bEnableRecordingFlag=false, const int nNumDetectedTagsRetrievalThreads=5, const bool bUsingGpuMats=false) | |
Construct a new TagDetector object. | |
TagDetector (std::shared_ptr< ZEDCamera > pZEDCam, const int nArucoCornerRefinementMaxIterations=30, const int nArucoCornerRefinementMethod=cv::aruco::CORNER_REFINE_NONE, const int nArucoMarkerBorderBits=1, const bool bArucoDetectInvertedMarkers=false, const bool bUseAruco3Detection=false, const bool bEnableTracking=false, const int nDetectorMaxFPS=30, const bool bEnableRecordingFlag=false, const int nNumDetectedTagsRetrievalThreads=5, const bool bUsingGpuMats=false) | |
Construct a new TagDetector object. | |
~TagDetector () | |
Destroy the Tag Detector:: Tag Detector object. | |
std::future< bool > | RequestDetectionOverlayFrame (cv::Mat &cvFrame) |
Request a copy of a frame containing the tag detection overlays from the aruco and tensorflow library. | |
std::future< bool > | RequestDetectedArucoTags (std::vector< tagdetectutils::ArucoTag > &vArucoTags) |
Request the most up to date vector of detected tags from OpenCV's Aruco algorithm. | |
bool | InitTorchDetection (const std::string &szModelPath, yolomodel::pytorch::PyTorchInterpreter::HardwareDevices eDevice=yolomodel::pytorch::PyTorchInterpreter::HardwareDevices::eCUDA) |
Attempt to open the next available Torch hardware and load model at the given path onto the device. | |
void | EnableTorchDetection (const float fMinObjectConfidence=0.4f, const float fNMSThreshold=0.6f) |
Turn on torch detection with given parameters. | |
void | DisableTorchDetection () |
Set flag to stop tag detection with the torch model. | |
void | SetDetectorMaxFPS (const int nRecordingFPS) |
Mutator for the desired max FPS for this detector. | |
void | SetEnableRecordingFlag (const bool bEnableRecordingFlag) |
Mutator for the Enable Recording Flag private member. | |
bool | GetIsReady () |
Accessor for the status of this TagDetector. | |
int | GetDetectorMaxFPS () const |
Accessor for the desired max FPS for this detector. | |
bool | GetEnableRecordingFlag () const |
Accessor for the Enable Recording Flag private member. | |
std::string | GetCameraName () |
Accessor for the camera name or path that this TagDetector is tied to. | |
cv::Size | GetProcessFrameResolution () const |
Accessor for the resolution of the process image used for tag detection. | |
![]() | |
AutonomyThread () | |
Construct a new Autonomy Thread object. | |
virtual | ~AutonomyThread () |
Destroy the Autonomy Thread object. If the parent object or main thread is destroyed or exited while this thread is still running, a race condition will occur. Stopping and joining the thread here insures that the main program can't exit if the user forgot to stop and join the thread. | |
void | Start () |
When this method is called, it starts a new thread that runs the code within the ThreadedContinuousCode method. This is the users main code that will run the important and continuous code for the class. | |
void | RequestStop () |
Signals threads to stop executing user code, terminate. DOES NOT JOIN. This method will not force the thread to exit, if the user code is not written properly and contains WHILE statement or any other long-executing or blocking code, then the thread will not exit until the next iteration. | |
void | Join () |
Waits for thread to finish executing and then closes thread. This method will block the calling code until thread is finished. | |
bool | Joinable () const |
Check if the code within the thread and all pools created by it are finished executing and the thread is ready to be closed. | |
AutonomyThreadState | GetThreadState () const |
Accessor for the Threads State private member. | |
IPS & | GetIPS () |
Accessor for the Frame I P S private member. | |
Private Member Functions | |
void | ThreadedContinuousCode () override |
This code will run continuously in a separate thread. New frames from the given camera are grabbed and the tags for the camera image are detected, filtered, and stored. Then any requests for the current tags are fulfilled. | |
void | PooledLinearCode () override |
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method. It copies the data from the different data objects to references of the same type stored in a queue filled by the Request methods. | |
void | UpdateDetectedTags (std::vector< tagdetectutils::ArucoTag > &vNewlyDetectedTags) |
Updates the detected torch tags including tracking the detected tags over time and removing tags that haven't been seen for long enough. | |
Private Attributes | |
std::shared_ptr< Camera< cv::Mat > > | m_pCamera |
cv::aruco::ArucoDetector | m_cvArucoDetector |
cv::aruco::DetectorParameters | m_cvArucoDetectionParams |
cv::aruco::Dictionary | m_cvTagDictionary |
std::shared_ptr< yolomodel::pytorch::PyTorchInterpreter > | m_pTorchDetector |
std::atomic< float > | m_fTorchMinObjectConfidence |
std::atomic< float > | m_fTorchNMSThreshold |
std::atomic_bool | m_bTorchInitialized |
std::atomic_bool | m_bTorchEnabled |
std::shared_ptr< tracking::MultiTracker > | m_pMultiTracker |
bool | m_bUsingZedCamera |
bool | m_bUsingGpuMats |
bool | m_bCameraIsOpened |
bool | m_bEnableTracking |
int | m_nNumDetectedTagsRetrievalThreads |
std::string | m_szCameraName |
std::atomic_bool | m_bEnableRecordingFlag |
std::vector< tagdetectutils::ArucoTag > | m_vNewlyDetectedTags |
std::vector< tagdetectutils::ArucoTag > | m_vDetectedArucoTags |
geoops::RoverPose | m_stRoverPose |
cv::Mat | m_cvFrame |
cv::cuda::GpuMat | m_cvGPUFrame |
cv::Mat | m_cvArucoProcFrame |
cv::Mat | m_cvPointCloud |
cv::cuda::GpuMat | m_cvGPUPointCloud |
std::queue< containers::FrameFetchContainer< cv::Mat > > | m_qDetectedTagDrawnOverlayFramesCopySchedule |
std::queue< containers::DataFetchContainer< std::vector< tagdetectutils::ArucoTag > > > | m_qDetectedArucoTagCopySchedule |
std::shared_mutex | m_muPoolScheduleMutex |
std::shared_mutex | m_muFrameCopyMutex |
std::shared_mutex | m_muArucoDataCopyMutex |
Additional Inherited Members | |
![]() | |
enum | AutonomyThreadState |
![]() | |
void | RunPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false) |
When this method is called, it starts/adds tasks to a thread pool that runs nNumTasksToQueue copies of the code within the PooledLinearCode() method using nNumThreads number of threads. This is meant to be used as an internal utility of the child class to further improve parallelization. Default value for nNumThreads is 2. | |
void | RunDetachedPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false) |
When this method is called, it starts a thread pool full of threads that don't return std::futures (like a placeholder for the thread return type). This means the thread will not have a return type and there is no way to determine if the thread has finished other than calling the Join() method. Only use this if you want to 'set and forget'. It will be faster as it doesn't return futures. Runs PooledLinearCode() method code. This is meant to be used as an internal utility of the child class to further improve parallelization. | |
void | ParallelizeLoop (const int nNumThreads, const N tTotalIterations, F &&tLoopFunction) |
Given a ref-qualified looping function and an arbitrary number of iterations, this method will divide up the loop and run each section in a thread pool. This function must not return anything. This method will block until the loop has completed. | |
void | ClearPoolQueue () |
Clears any tasks waiting to be ran in the queue, tasks currently running will remain running. | |
void | JoinPool () |
Waits for pool to finish executing tasks. This method will block the calling code until thread is finished. | |
bool | PoolJoinable () const |
Check if the internal pool threads are done executing code and the queue is empty. | |
void | SetMainThreadIPSLimit (int nMaxIterationsPerSecond=0) |
Mutator for the Main Thread Max I P S private member. | |
int | GetPoolNumOfThreads () |
Accessor for the Pool Num Of Threads private member. | |
int | GetPoolQueueLength () |
Accessor for the Pool Queue Size private member. | |
std::vector< void > | GetPoolResults () |
Accessor for the Pool Results private member. The action of getting results will destroy and remove them from this object. This method blocks if the thread is not finished, so no need to call JoinPool() before getting results. | |
int | GetMainThreadMaxIPS () const |
Accessor for the Main Thread Max I P S private member. | |
![]() | |
IPS | m_IPS |
Run's Aruco detection & camera pose estimation in a multithreading environment. Given a camera, tag detection using OpenCV's ArUco library and a custom trained model for detecting general tags will be continuously ran on the camera frames.
What are the threads doing? Continuous Thread: In this thread we are constantly getting images and depth maps from the necessary cameras. We then detect the tags in the image and estimate their location with respect to the rover. Pooled Threads: Copy the vector of detected tags to all of the threads requesting it through the RequestDetectedArucoTags(...) function.
TagDetector::TagDetector | ( | std::shared_ptr< BasicCamera > | pBasicCam, |
const int | nArucoCornerRefinementMaxIterations = 30 , |
||
const int | nArucoCornerRefinementMethod = cv::aruco::CORNER_REFINE_NONE , |
||
const int | nArucoMarkerBorderBits = 1 , |
||
const bool | bArucoDetectInvertedMarkers = false , |
||
const bool | bUseAruco3Detection = false , |
||
const bool | bEnableTracking = false , |
||
const int | nDetectorMaxFPS = 30 , |
||
const bool | bEnableRecordingFlag = false , |
||
const int | nNumDetectedTagsRetrievalThreads = 5 , |
||
const bool | bUsingGpuMats = false |
||
) |
Construct a new TagDetector object.
pBasicCam | - A pointer to the BasicCam camera to get frames from for detection. |
nArucoCornerRefinementMaxIterations | - The number of iterations to use when refining marker corners. |
nArucoCornerRefinementMethod | - The refinement method to use. |
nArucoMarkerBorderBits | - The number of border unit squares around the marker. |
bArucoDetectInvertedMarkers | - Enable or disable upside-down marker detection. |
bUseAruco3Detection | - Whether or not to use the newer/faster method of detection. Experimental. |
bEnableTracking | - Whether or not to enable tracking of detected tags. |
nDetectorMaxFPS | - The max FPS limit the detector can run at. |
bEnableRecordingFlag | - Whether or not this TagDetector's overlay output should be recorded. |
nNumDetectedTagsRetrievalThreads | - The number of threads to use when fulfilling requests for the detected aruco tags. Default is 5. |
bUsingGpuMats | - Whether or not the given camera name will be using GpuMats. |
TagDetector::TagDetector | ( | std::shared_ptr< ZEDCamera > | pZEDCam, |
const int | nArucoCornerRefinementMaxIterations = 30 , |
||
const int | nArucoCornerRefinementMethod = cv::aruco::CORNER_REFINE_NONE , |
||
const int | nArucoMarkerBorderBits = 1 , |
||
const bool | bArucoDetectInvertedMarkers = false , |
||
const bool | bUseAruco3Detection = false , |
||
const bool | bEnableTracking = false , |
||
const int | nDetectorMaxFPS = 30 , |
||
const bool | bEnableRecordingFlag = false , |
||
const int | nNumDetectedTagsRetrievalThreads = 5 , |
||
const bool | bUsingGpuMats = false |
||
) |
Construct a new TagDetector object.
pZEDCam | - A pointer to the ZEDCam camera to get frames from for detection. Override for ZED camera. |
nArucoCornerRefinementMaxIterations | - The number of iterations to use when refining marker corners. |
nArucoCornerRefinementMethod | - The refinement method to use. |
nArucoMarkerBorderBits | - The number of border unit squares around the marker. |
bArucoDetectInvertedMarkers | - Enable or disable upside-down marker detection. |
bUseAruco3Detection | - Whether or not to use the newer/faster method of detection. Experimental. |
bEnableTracking | - Whether or not to enable tracking of detected tags. |
nDetectorMaxFPS | - The max FPS limit the detector can run at. |
bEnableRecordingFlag | - Whether or not this TagDetector's overlay output should be recorded. |
nNumDetectedTagsRetrievalThreads | - The number of threads to use when fulfilling requests for the detected aruco tags. Default is 5. |
bUsingGpuMats | - Whether or not the given camera name will be using GpuMats. |
TagDetector::~TagDetector | ( | ) |
Destroy the Tag Detector:: Tag Detector object.
std::future< bool > TagDetector::RequestDetectionOverlayFrame | ( | cv::Mat & | cvFrame | ) |
Request a copy of a frame containing the tag detection overlays from the aruco and tensorflow library.
cvFrame | - The frame to copy the detection overlay image to. |
std::future< bool > TagDetector::RequestDetectedArucoTags | ( | std::vector< tagdetectutils::ArucoTag > & | vArucoTags | ) |
Request the most up to date vector of detected tags from OpenCV's Aruco algorithm.
vArucoTags | - The vector the detected aruco tags will be saved to. |
bool TagDetector::InitTorchDetection | ( | const std::string & | szModelPath, |
yolomodel::pytorch::PyTorchInterpreter::HardwareDevices | eDevice = yolomodel::pytorch::PyTorchInterpreter::HardwareDevices::eCUDA |
||
) |
Attempt to open the next available Torch hardware and load model at the given path onto the device.
szModelPath | - The absolute path to the model to open. |
eDevice | - The hardware device to launch the Torch model on. |
void TagDetector::EnableTorchDetection | ( | const float | fMinObjectConfidence = 0.4f , |
const float | fNMSThreshold = 0.6f |
||
) |
Turn on torch detection with given parameters.
fMinObjectConfidence | - The lower limit of detection confidence. |
fNMSThreshold | - The overlap thresh for NMS algorithm. |
void TagDetector::DisableTorchDetection | ( | ) |
Set flag to stop tag detection with the torch model.
void TagDetector::SetDetectorMaxFPS | ( | const int | nRecordingFPS | ) |
Mutator for the desired max FPS for this detector.
nRecordingFPS | - The max frames per second to detect tags at. |
void TagDetector::SetEnableRecordingFlag | ( | const bool | bEnableRecordingFlag | ) |
Mutator for the Enable Recording Flag private member.
bEnableRecordingFlag | - Whether or not recording should be enabled for this detector. |
bool TagDetector::GetIsReady | ( | ) |
Accessor for the status of this TagDetector.
int TagDetector::GetDetectorMaxFPS | ( | ) | const |
Accessor for the desired max FPS for this detector.
bool TagDetector::GetEnableRecordingFlag | ( | ) | const |
Accessor for the Enable Recording Flag private member.
std::string TagDetector::GetCameraName | ( | ) |
Accessor for the camera name or path that this TagDetector is tied to.
cv::Size TagDetector::GetProcessFrameResolution | ( | ) | const |
Accessor for the resolution of the process image used for tag detection.
|
overrideprivatevirtual |
This code will run continuously in a separate thread. New frames from the given camera are grabbed and the tags for the camera image are detected, filtered, and stored. Then any requests for the current tags are fulfilled.
Implements AutonomyThread< void >.
|
overrideprivatevirtual |
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method. It copies the data from the different data objects to references of the same type stored in a queue filled by the Request methods.
Implements AutonomyThread< void >.
|
private |
Updates the detected torch tags including tracking the detected tags over time and removing tags that haven't been seen for long enough.
vNewlyDetectedTags | - Input vector of TorchTag structs containing the tag info. |