fix cpp inference pre-process

pull/303/head
littletomatodonkey 2020-10-11 10:50:43 +00:00
parent d923c5bb8d
commit 44ed5fed77
3 changed files with 10 additions and 16 deletions

View File

@ -51,8 +51,7 @@ public:
class ResizeImg {
public:
virtual void Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len,
float &ratio_h, float &ratio_w);
virtual void Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len);
};
} // namespace PaddleClas

View File

@ -47,15 +47,12 @@ void Classifier::LoadModel(const std::string &model_dir) {
}
void Classifier::Run(cv::Mat &img) {
float ratio_h{};
float ratio_w{};
cv::Mat srcimg;
cv::Mat resize_img;
img.copyTo(srcimg);
this->resize_op_.Run(img, resize_img, this->resize_short_size_, ratio_h,
ratio_w);
this->resize_op_.Run(img, resize_img, this->resize_short_size_);
this->crop_op_.Run(resize_img, this->crop_size_);
this->normalize_op_.Run(&resize_img, this->mean_, this->scale_,

View File

@ -25,6 +25,7 @@
#include <cstring>
#include <fstream>
#include <math.h>
#include <numeric>
#include <include/preprocess_op.h>
@ -68,25 +69,22 @@ void CenterCropImg::Run(cv::Mat &img, const int crop_size) {
img = img(rect);
}
void ResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len,
float &ratio_h, float &ratio_w) {
void ResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img,
int resize_short_size) {
int w = img.cols;
int h = img.rows;
float ratio = 1.f;
if (h < w) {
ratio = float(max_size_len) / float(h);
ratio = float(resize_short_size) / float(h);
} else {
ratio = float(max_size_len) / float(w);
ratio = float(resize_short_size) / float(w);
}
int resize_h = int(float(h) * ratio);
int resize_w = int(float(w) * ratio);
int resize_h = round(float(h) * ratio);
int resize_w = round(float(w) * ratio);
cv::resize(img, resize_img, cv::Size(resize_w, resize_h));
ratio_h = float(resize_h) / float(h);
ratio_w = float(resize_w) / float(w);
}
} // namespace PaddleClas