FastDeploy  latest
Fast & Easy to Deploy!
dbdetector.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/fastdeploy_model.h"
17 #include "fastdeploy/vision/common/processors/transform.h"
18 #include "fastdeploy/vision/common/result.h"
19 #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
20 #include "fastdeploy/vision/ocr/ppocr/det_postprocessor.h"
21 #include "fastdeploy/vision/ocr/ppocr/det_preprocessor.h"
22 #include "fastdeploy/utils/unique_ptr.h"
23 
24 namespace fastdeploy {
25 namespace vision {
29 namespace ocr {
30 
33 class FASTDEPLOY_DECL DBDetector : public FastDeployModel {
34  public:
35  DBDetector();
43  DBDetector(const std::string& model_file, const std::string& params_file = "",
44  const RuntimeOption& custom_option = RuntimeOption(),
45  const ModelFormat& model_format = ModelFormat::PADDLE);
46 
51  virtual std::unique_ptr<DBDetector> Clone() const;
52 
54  std::string ModelName() const { return "ppocr/ocr_det"; }
55 
62  virtual bool Predict(const cv::Mat& img,
63  std::vector<std::array<int, 8>>* boxes_result);
64 
71  virtual bool Predict(const cv::Mat& img, vision::OCRResult* ocr_result);
72 
79  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
80  std::vector<std::vector<std::array<int, 8>>>* det_results);
81 
88  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
89  std::vector<vision::OCRResult>* ocr_results);
90 
93  return preprocessor_;
94  }
95 
98  return postprocessor_;
99  }
100 
101  private:
102  bool Initialize();
103  DBDetectorPreprocessor preprocessor_;
104  DBDetectorPostprocessor postprocessor_;
105 };
106 
107 } // namespace ocr
108 } // namespace vision
109 } // namespace fastdeploy
std::string ModelName() const
Get model&#39;s name.
Definition: dbdetector.h:54
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
DBDetector object is used to load the detection model provided by PaddleOCR.
Definition: dbdetector.h:33
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
virtual DBDetectorPostprocessor & GetPostprocessor()
Get postprocessor reference of DBDetectorPostprocessor.
Definition: dbdetector.h:97
Preprocessor object for DBDetector serials model.
Definition: det_preprocessor.h:28
Postprocessor object for DBDetector serials model.
Definition: det_postprocessor.h:26
virtual DBDetectorPreprocessor & GetPreprocessor()
Get preprocessor reference of DBDetectorPreprocessor.
Definition: dbdetector.h:92
Model with paddlepaddle format.
Definition: enum_variables.h:69
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16