FastDeploy  latest
Fast & Easy to Deploy!
preprocessor.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 
15 #pragma once
16 #include "fastdeploy/vision/common/processors/transform.h"
17 #include "fastdeploy/vision/common/result.h"
18 
19 namespace fastdeploy {
20 namespace vision {
21 namespace detection {
24 class FASTDEPLOY_DECL RKYOLOPreprocessor {
25  public:
29 
37  bool Run(std::vector<FDMat>* images, std::vector<FDTensor>* outputs);
38 
40  void SetSize(const std::vector<int>& size) { size_ = size; }
41 
43  std::vector<int> GetSize() const { return size_; }
44 
46  void SetPaddingValue(const std::vector<float>& padding_value) {
47  padding_value_ = padding_value;
48  }
49 
51  std::vector<float> GetPaddingValue() const { return padding_value_; }
52 
55  void SetScaleUp(bool is_scale_up) { is_scale_up_ = is_scale_up; }
56 
58  bool GetScaleUp() const { return is_scale_up_; }
59 
60  std::vector<std::vector<int>> GetPadHWValues() const {
61  return pad_hw_values_;
62  }
63  std::vector<float> GetScale() const { return scale_; }
64 
65  protected:
66  bool Preprocess(FDMat* mat, FDTensor* output);
67 
68  void LetterBox(FDMat* mat);
69 
70  // target size, tuple of (width, height), default size = {640, 640}
71  std::vector<int> size_;
72 
73  // padding value, size should be the same as channels
74  std::vector<float> padding_value_;
75 
76  // only pad to the minimum rectange which height and width is times of stride
77  bool is_mini_pad_;
78 
79  // while is_mini_pad = false and is_no_pad = true,
80  // will resize the image to the set size
81  bool is_no_pad_;
82 
83  // if is_scale_up is false, the input image only can be zoom out,
84  // the maximum resize scale cannot exceed 1.0
85  bool is_scale_up_;
86 
87  // padding stride, for is_mini_pad
88  int stride_;
89 
90  // for offseting the boxes by classes when using NMS
91  float max_wh_;
92 
93  std::vector<std::vector<int>> pad_hw_values_;
94  std::vector<float> scale_;
95 };
96 
97 } // namespace detection
98 } // namespace vision
99 } // namespace fastdeploy
void SetPaddingValue(const std::vector< float > &padding_value)
Set padding value, size should be the same as channels.
Definition: preprocessor.h:46
std::vector< float > GetPaddingValue() const
Get padding value, size should be the same as channels.
Definition: preprocessor.h:51
void SetSize(const std::vector< int > &size)
Set target size, tuple of (width, height), default size = {640, 640}.
Definition: preprocessor.h:40
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
void SetScaleUp(bool is_scale_up)
Definition: preprocessor.h:55
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
Preprocessor object for YOLOv5 serials model.
Definition: preprocessor.h:24
bool GetScaleUp() const
Get is_scale_up, default true.
Definition: preprocessor.h:58
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
std::vector< int > GetSize() const
Get target size, tuple of (width, height), default size = {640, 640}.
Definition: preprocessor.h:43