12#ifndef TORCH_TAG_DETECTION_HPP
13#define TORCH_TAG_DETECTION_HPP
15#include "../../util/vision/TagDetectionUtilty.hpp"
16#include "../../util/vision/YOLOModel.hpp"
45 inline std::vector<tagdetectutils::ArucoTag>
Detect(
const cv::Mat& cvFrame,
47 const float fMinObjectConfidence = 0.40f,
48 const float fNMSThreshold = 0.60f)
54 LOG_ERROR(logging::g_qSharedLogger,
"Detect() requires a RGB image.");
59 std::vector<tagdetectutils::ArucoTag> vDetectedTags;
65 std::vector<yolomodel::Detection> vOutputTensorTags = trPyTorchDetector.
Inference(cvFrame, fMinObjectConfidence, fNMSThreshold);
72 stDetectedTag.dConfidence = stTagDetection.fConfidence;
73 stDetectedTag.pBoundingBox = std::make_shared<cv::Rect2d>(stTagDetection.cvBoundingBox);
74 stDetectedTag.nID = stTagDetection.nClassID;
75 stDetectedTag.szClassName = stTagDetection.szClassName;
76 stDetectedTag.eDetectionMethod = tagdetectutils::TagDetectionMethod::eTorch;
77 stDetectedTag.cvImageResolution = cvFrame.
size();
80 vDetectedTags.emplace_back(stDetectedTag);
86 LOG_WARNING(logging::g_qSharedLogger,
87 "TorchDetect: Unable to detect tags using YOLO torch detection because hardware is not opened or model is not initialized.");
106 if (!cvDetectionsFrame.
empty() && (cvDetectionsFrame.
channels() == 1 || cvDetectionsFrame.
channels() == 3))
112 if (stTag.eDetectionMethod == tagdetectutils::TagDetectionMethod::eTorch)
116 std::string szText = stTag.szClassName +
" " + std::to_string(
static_cast<int>(stTag.dConfidence * 100)) +
"%";
120 stTag.pBoundingBox->tl() +
cv::Point2d(0, stTag.pBoundingBox->height),
127 stTag.pBoundingBox->tl() +
cv::Point2d(0, stTag.pBoundingBox->height + cvTextSize.
height),
137 LOG_ERROR(logging::g_qSharedLogger,
138 "TorchDetect: Unable to draw markers on image because it is empty or because it has {} channels. (Should be 1 or 3)",
This class is designed to enable quick, easy, and robust inferencing of .pt yolo model.
Definition YOLOModel.hpp:710
bool IsReadyForInference() const
Check if the model is ready for inference.
Definition YOLOModel.hpp:946
std::vector< Detection > Inference(const cv::Mat &cvInputFrame, const float fMinObjectConfidence=0.85, const float fNMSThreshold=0.6)
Given an input image forward the image through the YOLO model to run inference on the PyTorch model,...
Definition YOLOModel.hpp:859
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Size getTextSize(const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
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)
Namespace containing functions related to torch tag detections operations on images using PyTorch.
Definition TorchTagDetection.hpp:32
void DrawDetections(cv::Mat &cvDetectionsFrame, const std::vector< tagdetectutils::ArucoTag > &vDetectedTags)
Given a vector of tagdetectutils::ArucoTag structs draw each tag corner and confidence onto the given...
Definition TorchTagDetection.hpp:103
std::vector< tagdetectutils::ArucoTag > Detect(const cv::Mat &cvFrame, yolomodel::pytorch::PyTorchInterpreter &trPyTorchDetector, const float fMinObjectConfidence=0.40f, const float fNMSThreshold=0.60f)
Detect ArUco tags in the provided image using a YOLO DNN model.
Definition TorchTagDetection.hpp:45
Represents a single ArUco tag. Combines attributes from TorchTag, TensorflowTag, and the original Aru...
Definition TagDetectionUtilty.hpp:59
This struct is used to.
Definition YOLOModel.hpp:45