FastDeploy  latest
Fast & Easy to Deploy!
result.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 #include "fastdeploy/fastdeploy_model.h"
16 #include "opencv2/core/core.hpp"
17 #include <set>
18 
19 namespace fastdeploy {
23 namespace vision {
24 enum FASTDEPLOY_DECL ResultType {
25  UNKNOWN_RESULT,
26  CLASSIFY,
27  DETECTION,
28  SEGMENTATION,
29  OCR,
30  MOT,
31  FACE_DETECTION,
32  FACE_ALIGNMENT,
33  FACE_RECOGNITION,
34  MATTING,
35  MASK,
36  KEYPOINT_DETECTION,
37  HEADPOSE,
38 };
39 
40 struct FASTDEPLOY_DECL BaseResult {
41  ResultType type = ResultType::UNKNOWN_RESULT;
42 };
43 
46 struct FASTDEPLOY_DECL ClassifyResult : public BaseResult {
47  ClassifyResult() = default;
49  std::vector<int32_t> label_ids;
51  std::vector<float> scores;
52  ResultType type = ResultType::CLASSIFY;
53 
55  void Resize(int size);
56 
58  void Clear();
59 
61  void Free();
62 
64  ClassifyResult(const ClassifyResult& other) = default;
66  ClassifyResult& operator=(ClassifyResult&& other);
67 
69  std::string Str();
70 };
71 
74 struct FASTDEPLOY_DECL Mask : public BaseResult {
76  std::vector<uint8_t> data;
78  std::vector<int64_t> shape; // (H,W) ...
79  ResultType type = ResultType::MASK;
80 
82  void Clear();
83 
85  void Free();
86 
88  void* Data() { return data.data(); }
89 
91  const void* Data() const { return data.data(); }
92 
94  void Reserve(int size);
95 
97  void Resize(int size);
98 
100  std::string Str();
101 };
102 
103 
106 struct FASTDEPLOY_DECL DetectionResult : public BaseResult {
107  DetectionResult() = default;
110  std::vector<std::array<float, 4>> boxes;
113  std::vector<float> scores;
115  std::vector<int32_t> label_ids;
118  std::vector<Mask> masks;
120  bool contain_masks = false;
121 
122  ResultType type = ResultType::DETECTION;
123 
125  DetectionResult(const DetectionResult& res);
127  DetectionResult& operator=(DetectionResult&& other);
128 
130  void Clear();
131 
133  void Free();
134 
135  void Reserve(int size);
136 
137  void Resize(int size);
138 
140  std::string Str();
141 };
142 
145 struct FASTDEPLOY_DECL KeyPointDetectionResult : public BaseResult {
148  std::vector<std::array<float, 2>> keypoints;
150  std::vector<float> scores;
152  int num_joints = -1;
153 
154  ResultType type = ResultType::KEYPOINT_DETECTION;
156  void Clear();
157 
159  void Free();
160 
161  void Reserve(int size);
162 
163  void Resize(int size);
164 
166  std::string Str();
167 };
168 
169 struct FASTDEPLOY_DECL OCRResult : public BaseResult {
170  std::vector<std::array<int, 8>> boxes;
171 
172  std::vector<std::string> text;
173  std::vector<float> rec_scores;
174 
175  std::vector<float> cls_scores;
176  std::vector<int32_t> cls_labels;
177 
178  ResultType type = ResultType::OCR;
179 
180  void Clear();
181 
182  std::string Str();
183 };
184 
187 struct FASTDEPLOY_DECL MOTResult : public BaseResult {
190  std::vector<std::array<int, 4>> boxes;
193  std::vector<int> ids;
196  std::vector<float> scores;
199  std::vector<int> class_ids;
200 
201  ResultType type = ResultType::MOT;
203  void Clear();
205  std::string Str();
206 };
207 
208 
209 
212 struct FASTDEPLOY_DECL FaceDetectionResult : public BaseResult {
215  std::vector<std::array<float, 4>> boxes;
219  std::vector<std::array<float, 2>> landmarks;
223  std::vector<float> scores;
224  ResultType type = ResultType::FACE_DETECTION;
230 
231  FaceDetectionResult() { landmarks_per_face = 0; }
234  void Clear();
235 
237  void Free();
238 
239  void Reserve(int size);
240 
241  void Resize(int size);
243  std::string Str();
244 };
245 
248 struct FASTDEPLOY_DECL FaceAlignmentResult : public BaseResult {
251  std::vector<std::array<float, 2>> landmarks;
252 
253  ResultType type = ResultType::FACE_ALIGNMENT;
255  void Clear();
256 
258  void Free();
259 
260  void Reserve(int size);
261 
262  void Resize(int size);
263 
265  std::string Str();
266 };
267 
270 struct FASTDEPLOY_DECL SegmentationResult : public BaseResult {
271  SegmentationResult() = default;
275  std::vector<uint8_t> label_map;
279  std::vector<float> score_map;
281  std::vector<int64_t> shape;
283  bool contain_score_map = false;
284 
286  SegmentationResult(const SegmentationResult& other) = default;
288  SegmentationResult& operator=(SegmentationResult&& other);
289 
290  ResultType type = ResultType::SEGMENTATION;
292  void Clear();
293 
295  void Free();
296 
297  void Reserve(int size);
298 
299  void Resize(int size);
300 
302  std::string Str();
303 };
304 
307 struct FASTDEPLOY_DECL FaceRecognitionResult : public BaseResult {
310  std::vector<float> embedding;
311 
312  ResultType type = ResultType::FACE_RECOGNITION;
313 
317  void Clear();
318 
320  void Free();
321 
322  void Reserve(int size);
323 
324  void Resize(int size);
326  std::string Str();
327 };
328 
331 struct FASTDEPLOY_DECL MattingResult : public BaseResult {
335  std::vector<float> alpha; // h x w
339  std::vector<float> foreground; // h x w x c (c=3 default)
343  std::vector<int64_t> shape;
347  bool contain_foreground = false;
348 
349  ResultType type = ResultType::MATTING;
350 
351  MattingResult() {}
352  MattingResult(const MattingResult& res);
354  void Clear();
355 
357  void Free();
358 
359  void Reserve(int size);
360 
361  void Resize(int size);
363  std::string Str();
364 };
365 
368 struct FASTDEPLOY_DECL HeadPoseResult : public BaseResult {
371  std::vector<float> euler_angles;
372 
373  ResultType type = ResultType::HEADPOSE;
375  void Clear();
376 
378  void Free();
379 
380  void Reserve(int size);
381 
382  void Resize(int size);
383 
385  std::string Str();
386 };
387 
388 
389 } // namespace vision
390 } // namespace fastdeploy
Face recognition result structure for all the Face recognition models.
Definition: result.h:307
std::vector< int > ids
All the tracking object ids.
Definition: result.h:193
std::vector< uint8_t > label_map
label_map stores the pixel-level category labels for input image. the number of pixels is equal to la...
Definition: result.h:275
std::vector< float > scores
The confidence for each classify result.
Definition: result.h:51
std::vector< std::array< float, 2 > > landmarks
All the coordinates of detected landmarks for an input image, and the element of landmarks is a array...
Definition: result.h:251
Definition: result.h:74
std::vector< float > scores
The confidence for all the tracking objects.
Definition: result.h:196
std::vector< int32_t > label_ids
The classify label for all the detected objects.
Definition: result.h:115
Segmentation result structure for all the segmentation models.
Definition: result.h:270
std::vector< std::array< float, 2 > > keypoints
All the coordinates of detected keypoints for an input image, the size of keypoints is num_detected_o...
Definition: result.h:148
std::vector< float > score_map
score_map stores the probability of the predicted label for each pixel of input image.
Definition: result.h:279
Face Alignment result structure for all the face alignment models.
Definition: result.h:248
std::vector< std::array< float, 4 > > boxes
All the detected object boxes for an input image, the size of boxes is the number of detected objects...
Definition: result.h:110
std::vector< std::array< float, 2 > > landmarks
If the model detect face with landmarks, every detected object box correspoing to a landmark...
Definition: result.h:219
Processor for Resize images.
Definition: resize.h:29
std::vector< std::array< float, 4 > > boxes
All the detected object boxes for an input image, the size of boxes is the number of detected objects...
Definition: result.h:215
const void * Data() const
Return a pointer of the mask data buffer for read only.
Definition: result.h:91
Detection result structure for all the object detection models and instance segmentation models...
Definition: result.h:106
Classify result structure for all the image classify models.
Definition: result.h:46
std::vector< int64_t > shape
Shape of mask.
Definition: result.h:78
std::vector< float > alpha
alpha is a one-dimensional vector, which is the predicted alpha transparency value. The range of values is [0., 1.], and the length is hxw. h, w are the height and width of the input image
Definition: result.h:335
Matting result structure for all the Matting models.
Definition: result.h:331
std::vector< int64_t > shape
The output shape, means [H, W].
Definition: result.h:281
std::vector< float > scores
Indicates the confidence of all targets detected from a single image, and the number of elements is c...
Definition: result.h:223
Face detection result structure for all the face detection models.
Definition: result.h:212
HeadPose result structure for all the headpose models.
Definition: result.h:368
std::vector< int > class_ids
The classify label id for all the tracking object.
Definition: result.h:199
std::vector< float > scores
The confidence for all the detected objects.
Definition: result.h:113
std::vector< float > foreground
If the model can predict foreground, foreground save the predicted foreground image, the shape is [hight,width,channel] generally.
Definition: result.h:339
std::vector< Mask > masks
For instance segmentation model, masks is the predict mask for all the deteced objects.
Definition: result.h:118
std::vector< float > euler_angles
EulerAngles for an input image, and the element of euler_angles is a vector, contains {yaw...
Definition: result.h:371
std::vector< int64_t > shape
The shape of output result, when contain_foreground == false, shape only contains (h...
Definition: result.h:343
int landmarks_per_face
landmarks_per_face indicates the number of face landmarks for each detected face if the model&#39;s outpu...
Definition: result.h:229
std::vector< std::array< int, 4 > > boxes
All the tracking object boxes for an input image, the size of boxes is the number of tracking objects...
Definition: result.h:190
std::vector< uint8_t > data
Mask data buffer.
Definition: result.h:76
KeyPoint Detection result structure for all the keypoint detection models.
Definition: result.h:145
void * Data()
Return a mutable pointer of the mask data buffer.
Definition: result.h:88
std::vector< float > embedding
The feature embedding that represents the final extraction of the face recognition model can be used ...
Definition: result.h:310
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
MOT(Multi-Object Tracking) result structure for all the MOT models.
Definition: result.h:187
std::vector< int32_t > label_ids
Classify result for an image.
Definition: result.h:49