Skip to content

Commit 22325d2

Browse files
authored
[Other] Add const modifier to some OCR interface parameters (#836)
* [Other] Add const modifier to some OCR interface parameters * [Other] Add a Predict interface to PPOCR with const parameters For interface compatibility, I chose to add rather than modify
1 parent d19510f commit 22325d2

7 files changed

Lines changed: 12 additions & 6 deletions

File tree

examples/vision/ocr/PP-OCRv2/cpp/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ PPOCRv2 的初始化,由检测,识别模型串联构成(无分类器)
8282

8383
> ```
8484
> bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result);
85+
> bool Predict(const cv::Mat& img, fastdeploy::vision::OCRResult* result);
8586
> ```
8687
>
8788
> 模型预测接口,输入一张图片,返回OCR预测结果

fastdeploy/vision/ocr/ppocr/classifier.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool Classifier::Initialize() {
5050
return true;
5151
}
5252

53-
bool Classifier::Predict(cv::Mat& img, int32_t* cls_label, float* cls_score) {
53+
bool Classifier::Predict(const cv::Mat& img, int32_t* cls_label, float* cls_score) {
5454
std::vector<int32_t> cls_labels(1);
5555
std::vector<float> cls_scores(1);
5656
bool success = BatchPredict({img}, &cls_labels, &cls_scores);

fastdeploy/vision/ocr/ppocr/classifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FASTDEPLOY_DECL Classifier : public FastDeployModel {
4343
const ModelFormat& model_format = ModelFormat::PADDLE);
4444
/// Get model's name
4545
std::string ModelName() const { return "ppocr/ocr_cls"; }
46-
virtual bool Predict(cv::Mat& img, int32_t* cls_label, float* cls_score);
46+
virtual bool Predict(const cv::Mat& img, int32_t* cls_label, float* cls_score);
4747
/** \brief BatchPredict the input image and get OCR classification model cls_result.
4848
*
4949
* \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.

fastdeploy/vision/ocr/ppocr/ppocr_v2.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ bool PPOCRv2::Initialized() const {
7474
}
7575
return true;
7676
}
77-
7877
bool PPOCRv2::Predict(cv::Mat* img,
7978
fastdeploy::vision::OCRResult* result) {
79+
return Predict(*img, result);
80+
}
81+
82+
bool PPOCRv2::Predict(const cv::Mat& img,
83+
fastdeploy::vision::OCRResult* result) {
8084
std::vector<fastdeploy::vision::OCRResult> batch_result(1);
81-
bool success = BatchPredict({*img},&batch_result);
85+
bool success = BatchPredict({img},&batch_result);
8286
if(!success){
8387
return success;
8488
}

fastdeploy/vision/ocr/ppocr/ppocr_v2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class FASTDEPLOY_DECL PPOCRv2 : public FastDeployModel {
5959
* \return true if the prediction successed, otherwise false.
6060
*/
6161
virtual bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result);
62+
virtual bool Predict(const cv::Mat& img, fastdeploy::vision::OCRResult* result);
6263
/** \brief BatchPredict the input image and get OCR result.
6364
*
6465
* \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.

fastdeploy/vision/ocr/ppocr/recognizer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool Recognizer::Initialize() {
5353
return true;
5454
}
5555

56-
bool Recognizer::Predict(cv::Mat& img, std::string* text, float* rec_score) {
56+
bool Recognizer::Predict(const cv::Mat& img, std::string* text, float* rec_score) {
5757
std::vector<std::string> texts(1);
5858
std::vector<float> rec_scores(1);
5959
bool success = BatchPredict({img}, &texts, &rec_scores);

fastdeploy/vision/ocr/ppocr/recognizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FASTDEPLOY_DECL Recognizer : public FastDeployModel {
4545
const ModelFormat& model_format = ModelFormat::PADDLE);
4646
/// Get model's name
4747
std::string ModelName() const { return "ppocr/ocr_rec"; }
48-
virtual bool Predict(cv::Mat& img, std::string* text, float* rec_score);
48+
virtual bool Predict(const cv::Mat& img, std::string* text, float* rec_score);
4949
/** \brief BatchPredict the input image and get OCR recognition model result.
5050
*
5151
* \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.

0 commit comments

Comments
 (0)