12#ifndef TENSORFLOW_TAG_DETECTION_HPP
13#define TENSORFLOW_TAG_DETECTION_HPP
15#include "../../util/vision/YOLOModel.hpp"
19#include <opencv2/opencv.hpp>
50 double dConfidence = 0.0;
51 double dStraightLineDistance = 0.0;
52 double dYawAngle = 0.0;
70 cvCenter.
x += stTag.CornerBL.
x + stTag.CornerBR.
x + stTag.CornerTL.
x + stTag.CornerTR.
x;
71 cvCenter.
y += stTag.CornerBL.
y + stTag.CornerBR.
y + stTag.CornerTL.
y + stTag.CornerTR.
y;
96 const float fMinObjectConfidence = 0.40f,
97 const float fNMSThreshold = 0.60f)
103 LOG_ERROR(logging::g_qSharedLogger,
"Detect() requires a RGB image.");
108 std::vector<TensorflowTag> vDetectedTags;
114 std::vector<std::vector<yolomodel::Detection>> vOutputTensorTags = tfTensorflowDetector.
Inference(cvFrame, fMinObjectConfidence, fNMSThreshold);
117 for (std::vector<yolomodel::Detection> vTagDetections : vOutputTensorTags)
124 stDetectedTag.dConfidence = stTagDetection.fConfidence;
125 stDetectedTag.CornerTL =
cv::Point2f(stTagDetection.cvBoundingBox.x, stTagDetection.cvBoundingBox.y);
126 stDetectedTag.CornerTR =
cv::Point2f(stTagDetection.cvBoundingBox.x + stTagDetection.cvBoundingBox.width, stTagDetection.cvBoundingBox.y);
127 stDetectedTag.CornerBL =
cv::Point2f(stTagDetection.cvBoundingBox.x, stTagDetection.cvBoundingBox.y + stTagDetection.cvBoundingBox.height);
128 stDetectedTag.CornerBR =
cv::Point2f(stTagDetection.cvBoundingBox.x + stTagDetection.cvBoundingBox.width,
129 stTagDetection.cvBoundingBox.y + stTagDetection.cvBoundingBox.height);
132 vDetectedTags.emplace_back(stDetectedTag);
139 LOG_WARNING(logging::g_qSharedLogger,
140 "TensorflowDetect: Unable to detect tags using YOLO tensorflow detection because hardware is not opened or model is not initialized.");
144 return vDetectedTags;
162 if (!cvDetectionsFrame.
empty() && (cvDetectionsFrame.
channels() == 1 || cvDetectionsFrame.
channels() == 3))
171 cv::Point(stTag.CornerTL.x, stTag.CornerTL.y - 20),
172 cv::Point(stTag.CornerTR.x, stTag.CornerTL.y),
177 "Tag Conf: " + std::to_string(stTag.dConfidence),
178 cv::Point(stTag.CornerTL.x, stTag.CornerTL.y - 5),
187 LOG_ERROR(logging::g_qSharedLogger,
188 "TensorflowDetect: Unable to draw markers on image because it is empty or because it has {} channels. (Should be 1 or 3)",
208 if (constants::ZED_COORD_SYSTEM != sl::COORDINATE_SYSTEM::LEFT_HANDED_Y_UP)
211 LOG_CRITICAL(logging::g_qSharedLogger,
"TensorflowDetection: Calculations won't work for anything other than ZED coordinate system == LEFT_HANDED_Y_UP");
218 if (cvCenter.
y > cvPointCloud.
rows || cvCenter.
x > cvPointCloud.
cols || cvCenter.
y < 0 || cvCenter.
x < 0)
220 LOG_ERROR(logging::g_qSharedLogger,
221 "Detected tag center ({}, {}) out of point cloud's domain ({},{})",
231 float fForward = cvCoordinate[2];
232 float fRight = cvCoordinate[0];
233 float fUp = cvCoordinate[1];
236 stTag.dStraightLineDistance =
sqrt(
pow(fForward, 2) +
pow(fRight, 2) +
pow(fUp, 2));
239 stTag.dYawAngle =
atan2(fRight, fForward);
bool GetDeviceIsOpened() const
Accessor for the Device Is Opened private member.
Definition TensorflowTPU.hpp:347
This class is designed to enable quick, easy, and robust inferencing of .tflite yolo model.
Definition YOLOModel.hpp:210
std::vector< std::vector< Detection > > Inference(const cv::Mat &cvInputFrame, const float fMinObjectConfidence=0.85, const float fNMSThreshold=0.6) override
Given an input image forward the image through the YOLO model to run inference on the EdgeTPU,...
Definition YOLOModel.hpp:270
void sqrt(InputArray src, OutputArray dst)
void pow(InputArray src, double power, OutputArray dst)
__device__ __forceinline__ float1 atan2(const uchar1 &a, const uchar1 &b)
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
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 tensorflow tag detections operations on images.
Definition TensorflowTagDetection.hpp:33
cv::Point2f FindTagCenter(const TensorflowTag &stTag)
Given an TensorflowTag struct find the center point of the corners.
Definition TensorflowTagDetection.hpp:64
void DrawDetections(cv::Mat &cvDetectionsFrame, const std::vector< TensorflowTag > &vDetectedTags)
Given a vector of TensorflowTag structs draw each tag corner and confidence onto the given image.
Definition TensorflowTagDetection.hpp:159
void EstimatePoseFromPointCloud(const cv::Mat &cvPointCloud, TensorflowTag &stTag)
Estimate the pose of a position with respect to the observer using a point cloud.
Definition TensorflowTagDetection.hpp:205
std::vector< TensorflowTag > Detect(const cv::Mat &cvFrame, yolomodel::tensorflow::TPUInterpreter &tfTensorflowDetector, const float fMinObjectConfidence=0.40f, const float fNMSThreshold=0.60f)
Detect ArUco tags in the provided image using a YOLO DNN model.
Definition TensorflowTagDetection.hpp:94
Represents a single ArUco tag. Stores all information about a specific tag detection.
Definition TensorflowTagDetection.hpp:43
This struct is used to.
Definition YOLOModel.hpp:42