fix cpp inference pre-process
parent
d923c5bb8d
commit
44ed5fed77
|
@ -51,8 +51,7 @@ public:
|
||||||
|
|
||||||
class ResizeImg {
|
class ResizeImg {
|
||||||
public:
|
public:
|
||||||
virtual void Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len,
|
virtual void Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len);
|
||||||
float &ratio_h, float &ratio_w);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace PaddleClas
|
} // namespace PaddleClas
|
|
@ -47,15 +47,12 @@ void Classifier::LoadModel(const std::string &model_dir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Classifier::Run(cv::Mat &img) {
|
void Classifier::Run(cv::Mat &img) {
|
||||||
float ratio_h{};
|
|
||||||
float ratio_w{};
|
|
||||||
|
|
||||||
cv::Mat srcimg;
|
cv::Mat srcimg;
|
||||||
cv::Mat resize_img;
|
cv::Mat resize_img;
|
||||||
img.copyTo(srcimg);
|
img.copyTo(srcimg);
|
||||||
|
|
||||||
this->resize_op_.Run(img, resize_img, this->resize_short_size_, ratio_h,
|
this->resize_op_.Run(img, resize_img, this->resize_short_size_);
|
||||||
ratio_w);
|
|
||||||
this->crop_op_.Run(resize_img, this->crop_size_);
|
this->crop_op_.Run(resize_img, this->crop_size_);
|
||||||
|
|
||||||
this->normalize_op_.Run(&resize_img, this->mean_, this->scale_,
|
this->normalize_op_.Run(&resize_img, this->mean_, this->scale_,
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <math.h>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
#include <include/preprocess_op.h>
|
#include <include/preprocess_op.h>
|
||||||
|
@ -68,25 +69,22 @@ void CenterCropImg::Run(cv::Mat &img, const int crop_size) {
|
||||||
img = img(rect);
|
img = img(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len,
|
void ResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img,
|
||||||
float &ratio_h, float &ratio_w) {
|
int resize_short_size) {
|
||||||
int w = img.cols;
|
int w = img.cols;
|
||||||
int h = img.rows;
|
int h = img.rows;
|
||||||
|
|
||||||
float ratio = 1.f;
|
float ratio = 1.f;
|
||||||
if (h < w) {
|
if (h < w) {
|
||||||
ratio = float(max_size_len) / float(h);
|
ratio = float(resize_short_size) / float(h);
|
||||||
} else {
|
} else {
|
||||||
ratio = float(max_size_len) / float(w);
|
ratio = float(resize_short_size) / float(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resize_h = int(float(h) * ratio);
|
int resize_h = round(float(h) * ratio);
|
||||||
int resize_w = int(float(w) * ratio);
|
int resize_w = round(float(w) * ratio);
|
||||||
|
|
||||||
cv::resize(img, resize_img, cv::Size(resize_w, resize_h));
|
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
|
} // namespace PaddleClas
|
Loading…
Reference in New Issue