mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-30 20:40:22 +08:00
[Bug Fix] add ocr new feature and fix codestyle (#764)
* fix ocr bug and add new feature * fix bug * fix bug * fix bug * fix bug * fix bug * fix bug * add property * add test * fix code style * fix bug * fix bug * fix bug * fix port * fix ocr * fix_ocr * fix ocr * fix ocr * fix ocr * fix ocr * Update paddle2onnx.cmake * Update paddle2onnx.cmake * Update paddle2onnx.cmake Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: Jason <928090362@qq.com>
This commit is contained in:
@@ -53,10 +53,33 @@ bool Recognizer::Initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Recognizer::Predict(cv::Mat& img, std::string* text, float* rec_score) {
|
||||
std::vector<std::string> texts(1);
|
||||
std::vector<float> rec_scores(1);
|
||||
bool success = BatchPredict({img}, &texts, &rec_scores);
|
||||
if (!success) {
|
||||
return success;
|
||||
}
|
||||
*text = std::move(texts[0]);
|
||||
*rec_score = rec_scores[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Recognizer::BatchPredict(const std::vector<cv::Mat>& images,
|
||||
std::vector<std::string>* texts, std::vector<float>* rec_scores) {
|
||||
return BatchPredict(images, texts, rec_scores, 0, images.size(), {});
|
||||
}
|
||||
|
||||
bool Recognizer::BatchPredict(const std::vector<cv::Mat>& images,
|
||||
std::vector<std::string>* texts, std::vector<float>* rec_scores,
|
||||
size_t start_index, size_t end_index, const std::vector<int>& indices) {
|
||||
size_t total_size = images.size();
|
||||
if (indices.size() != 0 && indices.size() != total_size) {
|
||||
FDERROR << "indices.size() should be 0 or images.size()." << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::vector<FDMat> fd_images = WrapMat(images);
|
||||
if (!preprocessor_.Run(&fd_images, &reused_input_tensors_)) {
|
||||
if (!preprocessor_.Run(&fd_images, &reused_input_tensors_, start_index, end_index, indices)) {
|
||||
FDERROR << "Failed to preprocess the input image." << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -66,7 +89,7 @@ bool Recognizer::BatchPredict(const std::vector<cv::Mat>& images,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!postprocessor_.Run(reused_output_tensors_, texts, rec_scores)) {
|
||||
if (!postprocessor_.Run(reused_output_tensors_, texts, rec_scores, start_index, total_size, indices)) {
|
||||
FDERROR << "Failed to postprocess the inference cls_results by runtime." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user