|
17 | 17 |
|
18 | 18 | struct MetaData; |
19 | 19 |
|
20 | | -struct ResultBase { |
21 | | - ResultBase(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr) |
| 20 | +struct InferenceResult { |
| 21 | + InferenceResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr) |
22 | 22 | : frameId(frameId), |
23 | 23 | metaData(metaData) {} |
24 | | - virtual ~ResultBase() {} |
25 | 24 |
|
| 25 | + std::shared_ptr<InternalModelData> internalModelData; |
| 26 | + std::map<std::string, ov::Tensor> outputsData; |
26 | 27 | int64_t frameId; |
27 | | - |
28 | 28 | std::shared_ptr<MetaData> metaData; |
29 | | - bool IsEmpty() { |
30 | | - return frameId < 0; |
31 | | - } |
32 | | - |
33 | | - template <class T> |
34 | | - T& asRef() { |
35 | | - return dynamic_cast<T&>(*this); |
36 | | - } |
37 | | - |
38 | | - template <class T> |
39 | | - const T& asRef() const { |
40 | | - return dynamic_cast<const T&>(*this); |
41 | | - } |
42 | | -}; |
43 | 29 |
|
44 | | -struct InferenceResult : public ResultBase { |
45 | | - std::shared_ptr<InternalModelData> internalModelData; |
46 | | - std::map<std::string, ov::Tensor> outputsData; |
47 | 30 |
|
48 | 31 | /// Returns the first output tensor |
49 | 32 | /// This function is a useful addition to direct access to outputs list as many models have only one output |
@@ -89,35 +72,22 @@ struct DetectedKeypoints { |
89 | 72 | class Label { |
90 | 73 | public: |
91 | 74 | Label() {} |
92 | | - Label(int id, std::string name): id(id), name(name) {} |
| 75 | + Label(int id, std::string name, float score): id(id), name(name), score(score) {} |
93 | 76 |
|
94 | 77 | int id; |
95 | 78 | std::string name; |
96 | | - |
97 | | - friend std::ostream& operator<< (std::ostream& os, const Label& label) { |
98 | | - return os << label.id << " (" << label.name << ")"; |
99 | | - } |
100 | | -}; |
101 | | - |
102 | | -class LabelScore { |
103 | | -public: |
104 | | - LabelScore() {} |
105 | | - LabelScore(int id, std::string name, float score): label(Label(id, name)), score(score) {} |
106 | | - LabelScore(Label label, float score): label(label), score(score) {} |
107 | | - |
108 | | - Label label; |
109 | 79 | float score; |
110 | 80 |
|
111 | | - friend std::ostream& operator<< (std::ostream& os, const LabelScore& label) { |
112 | | - return os << label.label << ": " << std::fixed << std::setprecision(3) << label.score; |
| 81 | + friend std::ostream& operator<< (std::ostream& os, const Label& label) { |
| 82 | + return os << label.id << " (" << label.name << ")" << ": " << std::fixed << std::setprecision(3) << label.score; |
113 | 83 | } |
114 | 84 | }; |
115 | 85 |
|
116 | 86 | class Mask { |
117 | 87 | public: |
118 | | - Mask(LabelScore label, cv::Rect roi, cv::Mat mask): label(label), roi(roi), mask(mask) {} |
| 88 | + Mask(Label label, cv::Rect roi, cv::Mat mask): label(label), roi(roi), mask(mask) {} |
119 | 89 |
|
120 | | - LabelScore label; |
| 90 | + Label label; |
121 | 91 | cv::Rect roi; |
122 | 92 | cv::Mat mask; |
123 | 93 |
|
@@ -152,16 +122,16 @@ static inline std::vector<Contour> getContours(const std::vector<Mask>& segmente |
152 | 122 | if (contours.size() != 1) { |
153 | 123 | throw std::runtime_error("findContours() must have returned only one contour"); |
154 | 124 | } |
155 | | - combined_contours.push_back({obj.label.label.name, obj.label.score, contours[0]}); |
| 125 | + combined_contours.push_back({obj.label.name, obj.label.score, contours[0]}); |
156 | 126 | } |
157 | 127 | return combined_contours; |
158 | 128 | } |
159 | 129 |
|
160 | 130 | class Box { |
161 | 131 | public: |
162 | | - Box(cv::Rect shape, std::vector<LabelScore> labels): shape(shape), labels(labels) {} |
| 132 | + Box(cv::Rect shape, std::vector<Label> labels): shape(shape), labels(labels) {} |
163 | 133 | cv::Rect shape; |
164 | | - std::vector<LabelScore> labels; |
| 134 | + std::vector<Label> labels; |
165 | 135 |
|
166 | 136 | friend std::ostream& operator<< (std::ostream& os, const Box& box) { |
167 | 137 |
|
@@ -189,7 +159,7 @@ class Box { |
189 | 159 |
|
190 | 160 | class RotatedRect { |
191 | 161 | public: |
192 | | - LabelScore label; |
| 162 | + Label label; |
193 | 163 | cv::RotatedRect shape; |
194 | 164 |
|
195 | 165 | friend std::ostream& operator<< (std::ostream& os, const RotatedRect& box) { |
|
0 commit comments