plugin  0.1.0
results.h
1 /*
2 // Copyright (C) 2020-2024 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include <opencv2/core.hpp>
24 #include <openvino/openvino.hpp>
25 
26 #include "internal_model_data.h"
27 
28 struct MetaData;
29 struct ResultBase {
30  ResultBase(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
31  : frameId(frameId),
32  metaData(metaData) {}
33  virtual ~ResultBase() {}
34 
35  int64_t frameId;
36 
37  std::shared_ptr<MetaData> metaData;
38  bool IsEmpty() {
39  return frameId < 0;
40  }
41 
42  template <class T>
43  T& asRef() {
44  return dynamic_cast<T&>(*this);
45  }
46 
47  template <class T>
48  const T& asRef() const {
49  return dynamic_cast<const T&>(*this);
50  }
51 };
52 
53 struct InferenceResult : public ResultBase {
54  std::shared_ptr<InternalModelData> internalModelData;
55  std::map<std::string, ov::Tensor> outputsData;
56 
60  ov::Tensor getFirstOutputTensor() {
61  if (outputsData.empty()) {
62  throw std::out_of_range("Outputs map is empty.");
63  }
64  return outputsData.begin()->second;
65  }
66 
69  bool IsEmpty() {
70  return outputsData.empty();
71  }
72 };
73 
75  ClassificationResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
76  : ResultBase(frameId, metaData) {}
77 
78  struct Classification {
79  unsigned int id;
80  std::string label;
81  float score;
82 
83  Classification(unsigned int id, const std::string& label, float score) : id(id), label(label), score(score) {}
84  };
85 
86  std::vector<Classification> topLabels;
87 };
88 
89 struct DetectedObject : public cv::Rect2f {
90  size_t labelID;
91  std::string label;
92  float confidence;
93 };
94 
95 struct DetectionResult : public ResultBase {
96  DetectionResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
97  : ResultBase(frameId, metaData) {}
98  std::vector<DetectedObject> objects;
99 };
100 
102  RetinaFaceDetectionResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
103  : DetectionResult(frameId, metaData) {}
104  std::vector<cv::Point2f> landmarks;
105 };
106 
107 struct ImageResult : public ResultBase {
108  ImageResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
109  : ResultBase(frameId, metaData) {}
110  cv::Mat resultImage;
111 };
112 
113 struct HumanPose {
114  std::vector<cv::Point2f> keypoints;
115  float score;
116 };
117 
118 struct HumanPoseResult : public ResultBase {
119  HumanPoseResult(int64_t frameId = -1, const std::shared_ptr<MetaData>& metaData = nullptr)
120  : ResultBase(frameId, metaData) {}
121  std::vector<HumanPose> poses;
122  std::vector<cv::Mat> heatMaps;
123  std::vector<cv::Mat> pafs;
124 };
Definition: results.h:78
Definition: results.h:74
Definition: results.h:89
Definition: results.h:95
Definition: results.h:118
Definition: results.h:113
Definition: results.h:107
Definition: results.h:53
bool IsEmpty()
Definition: results.h:69
ov::Tensor getFirstOutputTensor()
Definition: results.h:60
Definition: metadata.h:20
Definition: results.h:29
Definition: results.h:101