FastDeploy  latest
Fast & Easy to Deploy!
recognizer.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/rec_preprocessor.h"
21 #include "fastdeploy/vision/ocr/ppocr/rec_postprocessor.h"
22 #include "fastdeploy/utils/unique_ptr.h"
23 
24 namespace fastdeploy {
25 namespace vision {
29 namespace ocr {
32 class FASTDEPLOY_DECL Recognizer : public FastDeployModel {
33  public:
34  Recognizer();
43  Recognizer(const std::string& model_file, const std::string& params_file = "",
44  const std::string& label_path = "",
45  const RuntimeOption& custom_option = RuntimeOption(),
46  const ModelFormat& model_format = ModelFormat::PADDLE);
47 
49  std::string ModelName() const { return "ppocr/ocr_rec"; }
50 
55  virtual std::unique_ptr<Recognizer> Clone() const;
56 
64  virtual bool Predict(const cv::Mat& img, std::string* text, float* rec_score);
65 
72  virtual bool Predict(const cv::Mat& img, vision::OCRResult* ocr_result);
73 
80  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
81  vision::OCRResult* ocr_result);
82 
90  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
91  std::vector<std::string>* texts, std::vector<float>* rec_scores);
92 
93  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
94  std::vector<std::string>* texts, std::vector<float>* rec_scores,
95  size_t start_index, size_t end_index,
96  const std::vector<int>& indices);
97 
100  return preprocessor_;
101  }
102 
105  return postprocessor_;
106  }
107 
108  private:
109  bool Initialize();
110  RecognizerPreprocessor preprocessor_;
111  RecognizerPostprocessor postprocessor_;
112 };
113 
114 } // namespace ocr
115 } // namespace vision
116 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
std::string ModelName() const
Get model&#39;s name.
Definition: recognizer.h:49
Preprocessor object for PaddleClas serials model.
Definition: rec_preprocessor.h:26
Recognizer object is used to load the recognition model provided by PaddleOCR.
Definition: recognizer.h:32
Model with paddlepaddle format.
Definition: enum_variables.h:69
virtual RecognizerPostprocessor & GetPostprocessor()
Get postprocessor reference of DBDetectorPostprocessor.
Definition: recognizer.h:104
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
virtual RecognizerPreprocessor & GetPreprocessor()
Get preprocessor reference of DBDetectorPreprocessor.
Definition: recognizer.h:99
Postprocessor object for Recognizer serials model.
Definition: rec_postprocessor.h:26