FastDeploy  latest
Fast & Easy to Deploy!
det_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/manager.h"
17 #include "fastdeploy/vision/common/processors/resize.h"
18 #include "fastdeploy/vision/common/processors/pad.h"
19 #include "fastdeploy/vision/common/processors/normalize_and_permute.h"
20 #include "fastdeploy/vision/common/result.h"
21 
22 namespace fastdeploy {
23 namespace vision {
24 
25 namespace ocr {
28 class FASTDEPLOY_DECL DBDetectorPreprocessor : public ProcessorManager {
29  public:
31 
38  virtual bool Apply(FDMatBatch* image_batch, std::vector<FDTensor>* outputs);
39 
41  void SetMaxSideLen(int max_side_len) { max_side_len_ = max_side_len; }
42 
44  int GetMaxSideLen() const { return max_side_len_; }
45 
49  void SetNormalize(const std::vector<float>& mean,
50  const std::vector<float>& std,
51  bool is_scale) {
52  normalize_permute_op_ =
53  std::make_shared<NormalizeAndPermute>(mean, std, is_scale);
54  }
55 
58  const std::vector<std::array<int, 4>>* GetBatchImgInfo() {
59  return &batch_det_img_info_;
60  }
61 
63  void DisableNormalize() { disable_permute_ = true; }
65  void DisablePermute() { disable_normalize_ = true; }
66 
70  void SetDetImageShape(const std::vector<int>& det_image_shape) {
71  det_image_shape_ = det_image_shape;
72  }
74  std::vector<int> GetDetImageShape() const { return det_image_shape_; }
75 
79  void SetStaticShapeInfer(bool static_shape_infer) {
80  static_shape_infer_ = static_shape_infer;
81  }
83  bool GetStaticShapeInfer() const { return static_shape_infer_; }
84 
85  private:
86  bool ResizeImage(FDMat* img, int resize_w, int resize_h, int max_resize_w,
87  int max_resize_h);
88  // for recording the switch of hwc2chw
89  bool disable_permute_ = false;
90  // for recording the switch of normalize
91  bool disable_normalize_ = false;
92  int max_side_len_ = 960;
93  std::vector<std::array<int, 4>> batch_det_img_info_;
94  std::shared_ptr<Resize> resize_op_;
95  std::shared_ptr<Pad> pad_op_;
96  std::shared_ptr<NormalizeAndPermute> normalize_permute_op_;
97  std::vector<int> det_image_shape_ = {3, 960, 960};
98  bool static_shape_infer_ = false;
99  std::array<int, 4> OcrDetectorGetInfo(FDMat* img, int max_size_len);
100 };
101 
102 } // namespace ocr
103 } // namespace vision
104 } // namespace fastdeploy
void SetNormalize(const std::vector< float > &mean, const std::vector< float > &std, bool is_scale)
Definition: det_preprocessor.h:49
const std::vector< std::array< int, 4 > > * GetBatchImgInfo()
Definition: det_preprocessor.h:58
Definition: float16.h:572
void SetDetImageShape(const std::vector< int > &det_image_shape)
Definition: det_preprocessor.h:70
void SetStaticShapeInfer(bool static_shape_infer)
Definition: det_preprocessor.h:79
Preprocessor object for DBDetector serials model.
Definition: det_preprocessor.h:28
bool GetStaticShapeInfer() const
Get static_shape_infer of the recognition preprocess.
Definition: det_preprocessor.h:83
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
void SetMaxSideLen(int max_side_len)
Set max_side_len for the detection preprocess, default is 960.
Definition: det_preprocessor.h:41
int GetMaxSideLen() const
Get max_side_len of the detection preprocess.
Definition: det_preprocessor.h:44
std::vector< int > GetDetImageShape() const
Get cls_image_shape for the classification preprocess.
Definition: det_preprocessor.h:74
FDMatBatch contains batch data for preprocess.
Definition: mat_batch.h:28
void DisablePermute()
This function will disable hwc2chw in preprocessing step.
Definition: det_preprocessor.h:65
ProcessorManager for Preprocess.
Definition: manager.h:27
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
void DisableNormalize()
This function will disable normalize in preprocessing step.
Definition: det_preprocessor.h:63