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
ObjectDetectionUtility.hpp
1
14#ifndef OBJECT_DETECTION_UTILITY_HPP
15#define OBJECT_DETECTION_UTILITY_HPP
16
17#include "../../AutonomyConstants.h"
18#include "../../AutonomyLogging.h"
19#include "../GeospatialOperations.hpp"
20
22#include <opencv2/opencv.hpp>
23
25
27
28
36{
37
45 {
46 eUnknown, // Unknown detection method.
47 eTorch, // Torch detection using a YOLO model.
48 };
49
50
58 {
59 eUnknown, // Unknown detection type.
60 eMallet, // Detection is a mallet.
61 eWaterBottle, // Detection is a water bottle.
62 eRockPick // Detection is a rock pick.
63 };
64
65
72 struct Object
73 {
74 public:
75 // Declare public struct member attributes.
76 std::shared_ptr<cv::Rect2d> pBoundingBox = std::make_shared<cv::Rect2d>(); // The bounding box of the detected object.
77 double dConfidence = 0.0; // The detection confidence of the object (from Torch models).
78 double dStraightLineDistance = 0.0; // Distance between the object and the camera.
79 double dYawAngle = 0.0; // This is the yaw angle so roll and pitch are ignored.
80 std::string szClassName = ""; // The class name of the object (used in Torch models).
81 std::chrono::system_clock::time_point tmCreation = std::chrono::system_clock::now(); // Set the time detected to the minimum time point.
82 ObjectDetectionMethod eDetectionMethod = ObjectDetectionMethod::eUnknown; // The detection method used to detect the object.
83 ObjectDetectionType eDetectionType = ObjectDetectionType::eUnknown; // The detection type used to detect the object.
84 cv::Size cvImageResolution = cv::Size(0, 0); // The resolution of the image used to detect the object.
85 double dHorizontalFOV = 0.0; // The horizontal field of view of the camera used to detect the object.
86 geoops::Waypoint stGeolocatedPosition = geoops::Waypoint(); // The geolocated position of the object.
87 std::string szDetectorUUID = ""; // The UUID of the detector that detected the object. This is used to associate objects with their detectors.
88
89
99 bool operator==(const Object& stOther) const
100 {
101 return *pBoundingBox == *stOther.pBoundingBox && dConfidence == stOther.dConfidence && dStraightLineDistance == stOther.dStraightLineDistance &&
102 dYawAngle == stOther.dYawAngle && szClassName == stOther.szClassName && tmCreation == stOther.tmCreation &&
103 eDetectionMethod == stOther.eDetectionMethod && eDetectionType == stOther.eDetectionType && cvImageResolution == stOther.cvImageResolution &&
104 dHorizontalFOV == stOther.dHorizontalFOV && stGeolocatedPosition == stOther.stGeolocatedPosition && szDetectorUUID == stOther.szDetectorUUID;
105 }
106
107
117 bool operator!=(const Object& stOther) const { return !(*this == stOther); }
118
119
128 Object& operator=(const Object& stOther)
129 {
130 // Check if the other Object is not the same as this one.
131 if (this != &stOther)
132 {
133 // Shallow copy the bounding box.
134 pBoundingBox = stOther.pBoundingBox;
135
136 // Copy other member variables.
137 dConfidence = stOther.dConfidence;
138 dStraightLineDistance = stOther.dStraightLineDistance;
139 dYawAngle = stOther.dYawAngle;
140 szClassName = stOther.szClassName;
141 tmCreation = stOther.tmCreation;
142 eDetectionMethod = stOther.eDetectionMethod;
143 eDetectionType = stOther.eDetectionType;
144 cvImageResolution = stOther.cvImageResolution;
145 dHorizontalFOV = stOther.dHorizontalFOV;
146 stGeolocatedPosition = stOther.stGeolocatedPosition;
147 szDetectorUUID = stOther.szDetectorUUID;
148 }
149 return *this;
150 }
151 };
152
153
162 inline cv::Point2f FindObjectCenter(const Object& stObject)
163 {
164 // Find the center of the object.
165 return cv::Point2f(stObject.pBoundingBox->x + stObject.pBoundingBox->width / 2, stObject.pBoundingBox->y + stObject.pBoundingBox->height / 2);
166 }
167
168
179 {
180 // Use camera field of view and camera frame size to determine tag angle in degrees from center of camera.
181 double dDegreesPerPixel = stTag.dHorizontalFOV / stTag.cvImageResolution.width;
182 // Find tag error in pixels from center of image.
183 double dTagErrorX = (stTag.pBoundingBox->x + stTag.pBoundingBox->width / 2) - (stTag.cvImageResolution.width / 2);
184 // Find angle error.
185 double dTagAngleX = dTagErrorX * dDegreesPerPixel;
186 // Reassign yaw and distance to tag.
187 stTag.dYawAngle = dTagAngleX;
188
189 // For the distance, we'll just use the screen percentage of the tag.
190 stTag.dStraightLineDistance = (stTag.pBoundingBox->area() / (stTag.cvImageResolution.width * stTag.cvImageResolution.height)) * 100.0;
191 }
192} // namespace objectdetectutils
193
194#endif
Size2i Size
Point_< float > Point2f
Namespace containing functions to assist in object detection.
Definition ObjectDetectionUtility.hpp:36
void EstimatePoseFromCameraFrame(Object &stTag)
Estimate the pose of a tag from a camera frame.
Definition ObjectDetectionUtility.hpp:178
ObjectDetectionType
Enum class to define the different object detection types available.
Definition ObjectDetectionUtility.hpp:58
cv::Point2f FindObjectCenter(const Object &stObject)
Find the center of an object.
Definition ObjectDetectionUtility.hpp:162
ObjectDetectionMethod
Enum class to define the different object detection methods available.
Definition ObjectDetectionUtility.hpp:45
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:423
Represents a single detected object.
Definition ObjectDetectionUtility.hpp:73
bool operator==(const Object &stOther) const
Overridden operator equals for Object struct.
Definition ObjectDetectionUtility.hpp:99
Object & operator=(const Object &stOther)
Overload the assignment operator for the Object struct to perform a deep copy.
Definition ObjectDetectionUtility.hpp:128
bool operator!=(const Object &stOther) const
Overridden operator equals for Object struct.
Definition ObjectDetectionUtility.hpp:117