Skip to content

Commit 9069f57

Browse files
committed
alter cpp NormalizeImage
1 parent d322909 commit 9069f57

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

deploy/cpp/include/preprocess_op.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class NormalizeImage : public PreprocessOp {
6666
mean_ = item["mean"].as<std::vector<float>>();
6767
scale_ = item["std"].as<std::vector<float>>();
6868
is_scale_ = item["is_scale"].as<bool>();
69+
if (item["norm_type"]) {
70+
norm_type_ = item["norm_type"].as<std::string>();
71+
}
6972
}
7073

7174
virtual void Run(cv::Mat* im, ImageBlob* data);
@@ -75,6 +78,7 @@ class NormalizeImage : public PreprocessOp {
7578
std::vector<float> mean_;
7679
std::vector<float> scale_;
7780
bool is_scale_ = true;
81+
std::string norm_type_ = "mean_std";
7882
};
7983

8084
class Permute : public PreprocessOp {

deploy/cpp/src/preprocess_op.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ void NormalizeImage::Run(cv::Mat* im, ImageBlob* data) {
3434
e /= 255.0;
3535
}
3636
(*im).convertTo(*im, CV_32FC3, e);
37-
for (int h = 0; h < im->rows; h++) {
38-
for (int w = 0; w < im->cols; w++) {
39-
im->at<cv::Vec3f>(h, w)[0] =
40-
(im->at<cv::Vec3f>(h, w)[0] - mean_[0]) / scale_[0];
41-
im->at<cv::Vec3f>(h, w)[1] =
42-
(im->at<cv::Vec3f>(h, w)[1] - mean_[1]) / scale_[1];
43-
im->at<cv::Vec3f>(h, w)[2] =
44-
(im->at<cv::Vec3f>(h, w)[2] - mean_[2]) / scale_[2];
37+
if (norm_type_ == "mean_std"){
38+
for (int h = 0; h < im->rows; h++) {
39+
for (int w = 0; w < im->cols; w++) {
40+
im->at<cv::Vec3f>(h, w)[0] =
41+
(im->at<cv::Vec3f>(h, w)[0] - mean_[0]) / scale_[0];
42+
im->at<cv::Vec3f>(h, w)[1] =
43+
(im->at<cv::Vec3f>(h, w)[1] - mean_[1]) / scale_[1];
44+
im->at<cv::Vec3f>(h, w)[2] =
45+
(im->at<cv::Vec3f>(h, w)[2] - mean_[2]) / scale_[2];
46+
}
4547
}
4648
}
4749
}

0 commit comments

Comments
 (0)