FastDeploy  latest
Fast & Easy to Deploy!
ppocr_v2.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 
17 #include <vector>
18 
19 #include "fastdeploy/fastdeploy_model.h"
20 #include "fastdeploy/vision/common/processors/transform.h"
21 #include "fastdeploy/vision/common/result.h"
22 
23 #include "fastdeploy/vision/ocr/ppocr/classifier.h"
24 #include "fastdeploy/vision/ocr/ppocr/dbdetector.h"
25 #include "fastdeploy/vision/ocr/ppocr/recognizer.h"
26 #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
27 #include "fastdeploy/utils/unique_ptr.h"
28 
29 namespace fastdeploy {
33 namespace pipeline {
36 class FASTDEPLOY_DECL PPOCRv2 : public FastDeployModel {
37  public:
47 
55 
60  std::unique_ptr<PPOCRv2> Clone() const;
61 
68  virtual bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result);
69  virtual bool Predict(const cv::Mat& img,
70  fastdeploy::vision::OCRResult* result);
77  virtual bool BatchPredict(const std::vector<cv::Mat>& images,
78  std::vector<fastdeploy::vision::OCRResult>* batch_result);
79 
80  bool Initialized() const override;
81  bool SetClsBatchSize(int cls_batch_size);
82  int GetClsBatchSize();
83  bool SetRecBatchSize(int rec_batch_size);
84  int GetRecBatchSize();
85 
86  protected:
87  fastdeploy::vision::ocr::DBDetector* detector_ = nullptr;
88  fastdeploy::vision::ocr::Classifier* classifier_ = nullptr;
89  fastdeploy::vision::ocr::Recognizer* recognizer_ = nullptr;
90 
91  private:
92  int cls_batch_size_ = 1;
93  int rec_batch_size_ = 6;
94 };
95 
96 namespace application {
97 namespace ocrsystem {
98  typedef pipeline::PPOCRv2 PPOCRSystemv2;
99 } // namespace ocrsystem
100 } // namespace application
101 
102 } // namespace pipeline
103 } // namespace fastdeploy
DBDetector object is used to load the detection model provided by PaddleOCR.
Definition: dbdetector.h:33
Classifier object is used to load the classification model provided by PaddleOCR. ...
Definition: classifier.h:32
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
Recognizer object is used to load the recognition model provided by PaddleOCR.
Definition: recognizer.h:32
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
PPOCRv2 is used to load PP-OCRv2 series models provided by PaddleOCR.
Definition: ppocr_v2.h:36