13#ifndef TAG_DETECTION_UTILITY_HPP
14#define TAG_DETECTION_UTILITY_HPP
16#include "../../AutonomyConstants.h"
17#include "../../AutonomyLogging.h"
18#include "../GeospatialOperations.hpp"
21#include <opencv2/opencv.hpp>
62 std::shared_ptr<cv::Rect2d> pBoundingBox = std::make_shared<cv::Rect2d>();
63 double dConfidence = 0.0;
64 double dStraightLineDistance = 0.0;
65 double dYawAngle = 0.0;
67 std::string szClassName =
"";
68 std::chrono::system_clock::time_point tmCreation = std::chrono::system_clock::now();
71 double dHorizontalFOV = 0.0;
86 return *pBoundingBox == *stOther.pBoundingBox && dConfidence == stOther.dConfidence && dStraightLineDistance == stOther.dStraightLineDistance &&
87 dYawAngle == stOther.dYawAngle && nID == stOther.nID && szClassName == stOther.szClassName && tmCreation == stOther.tmCreation &&
88 eDetectionMethod == stOther.eDetectionMethod && cvImageResolution == stOther.cvImageResolution && dHorizontalFOV == stOther.dHorizontalFOV &&
89 stGeolocatedPosition == stOther.stGeolocatedPosition;
116 if (
this != &stOther)
119 pBoundingBox = stOther.pBoundingBox;
122 dConfidence = stOther.dConfidence;
123 dStraightLineDistance = stOther.dStraightLineDistance;
124 dYawAngle = stOther.dYawAngle;
126 szClassName = stOther.szClassName;
127 tmCreation = stOther.tmCreation;
128 eDetectionMethod = stOther.eDetectionMethod;
129 cvImageResolution = stOther.cvImageResolution;
130 dHorizontalFOV = stOther.dHorizontalFOV;
131 stGeolocatedPosition = stOther.stGeolocatedPosition;
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;
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:392
Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original Aru...
Definition TagDetectionUtilty.hpp:59
bool operator!=(const ArucoTag &stOther) const
Overload the inequality operator for the ArucoTag struct.
Definition TagDetectionUtilty.hpp:102
bool operator==(const ArucoTag &stOther) const
Overload the equality operator for the ArucoTag struct.
Definition TagDetectionUtilty.hpp:84
ArucoTag & operator=(const ArucoTag &stOther)
Overload the assignment operator for the ArucoTag struct to perform a deep copy.
Definition TagDetectionUtilty.hpp:113