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

Namespace containing function to assist in tag detection. More...

Classes

struct  ArucoTag
 Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original ArucoTag structs. More...
 

Enumerations

enum class  TagDetectionMethod { eUnknown , eOpenCV , eTorch , eTensorflow }
 Enum class to define the different tag detection methods available. More...
 

Functions

cv::Point2f FindTagCenter (const ArucoTag &stTag)
 Given an tagdetectutils::ArucoTag struct find the center point of the corners.
 
void EstimatePoseFromPNP (cv::Mat &cvCameraMatrix, cv::Mat &cvDistCoeffs, ArucoTag &stTag)
 Estimate the pose of a position with respect to the observer using an image.
 
void EstimatePoseFromCameraFrame (ArucoTag &stTag)
 
  • Estimate the pose of a tag from a camera frame.

 

Detailed Description

Namespace containing function to assist in tag detection.

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

Enumeration Type Documentation

◆ TagDetectionMethod

Enum class to define the different tag detection methods available.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-04-03
44 {
45 eUnknown, // Unknown detection method.
46 eOpenCV, // Standard OpenCV detection using the ArUco library.
47 eTorch, // Torch detection using a YOLO model.
48 eTensorflow // Tensorflow detection using a YOLO model.
49 };

Function Documentation

◆ FindTagCenter()

cv::Point2f tagdetectutils::FindTagCenter ( const ArucoTag stTag)
inline

Given an tagdetectutils::ArucoTag struct find the center point of the corners.

Parameters
stTag- The tag to find the center of.
Returns
cv::Point2f - The resultant center point within the image.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2025-02-13
147 {
148 // Calculate the center point of the tag.
149 cv::Point2f cvCenter = cv::Point2f(stTag.pBoundingBox->x + stTag.pBoundingBox->width / 2, stTag.pBoundingBox->y + stTag.pBoundingBox->height / 2);
150
151 return cvCenter;
152 }
Point_< float > Point2f

◆ EstimatePoseFromPNP()

void tagdetectutils::EstimatePoseFromPNP ( cv::Mat cvCameraMatrix,
cv::Mat cvDistCoeffs,
ArucoTag stTag 
)
inline

Estimate the pose of a position with respect to the observer using an image.

Parameters
cvCameraMatrix- Matrix of camera's parameters including focal length and optical center.
cvDistCoeffs- Matrix of the camera's distortion coefficients.
stTag- The tag we are estimating the pose of and then storing the distance and angle calculations in.
Author
jspencerpittman (jspen.nosp@m.cerp.nosp@m.ittma.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-06
165 {
166 // rotVec is how the tag is orientated with respect to the camera. It's 3 numbers defining an axis of rotation around which we rotate the angle which is the
167 // euclidean distance of the vector. transVec is the XYZ translation of the tag from the camera if you image the convergence of light as a pinhole sitting at
168 // (0,0,0) in space.
169 cv::Vec3d cvRotVec, cvTransVec;
170
171 // Set expected object coordinate system shape.
172 cv::Mat cvObjPoints(4, 1, CV_32FC3);
173 cvObjPoints.at<cv::Vec3f>(0) = cv::Vec3f{0, 0, 0}; // Top-left corner.
174 cvObjPoints.at<cv::Vec3f>(1) = cv::Vec3f{constants::ARUCO_TAG_SIDE_LENGTH, 0, 0}; // Bottom-left corner.
175 cvObjPoints.at<cv::Vec3f>(2) = cv::Vec3f{0, constants::ARUCO_TAG_SIDE_LENGTH, 0}; // Top-right corner.
176 cvObjPoints.at<cv::Vec3f>(3) = cv::Vec3f{constants::ARUCO_TAG_SIDE_LENGTH, constants::ARUCO_TAG_SIDE_LENGTH, 0}; // Bottom-right corner.
177
178 // Repackage tag image points into a mat.
179 cv::Mat cvImgPoints(4, 1, CV_32FC3);
180 cvImgPoints.at<cv::Vec3f>(0) = cv::Vec3f{static_cast<float>(stTag.pBoundingBox->x), static_cast<float>(stTag.pBoundingBox->y), 0.0f}; // Top-left corner.
181 cvImgPoints.at<cv::Vec3f>(1) =
182 cv::Vec3f{static_cast<float>(stTag.pBoundingBox->x), static_cast<float>(stTag.pBoundingBox->y + stTag.pBoundingBox->height), 0.0f}; // Bottom-left corner.
183 cvImgPoints.at<cv::Vec3f>(2) =
184 cv::Vec3f{static_cast<float>(stTag.pBoundingBox->x + stTag.pBoundingBox->width), static_cast<float>(stTag.pBoundingBox->y), 0.0f}; // Top-right corner.
185 cvImgPoints.at<cv::Vec3f>(3) = cv::Vec3f{static_cast<float>(stTag.pBoundingBox->x + stTag.pBoundingBox->width),
186 static_cast<float>(stTag.pBoundingBox->y + stTag.pBoundingBox->height),
187 0.0f}; // Bottom-right corner.
188
189 // Use solve perspective n' point algorithm to estimate pose of the tag.
190 cv::solvePnP(cvObjPoints, cvImgPoints, cvCameraMatrix, cvDistCoeffs, cvRotVec, cvTransVec);
191
192 // Grab (x,y,z) coordinates from where the tag was detected
193 double dForward = cvTransVec[2];
194 double dRight = cvTransVec[0];
195 double dUp = cvTransVec[1];
196
197 // Calculate euclidean distance from ZED camera left eye to the point of interest
198 stTag.dStraightLineDistance = std::sqrt(std::pow(dForward, 2) + std::pow(dRight, 2) + std::pow(dUp, 2));
199
200 // Calculate the angle on plane horizontal to the viewpoint
201 stTag.dYawAngle = std::atan2(dRight, dForward);
202 }
bool solvePnP(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE)
Here is the call graph for this function:

◆ EstimatePoseFromCameraFrame()

void tagdetectutils::EstimatePoseFromCameraFrame ( ArucoTag stTag)
inline

  • Estimate the pose of a tag from a camera frame.

Parameters
stTag- The tag to estimate the pose of.
Note
In order for this to be accurate, the camera's horizontal field of view (HFOV) and the camera frame size must be known.
Author
sam_hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com) :3
Date
2025-04-04
215 {
216 // Use camera field of view and camera frame size to determine tag angle in degrees from center of camera.
217 double dDegreesPerPixel = stTag.dHorizontalFOV / stTag.cvImageResolution.width;
218 // Find tag error in pixels from center of image.
219 double dTagErrorX = (stTag.pBoundingBox->x + stTag.pBoundingBox->width / 2) - (stTag.cvImageResolution.width / 2);
220 // Find angle error.
221 double dTagAngleX = dTagErrorX * dDegreesPerPixel;
222 // Reassign yaw and distance to tag.
223 stTag.dYawAngle = dTagAngleX;
224
225 // For the distance, we'll just use the screen percentage of the tag.
226 stTag.dStraightLineDistance = (stTag.pBoundingBox->area() / (stTag.cvImageResolution.width * stTag.cvImageResolution.height)) * 100.0;
227 }
Here is the caller graph for this function: