![]() |
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.
|
This class implements a modular and easy to use object detector for a single camera. Given a camera name, this class will detect objects using the depth measure from a ZED camera and/or inferenced objects from a custom trained model. This class and it's detections are ran in a different thread. More...
#include <ObjectDetector.h>
Public Member Functions | |
ObjectDetector (BasicCamera *pBasicCam, const int nNumDetectedObjectsRetrievalThreads=5, const bool bUsingGpuMats=false) | |
Construct a new ObjectDetector object. | |
ObjectDetector (ZEDCamera *pZEDCam, const int nNumDetectedObjectsRetrievalThreads=5, const bool bUsingGpuMats=false) | |
Construct a new ObjectDetector object. | |
std::future< bool > | RequestDepthDetectionOverlayFrame (cv::Mat &cvFrame) |
Request a copy of a frame containing the object detection overlays from the depth library. | |
std::future< bool > | RequestTensorflowDetectionOverlayFrame (cv::Mat &cvFrame) |
Request a copy of a frame containing the object detection overlays from the tensorflow model. | |
std::future< bool > | RequestDetectedDepthObjects (std::vector< depthobject::DepthObject > &vDepthObjects) |
Request the most up to date vector of detected objects from OpenCV's Depth algorithm. | |
std::future< bool > | RequestDetectedTensorflowObjects (std::vector< tensorflowobject::TensorflowObject > &vTensorflowObjects) |
Request the most up to date vector of detected objects from our custom tensorflow model. | |
IPS & | GetIPS () |
Accessor for the Frame I P S private member. | |
![]() | |
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 objects for the camera image are detected, filtered, and stored. Then any requests for the current objects 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 | UpdateDetectedObjects (std::vector< depthobject::DepthObject > &vNewlyDetectedObjects) |
void | UpdateDetectedObjects (std::vector< tensorflowobject::TensorflowObject > &vNewlyDetectedObjects) |
Private Attributes | |
Camera< cv::Mat > * | m_pCamera |
bool | m_bUsingZedCamera |
bool | m_bUsingGpuMats |
int | m_nNumDetectedObjectsRetrievalThreads |
IPS | m_IPS |
std::vector< depthobject::DepthObject > | m_vDetectedDepthObjects |
std::vector< tensorflowobject::TensorflowObject > | m_vDetectedTensorObjects |
cv::Mat | m_cvNormalFrame |
cv::Mat | m_cvProcFrame |
cv::Mat | m_cvDepthMeasure |
cv::cuda::GpuMat | m_cvGPUNormalFrame |
cv::cuda::GpuMat | m_cvGPUDepthMeasure |
std::queue< containers::FrameFetchContainer< cv::Mat > > | m_qDetectedObjectDrawnOverlayFrames |
std::queue< containers::DataFetchContainer< std::vector< depthobject::DepthObject > > > | m_qDetectedDepthObjectCopySchedule |
std::queue< containers::DataFetchContainer< std::vector< tensorflowobject::TensorflowObject > > > | m_qDetectedTensorflowObjectCopySchedule |
std::shared_mutex | m_muPoolScheduleMutex |
std::mutex | m_muFrameCopyMutex |
std::mutex | m_muDepthDataCopyMutex |
std::mutex | m_muTensorflowDataCopyMutex |
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 |
This class implements a modular and easy to use object detector for a single camera. Given a camera name, this class will detect objects using the depth measure from a ZED camera and/or inferenced objects from a custom trained model. This class and it's detections are ran in a different thread.
ObjectDetector::ObjectDetector | ( | BasicCamera * | pBasicCam, |
const int | nNumDetectedObjectsRetrievalThreads = 5 , |
||
const bool | bUsingGpuMats = false |
||
) |
Construct a new ObjectDetector object.
pBasicCam | - A pointer to the BasicCam camera to get frames from for detection. |
nNumDetectedObjectsRetrievalThreads | - The number of threads to use when fulfilling requests for the detected depth objects. Default is 5. |
bUsingGpuMats | - Whether or not the given camera name will be using GpuMats. |
ObjectDetector::ObjectDetector | ( | ZEDCamera * | pZEDCam, |
const int | nNumDetectedObjectsRetrievalThreads = 5 , |
||
const bool | bUsingGpuMats = false |
||
) |
Construct a new ObjectDetector object.
pZEDCam | - A pointer to the ZEDCam camera to get frames from for detection. Override for ZED camera. |
nNumDetectedObjectsRetrievalThreads | - The number of threads to use when fulfilling requests for the detected depth objects. Default is 5. |
bUsingGpuMats | - Whether or not the given camera name will be using GpuMats. |
std::future< bool > ObjectDetector::RequestDepthDetectionOverlayFrame | ( | cv::Mat & | cvFrame | ) |
Request a copy of a frame containing the object detection overlays from the depth library.
cvFrame | - The frame to copy the detection overlay image to. |
std::future< bool > ObjectDetector::RequestTensorflowDetectionOverlayFrame | ( | cv::Mat & | cvFrame | ) |
Request a copy of a frame containing the object detection overlays from the tensorflow model.
cvFrame | - The frame to copy the detection overlay image to. |
std::future< bool > ObjectDetector::RequestDetectedDepthObjects | ( | std::vector< depthobject::DepthObject > & | vDepthObjects | ) |
Request the most up to date vector of detected objects from OpenCV's Depth algorithm.
vDepthObjects | - The vector the detected depth objects will be saved to. |
std::future< bool > ObjectDetector::RequestDetectedTensorflowObjects | ( | std::vector< tensorflowobject::TensorflowObject > & | vTensorflowObjects | ) |
Request the most up to date vector of detected objects from our custom tensorflow model.
vTensorflowObjects | - The vector the detected tensorflow objects will be saved to. |
IPS & ObjectDetector::GetIPS | ( | ) |
Accessor for the Frame I P S private member.
|
overrideprivatevirtual |
This code will run continuously in a separate thread. New frames from the given camera are grabbed and the objects for the camera image are detected, filtered, and stored. Then any requests for the current objects 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 >.