13#ifndef TAG_DETECTION_UTILITY_HPP
14#define TAG_DETECTION_UTILITY_HPP
21#include <opencv2/opencv.hpp>
60 std::shared_ptr<cv::Rect2d> pBoundingBox = std::make_shared<cv::Rect2d>();
61 double dConfidence = 0.0;
62 double dStraightLineDistance = 0.0;
63 double dYawAngle = 0.0;
65 std::string szClassName =
"";
66 std::chrono::system_clock::time_point tmCreation = std::chrono::system_clock::now();
69 double dHorizontalFOV = 0.0;
71 std::string szDetectorUUID =
"";
85 return *pBoundingBox == *stOther.pBoundingBox && dConfidence == stOther.dConfidence && dStraightLineDistance == stOther.dStraightLineDistance &&
86 dYawAngle == stOther.dYawAngle && nID == stOther.nID && szClassName == stOther.szClassName && tmCreation == stOther.tmCreation &&
87 eDetectionMethod == stOther.eDetectionMethod && cvImageResolution == stOther.cvImageResolution && dHorizontalFOV == stOther.dHorizontalFOV &&
88 stGeolocatedPosition == stOther.stGeolocatedPosition && szDetectorUUID == stOther.szDetectorUUID;
115 if (
this != &stOther)
118 pBoundingBox = stOther.pBoundingBox;
121 dConfidence = stOther.dConfidence;
122 dStraightLineDistance = stOther.dStraightLineDistance;
123 dYawAngle = stOther.dYawAngle;
125 szClassName = stOther.szClassName;
126 tmCreation = stOther.tmCreation;
127 eDetectionMethod = stOther.eDetectionMethod;
128 cvImageResolution = stOther.cvImageResolution;
129 dHorizontalFOV = stOther.dHorizontalFOV;
130 stGeolocatedPosition = stOther.stGeolocatedPosition;
131 szDetectorUUID = stOther.szDetectorUUID;
149 cv::Point2f cvCenter =
cv::Point2f(stTag.pBoundingBox->x + stTag.pBoundingBox->width / 2, stTag.pBoundingBox->y + stTag.pBoundingBox->height / 2);
176 cvObjPoints.
at<
cv::Vec3f>(3) =
cv::Vec3f{constants::ARUCO_TAG_SIDE_LENGTH, constants::ARUCO_TAG_SIDE_LENGTH, 0};
180 cvImgPoints.
at<
cv::Vec3f>(0) =
cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x),
static_cast<float>(stTag.pBoundingBox->y), 0.0f};
182 cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x),
static_cast<float>(stTag.pBoundingBox->y + stTag.pBoundingBox->height), 0.0f};
184 cv::Vec3f{
static_cast<float>(stTag.pBoundingBox->x + stTag.pBoundingBox->width),
static_cast<float>(stTag.pBoundingBox->y), 0.0f};
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),
190 cv::solvePnP(cvObjPoints, cvImgPoints, cvCameraMatrix, cvDistCoeffs, cvRotVec, cvTransVec);
193 double dForward = cvTransVec[2];
194 double dRight = cvTransVec[0];
195 double dUp = cvTransVec[1];
198 stTag.dStraightLineDistance = std::sqrt(std::pow(dForward, 2) + std::pow(dRight, 2) + std::pow(dUp, 2));
201 stTag.dYawAngle = std::atan2(dRight, dForward);
217 double dDegreesPerPixel = stTag.dHorizontalFOV / stTag.cvImageResolution.
width;
219 double dTagErrorX = (stTag.pBoundingBox->x + stTag.pBoundingBox->width / 2) - (stTag.cvImageResolution.
width / 2);
221 double dTagAngleX = dTagErrorX * dDegreesPerPixel;
223 stTag.dYawAngle = dTagAngleX;
226 stTag.dStraightLineDistance = (stTag.pBoundingBox->area() / (stTag.cvImageResolution.
width * stTag.cvImageResolution.
height)) * 100.0;
Declares constants for the autonomy software.
Implements Logging for Autonomy.
Defines and implements functions related to operations on location or orientation coordinate systems ...
bool solvePnP(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE)
Namespace containing function to assist in tag detection.
Definition TagDetectionUtilty.hpp:35
cv::Point2f FindTagCenter(const ArucoTag &stTag)
Given an tagdetectutils::ArucoTag struct find the center point of the corners.
Definition TagDetectionUtilty.hpp:146
void EstimatePoseFromPNP(cv::Mat &cvCameraMatrix, cv::Mat &cvDistCoeffs, ArucoTag &stTag)
Estimate the pose of a position with respect to the observer using an image.
Definition TagDetectionUtilty.hpp:164
TagDetectionMethod
Enum class to define the different tag detection methods available.
Definition TagDetectionUtilty.hpp:44
void EstimatePoseFromCameraFrame(ArucoTag &stTag)
Estimate the pose of a tag from a camera frame.
Definition TagDetectionUtilty.hpp:214
This struct is used by the WaypointHandler class to store location, size, and type information about ...
Definition GeospatialOperations.hpp:423
Represents a single ArUco tag.
Definition TagDetectionUtilty.hpp:57
bool operator!=(const ArucoTag &stOther) const
Overload the inequality operator for the ArucoTag struct.
Definition TagDetectionUtilty.hpp:101
bool operator==(const ArucoTag &stOther) const
Overload the equality operator for the ArucoTag struct.
Definition TagDetectionUtilty.hpp:83
ArucoTag & operator=(const ArucoTag &stOther)
Overload the assignment operator for the ArucoTag struct to perform a deep copy.
Definition TagDetectionUtilty.hpp:112