7 : _frameName(frameName), _width(width), _height(height), _normalized(normalized) {}
10 std::deque<SpatialMessages::SpatialDetectionArray>& opDetectionMsgs) {
12 auto tstamp = inNetData->getTimestamp();
13 SpatialMessages::SpatialDetectionArray opDetectionMsg;
17 auto steadyTime = std::chrono::steady_clock::now();
18 auto diffTime = steadyTime - tstamp;
19 uint64_t nsec = rosNow.toNSec() - diffTime.count();
20 auto rosStamp = rosNow.fromNSec(nsec);
21 opDetectionMsg.header.stamp = rosStamp;
22 opDetectionMsg.header.seq = inNetData->getSequenceNum();
24 auto rclNow = rclcpp::Clock().now();
25 auto steadyTime = std::chrono::steady_clock::now();
26 auto diffTime = steadyTime - tstamp;
27 auto rclStamp = rclNow - diffTime;
28 opDetectionMsg.header.stamp = rclStamp;
32 opDetectionMsg.detections.resize(inNetData->detections.size());
36 for(
int i = 0; i < inNetData->detections.size(); ++i) {
37 int xMin, yMin, xMax, yMax;
39 xMin = inNetData->detections[i].xmin;
40 yMin = inNetData->detections[i].ymin;
41 xMax = inNetData->detections[i].xmax;
42 yMax = inNetData->detections[i].ymax;
44 xMin = inNetData->detections[i].xmin *
_width;
45 yMin = inNetData->detections[i].ymin *
_height;
46 xMax = inNetData->detections[i].xmax *
_width;
47 yMax = inNetData->detections[i].ymax *
_height;
50 float xSize = xMax - xMin;
51 float ySize = yMax - yMin;
52 float xCenter = xMin + xSize / 2;
53 float yCenter = yMin + ySize / 2;
55 opDetectionMsg.detections[i].results.resize(1);
58 opDetectionMsg.detections[i].results[0].class_id = std::to_string(inNetData->detections[i].label);
60 opDetectionMsg.detections[i].results[0].id = std::to_string(inNetData->detections[i].label);
62 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;
74 opDetectionMsg.detections[i].position.x = inNetData->detections[i].spatialCoordinates.x / 1000;
75 opDetectionMsg.detections[i].position.y = inNetData->detections[i].spatialCoordinates.y / 1000;
76 opDetectionMsg.detections[i].position.z = inNetData->detections[i].spatialCoordinates.z / 1000;
79 opDetectionMsgs.push_back(opDetectionMsg);
83 std::deque<SpatialMessages::SpatialDetectionArray> msgQueue;
85 auto msg = msgQueue.front();
void toRosMsg(std::shared_ptr< dai::SpatialImgDetections > inNetData, std::deque< SpatialMessages::SpatialDetectionArray > &opDetectionMsg)
const std::string _frameName
SpatialDetectionArrayPtr toRosMsgPtr(std::shared_ptr< dai::SpatialImgDetections > inNetData)
SpatialDetectionConverter(std::string frameName, int width, int height, bool normalized=false)
SpatialMessages::SpatialDetectionArray::Ptr SpatialDetectionArrayPtr