未验证 提交 534ef5d9 编写于 作者: L littletomatodonkey 提交者: GitHub

fix cpp infer (#1594)

* fix cpp infer

* restore img shape
上级 4da38551
......@@ -62,4 +62,4 @@ public:
const std::vector<int> &rec_image_shape = {3, 48, 192});
};
} // namespace PaddleOCR
\ No newline at end of file
} // namespace PaddleOCR
......@@ -81,7 +81,7 @@ void ResizeImgType0::Run(const cv::Mat &img, cv::Mat &resize_img,
else if (resize_h / 32 < 1 + 1e-5)
resize_h = 32;
else
resize_h = (resize_h / 32 - 1) * 32;
resize_h = resize_h / 32 * 32;
if (resize_w % 32 == 0)
resize_w = resize_w;
......@@ -96,13 +96,17 @@ void ResizeImgType0::Run(const cv::Mat &img, cv::Mat &resize_img,
ratio_w = float(resize_w) / float(w);
}
void CrnnResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, float wh_ratio,
void CrnnResizeImg::Run(const cv::Mat &img, cv::Mat &pad_resize_img,
float max_wh_ratio,
const std::vector<int> &rec_image_shape) {
int imgC, imgH, imgW;
imgC = rec_image_shape[0];
imgH = rec_image_shape[1];
imgW = rec_image_shape[2];
float wh_ratio = 1.0 * imgW / imgH;
wh_ratio = std::max(max_wh_ratio, wh_ratio);
imgW = int(32 * wh_ratio);
float ratio = float(img.cols) / float(img.rows);
......@@ -112,8 +116,12 @@ void CrnnResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, float wh_ratio,
else
resize_w = int(ceilf(imgH * ratio));
cv::Mat resize_img;
cv::resize(img, resize_img, cv::Size(resize_w, imgH), 0.f, 0.f,
cv::INTER_LINEAR);
cv::copyMakeBorder(resize_img, pad_resize_img, 0, 0, 0,
int(imgW - resize_img.cols), cv::BORDER_CONSTANT,
{127, 127, 127});
}
void ClsResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册