FastDeploy  latest
Fast & Easy to Deploy!
Public Member Functions | List of all members
fastdeploy::vision::ocr::Recognizer Class Reference

Recognizer object is used to load the recognition model provided by PaddleOCR. More...

#include <recognizer.h>

Inheritance diagram for fastdeploy::vision::ocr::Recognizer:
Inheritance graph
[legend]
Collaboration diagram for fastdeploy::vision::ocr::Recognizer:
Collaboration graph
[legend]

Public Member Functions

 Recognizer (const std::string &model_file, const std::string &params_file="", const std::string &label_path="", const RuntimeOption &custom_option=RuntimeOption(), const ModelFormat &model_format=ModelFormat::PADDLE)
 Set path of model file, and the configuration of runtime. More...
 
std::string ModelName () const
 Get model's name.
 
virtual std::unique_ptr< RecognizerClone () const
 Clone a new Recognizer with less memory usage when multiple instances of the same model are created. More...
 
virtual bool Predict (const cv::Mat &img, std::string *text, float *rec_score)
 Predict the input image and get OCR recognition model result. More...
 
virtual bool Predict (const cv::Mat &img, vision::OCRResult *ocr_result)
 Predict the input image and get OCR recognition model result. More...
 
virtual bool BatchPredict (const std::vector< cv::Mat > &images, vision::OCRResult *ocr_result)
 BatchPredict the input image and get OCR recognition model result. More...
 
virtual bool BatchPredict (const std::vector< cv::Mat > &images, std::vector< std::string > *texts, std::vector< float > *rec_scores)
 BatchPredict the input image and get OCR recognition model result. More...
 
virtual RecognizerPreprocessorGetPreprocessor ()
 Get preprocessor reference of DBDetectorPreprocessor.
 
virtual RecognizerPostprocessorGetPostprocessor ()
 Get postprocessor reference of DBDetectorPostprocessor.
 
- Public Member Functions inherited from fastdeploy::FastDeployModel
virtual bool Infer (std::vector< FDTensor > &input_tensors, std::vector< FDTensor > *output_tensors)
 Inference the model by the runtime. This interface is included in the Predict() function, so we don't call Infer() directly in most common situation.
 
virtual bool Infer ()
 Inference the model by the runtime. This interface is using class member reused_input_tensors_ to do inference and writing results to reused_output_tensors_.
 
virtual int NumInputsOfRuntime ()
 Get number of inputs for this model.
 
virtual int NumOutputsOfRuntime ()
 Get number of outputs for this model.
 
virtual TensorInfo InputInfoOfRuntime (int index)
 Get input information for this model.
 
virtual TensorInfo OutputInfoOfRuntime (int index)
 Get output information for this model.
 
virtual bool Initialized () const
 Check if the model is initialized successfully.
 
virtual void EnableRecordTimeOfRuntime ()
 This is a debug interface, used to record the time of runtime (backend + h2d + d2h) More...
 
virtual void DisableRecordTimeOfRuntime ()
 Disable to record the time of runtime, see EnableRecordTimeOfRuntime() for more detail.
 
virtual std::map< std::string, float > PrintStatisInfoOfRuntime ()
 Print the statistic information of runtime in the console, see function EnableRecordTimeOfRuntime() for more detail.
 
virtual bool EnabledRecordTimeOfRuntime ()
 Check if the EnableRecordTimeOfRuntime() method is enabled.
 
virtual double GetProfileTime ()
 Get profile time of Runtime after the profile process is done.
 
virtual void ReleaseReusedBuffer ()
 Release reused input/output buffers.
 

Additional Inherited Members

- Public Attributes inherited from fastdeploy::FastDeployModel
std::vector< Backendvalid_cpu_backends = {Backend::ORT}
 Model's valid cpu backends. This member defined all the cpu backends have successfully tested for the model.
 
std::vector< Backendvalid_gpu_backends = {Backend::ORT}
 
std::vector< Backendvalid_ipu_backends = {}
 
std::vector< Backendvalid_timvx_backends = {}
 
std::vector< Backendvalid_directml_backends = {}
 
std::vector< Backendvalid_ascend_backends = {}
 
std::vector< Backendvalid_kunlunxin_backends = {}
 
std::vector< Backendvalid_rknpu_backends = {}
 
std::vector< Backendvalid_sophgonpu_backends = {}
 

Detailed Description

Recognizer object is used to load the recognition model provided by PaddleOCR.

Constructor & Destructor Documentation

◆ Recognizer()

fastdeploy::vision::ocr::Recognizer::Recognizer ( const std::string &  model_file,
const std::string &  params_file = "",
const std::string &  label_path = "",
const RuntimeOption custom_option = RuntimeOption(),
const ModelFormat model_format = ModelFormat::PADDLE 
)

Set path of model file, and the configuration of runtime.

Parameters
[in]model_filePath of model file, e.g ./ch_PP-OCRv3_rec_infer/model.pdmodel.
[in]params_filePath of parameter file, e.g ./ch_PP-OCRv3_rec_infer/model.pdiparams, if the model format is ONNX, this parameter will be ignored.
[in]label_pathPath of label file used by OCR recognition model. e.g ./ppocr_keys_v1.txt
[in]custom_optionRuntimeOption for inference, the default will use cpu, and choose the backend defined in valid_cpu_backends.
[in]model_formatModel format of the loaded model, default is Paddle format.

Member Function Documentation

◆ BatchPredict() [1/2]

bool fastdeploy::vision::ocr::Recognizer::BatchPredict ( const std::vector< cv::Mat > &  images,
vision::OCRResult *  ocr_result 
)
virtual

BatchPredict the input image and get OCR recognition model result.

Parameters
[in]imagesThe list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
[in]ocr_resultThe output of OCR recognition model result will be writen to this structure.
Returns
true if the prediction is successed, otherwise false.

◆ BatchPredict() [2/2]

bool fastdeploy::vision::ocr::Recognizer::BatchPredict ( const std::vector< cv::Mat > &  images,
std::vector< std::string > *  texts,
std::vector< float > *  rec_scores 
)
virtual

BatchPredict the input image and get OCR recognition model result.

Parameters
[in]imagesThe list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
[in]textsThe list of text results of rec model will be written into this vector.
[in]rec_scoresThe list of sccore result of rec model will be written into this vector.
Returns
true if the prediction is successed, otherwise false.

◆ Clone()

std::unique_ptr< Recognizer > fastdeploy::vision::ocr::Recognizer::Clone ( ) const
virtual

Clone a new Recognizer with less memory usage when multiple instances of the same model are created.

Returns
new Recognizer* type unique pointer

◆ Predict() [1/2]

bool fastdeploy::vision::ocr::Recognizer::Predict ( const cv::Mat &  img,
std::string *  text,
float *  rec_score 
)
virtual

Predict the input image and get OCR recognition model result.

Parameters
[in]imgThe input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
[in]textThe text result of rec model will be written into this parameter.
[in]rec_scoreThe sccore result of rec model will be written into this parameter.
Returns
true if the prediction is successed, otherwise false.

◆ Predict() [2/2]

bool fastdeploy::vision::ocr::Recognizer::Predict ( const cv::Mat &  img,
vision::OCRResult *  ocr_result 
)
virtual

Predict the input image and get OCR recognition model result.

Parameters
[in]imgThe input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
[in]ocr_resultThe output of OCR recognition model result will be writen to this structure.
Returns
true if the prediction is successed, otherwise false.

The documentation for this class was generated from the following files: