SubZero Common
Common library components for an FRC CommandRobot
Loading...
Searching...
No Matches
DetectionParser.h
Go to the documentation of this file.
1#ifndef DETECTION_PARSER_H
2#define DETECTION_PARSER_H
3
4#include <array>
5#include <utility>
6#include <vector>
7
9
10namespace subzero {
11namespace DetectionParser {
12
14 // An ordered pair representing X and Y of the top left coordinate
15 std::pair<double, double> topLeft;
16 // An ordered pair representing X and Y of the bottom right coordinate
17 std::pair<double, double> bottomRight;
18 double width;
19 double height;
20
21 // [topLeftY, topLeftX, bottomRightY, bottomRightX]
22 static BoundingBox parse(std::array<double, 4> boxes) {
23 return {std::make_pair(boxes.at(1), boxes.at(0)), // top-left (X, Y)
24 std::make_pair(boxes.at(3), boxes.at(2)), // bottom-right (X, y)
25 boxes.at(3) - boxes.at(1), // width
26 boxes.at(2) - boxes.at(0)}; // height
27 }
28};
29
32 double confidence;
34
35 static std::vector<DetectedObject>
36 parse(std::vector<double> flattenedOutputList) {
37 std::vector<DetectedObject> detectedObjects;
38 detectedObjects.reserve(10);
39
40 int entryNum = flattenedOutputList.at(0);
41
42 for (int i = 0; i < entryNum; i++) {
43 int startNum = i * 6 + 1;
44 auto bound =
45 std::array<double, 4>({flattenedOutputList.at(startNum + 2),
46 flattenedOutputList.at(startNum + 3),
47 flattenedOutputList.at(startNum + 4),
48 flattenedOutputList.at(startNum + 5)});
49 DetectedObject box = {
50 (ObjectClasses)flattenedOutputList.at(startNum), // classId
51 flattenedOutputList.at(startNum + 1), // confidence score
52 BoundingBox::parse(bound)}; // bbox
53 detectedObjects.push_back(box);
54 }
55 return detectedObjects;
56 }
57};
58} // namespace DetectionParser
59} // namespace subzero
60
61#endif
std::pair< double, double > bottomRight
std::pair< double, double > topLeft
static BoundingBox parse(std::array< double, 4 > boxes)
static std::vector< DetectedObject > parse(std::vector< double > flattenedOutputList)