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
yolomodel Namespace Reference

Namespace containing functions or objects/struct used to aid in easy use of YOLO models. Namespace can contain other namespace pertaining to the method of inference or library being used. More...

Namespaces

namespace  pytorch
 Namespace containing functions or objects/structs used to run inference on a YOLO model with the PyTorch library. This namespace contains static functions for getting available hardware devices, and classes for running a .pt model on each device. This namespace was built to work with YOLO models only!
 
namespace  tensorflow
 Namespace containing functions or objects/structs used to run inference on a YOLO model with the Tensorflow library. This namespace contains static functions for getting available hardware devices, and classes for running a .tflite model on each device. This namespace was built to work with YOLO models only!
 

Classes

struct  Detection
 This struct is used to. More...
 

Functions

void NonMaxSuppression (std::vector< Detection > &vObjects, std::vector< int > &vClassIDs, std::vector< float > &vClassConfidences, std::vector< cv::Rect > &vBoundingBoxes, float fMinObjectConfidence, float fNMSThreshold)
 Perform non max suppression for the given predictions. This eliminates/combines predictions that overlap with each other.
 
void DrawDetections (cv::Mat &cvInputFrame, std::vector< Detection > &vObjects)
 Given an image and a vector of object structs, draw each object bounding box, class type, and confidence onto the image.
 

Detailed Description

Namespace containing functions or objects/struct used to aid in easy use of YOLO models. Namespace can contain other namespace pertaining to the method of inference or library being used.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-11-11

Function Documentation

◆ NonMaxSuppression()

void yolomodel::NonMaxSuppression ( std::vector< Detection > &  vObjects,
std::vector< int > &  vClassIDs,
std::vector< float > &  vClassConfidences,
std::vector< cv::Rect > &  vBoundingBoxes,
float  fMinObjectConfidence,
float  fNMSThreshold 
)
inline

Perform non max suppression for the given predictions. This eliminates/combines predictions that overlap with each other.

Parameters
vObjects- A vector that will be filled with all of the valid/filtered predictions with their data stored in an easy-to-use struct.
vClassIDs- A reference to a vector that contains class IDs for each prediction.
vClassConfidences- A reference to a vector that contains the highest class confidence for that prediction.
vBoundingBoxes- A reference to a vector that contains a cv::Rect bounding box for each prediction.
fMinObjectConfidence- The minimum confidence for determining which predictions to throw out.
fNMSThreshold- The threshold value for filtering out weaker bounding boxes or detections.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-11-15
73 {
74 // Create instance variables.
75 std::vector<int> vNMSValidIndices;
76
77 // Perform Non-Max Suppression using OpenCV's implementation.
78 cv::dnn::NMSBoxes(vBoundingBoxes, vClassConfidences, fMinObjectConfidence, fNMSThreshold, vNMSValidIndices);
79
80 // Loop through each valid index.
81 for (int nValidIndex : vNMSValidIndices)
82 {
83 // Create new Detection struct.
84 Detection stNewDetection;
85 // Repackage prediction data into easy-to-use struct.
86 stNewDetection.nClassID = vClassIDs[nValidIndex];
87 stNewDetection.fConfidence = vClassConfidences[nValidIndex];
88 stNewDetection.cvBoundingBox = vBoundingBoxes[nValidIndex];
89
90 // Append new object detection to objects vector.
91 vObjects.emplace_back(stNewDetection);
92 }
93 }
void NMSBoxes(const std::vector< Rect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0)
This struct is used to.
Definition YOLOModel.hpp:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawDetections()

void yolomodel::DrawDetections ( cv::Mat cvInputFrame,
std::vector< Detection > &  vObjects 
)
inline

Given an image and a vector of object structs, draw each object bounding box, class type, and confidence onto the image.

Parameters
cvInputFrame- A reference to the cv::Mat to draw overlays on.
vObjects- A reference to the vector containing the object detection structs.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-11-15
106 {
107 // Loop through each detection.
108 for (Detection stObject : vObjects)
109 {
110 // Calculate the hue value based on the class ID.
111 int nHue = static_cast<int>(stObject.nClassID % 256);
112 // Set saturation and value to 1.0 for full intensity colors.
113 int nSaturation = 255;
114 int nValue = 255;
115
116 // Convert HSV to RGB
117 cv::Mat cvHSV(1, 1, CV_8UC3, cv::Scalar(nHue, nSaturation, nValue));
118 cv::cvtColor(cvHSV, cvHSV, cv::COLOR_HSV2BGR);
119 // Extract the RGB values
120 cv::Vec3b cvConvertedValues = cvHSV.at<cv::Vec3b>(0, 0);
121 cv::Scalar cvBoxColor(cvConvertedValues[2], cvConvertedValues[1], cvConvertedValues[0]);
122
123 // Draw bounding box onto image.
124 cv::rectangle(cvInputFrame, stObject.cvBoundingBox, cvBoxColor, 2);
125 // Draw classID background box onto image.
126 cv::rectangle(cvInputFrame,
127 cv::Point(stObject.cvBoundingBox.x, stObject.cvBoundingBox.y - 20),
128 cv::Point(stObject.cvBoundingBox.x + stObject.cvBoundingBox.width, stObject.cvBoundingBox.y),
129 cvBoxColor,
130 cv::FILLED);
131 // Draw class text onto image.
132 cv::putText(cvInputFrame,
133 std::to_string(stObject.nClassID) + " " + std::to_string(stObject.fConfidence),
134 cv::Point(stObject.cvBoundingBox.x, stObject.cvBoundingBox.y - 5),
136 0.5,
137 cv::Scalar(255, 255, 255));
138 }
139 }
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
COLOR_HSV2BGR
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
FONT_HERSHEY_SIMPLEX
Here is the call graph for this function:
Here is the caller graph for this function: