8 : _frameName(frameName), _width(width), _height(height), _normalized(normalized) {}
12 auto tstamp = inNetData->getTimestamp();
13 VisionMsgs::Detection2DArray opDetectionMsg;
16 auto steadyTime = std::chrono::steady_clock::now();
17 auto diffTime = steadyTime - tstamp;
18 uint64_t nsec = rosNow.toNSec() - diffTime.count();
19 auto rosStamp = rosNow.fromNSec(nsec);
20 opDetectionMsg.header.stamp = rosStamp;
21 opDetectionMsg.header.seq = inNetData->getSequenceNum();
23 auto rclNow = rclcpp::Clock().now();
24 auto steadyTime = std::chrono::steady_clock::now();
25 auto diffTime = steadyTime - tstamp;
26 auto rclStamp = rclNow - diffTime;
27 opDetectionMsg.header.stamp = rclStamp;
31 opDetectionMsg.detections.resize(inNetData->detections.size());
35 for(
int i = 0; i < inNetData->detections.size(); ++i) {
36 int xMin, yMin, xMax, yMax;
38 xMin = inNetData->detections[i].xmin;
39 yMin = inNetData->detections[i].ymin;
40 xMax = inNetData->detections[i].xmax;
41 yMax = inNetData->detections[i].ymax;
43 xMin = inNetData->detections[i].xmin *
_width;
44 yMin = inNetData->detections[i].ymin *
_height;
45 xMax = inNetData->detections[i].xmax *
_width;
46 yMax = inNetData->detections[i].ymax *
_height;
49 float xSize = xMax - xMin;
50 float ySize = yMax - yMin;
51 float xCenter = xMin + xSize / 2;
52 float yCenter = yMin + ySize / 2;
54 opDetectionMsg.detections[i].results.resize(1);
57 opDetectionMsg.detections[i].id = std::to_string(inNetData->detections[i].label);
58 opDetectionMsg.detections[i].results[0].hypothesis.class_id = std::to_string(inNetData->detections[i].label);
59 opDetectionMsg.detections[i].results[0].hypothesis.score = inNetData->detections[i].confidence;
61 opDetectionMsg.detections[i].results[0].id = std::to_string(inNetData->detections[i].label);
62 opDetectionMsg.detections[i].results[0].score = inNetData->detections[i].confidence;
64 opDetectionMsg.detections[i].results[0].id = inNetData->detections[i].label;
65 opDetectionMsg.detections[i].results[0].score = inNetData->detections[i].confidence;
67 opDetectionMsg.detections[i].bbox.center.x = xCenter;
68 opDetectionMsg.detections[i].bbox.center.y = yCenter;
69 opDetectionMsg.detections[i].bbox.size_x = xSize;
70 opDetectionMsg.detections[i].bbox.size_y = ySize;
73 opDetectionMsgs.push_back(opDetectionMsg);
77 std::deque<VisionMsgs::Detection2DArray> msgQueue;
79 auto msg = msgQueue.front();
ImgDetectionConverter(std::string frameName, int width, int height, bool normalized=false)
const std::string _frameName
VisionMsgs::Detection2DArray::Ptr Detection2DArrayPtr
Detection2DArrayPtr toRosMsgPtr(std::shared_ptr< dai::ImgDetections > inNetData)
void toRosMsg(std::shared_ptr< dai::ImgDetections > inNetData, std::deque< VisionMsgs::Detection2DArray > &opDetectionMsgs)