diff --git a/deploy/cpp_infer/src/ocr_rec.cpp b/deploy/cpp_infer/src/ocr_rec.cpp index da1822af31d..3d16ffd3612 100644 --- a/deploy/cpp_infer/src/ocr_rec.cpp +++ b/deploy/cpp_infer/src/ocr_rec.cpp @@ -59,6 +59,10 @@ void CRNNRecognizer::Run(std::vector img_list, this->use_tensorrt_, this->rec_image_shape_); this->normalize_op_.Run(&resize_img, this->mean_, this->scale_, this->is_scale_); + int border = std::max(this->rec_image_shape_[2], (int)(this->rec_image_shape_[1] * max_wh_ratio)) - resize_img.cols; + if (border > 0) { + cv::copyMakeBorder(resize_img, resize_img, 0, 0, 0, border, cv::BORDER_CONSTANT, { 0, 0, 0 }); + } norm_img_batch.push_back(resize_img); batch_width = std::max(resize_img.cols, batch_width); } diff --git a/deploy/cpp_infer/src/preprocess_op.cpp b/deploy/cpp_infer/src/preprocess_op.cpp index 4dabb120680..45c63a105c5 100644 --- a/deploy/cpp_infer/src/preprocess_op.cpp +++ b/deploy/cpp_infer/src/preprocess_op.cpp @@ -110,9 +110,6 @@ void CrnnResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, float wh_ratio, cv::resize(img, resize_img, cv::Size(resize_w, imgH), 0.f, 0.f, cv::INTER_LINEAR); - cv::copyMakeBorder(resize_img, resize_img, 0, 0, 0, - int(imgW - resize_img.cols), cv::BORDER_CONSTANT, - {0, 0, 0}); } void ClsResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img,