Skip to content

Commit

Permalink
Merge pull request #222 from syyxsxx/padding3
Browse files Browse the repository at this point in the history
add padding im_vaule
  • Loading branch information
rollroll90 authored Jul 13, 2020
2 parents 50bb5a9 + 5329c1f commit c1c91a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions deploy/cpp/include/paddlex/transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,20 @@ class Padding : public Transform {
height_ = item["target_size"].as<std::vector<int>>()[1];
}
}
if (item["im_padding_value"].IsDefined()) {
im_value_ = item["im_padding_value"].as<std::vector<float>>();
}
else {
im_value_ = {0, 0, 0};
}
}
virtual bool Run(cv::Mat* im, ImageBlob* data);

private:
int coarsest_stride_ = -1;
int width_ = 0;
int height_ = 0;
std::vector<float> im_value_;
};
/*
* @brief
Expand Down
3 changes: 2 additions & 1 deletion deploy/cpp/src/transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ bool Padding::Run(cv::Mat* im, ImageBlob* data) {
<< ", but they should be greater than 0." << std::endl;
return false;
}
cv::Scalar value = cv::Scalar(im_value_[0], im_value_[1], im_value_[2]);
cv::copyMakeBorder(
*im, *im, 0, padding_h, 0, padding_w, cv::BORDER_CONSTANT, cv::Scalar(0));
*im, *im, 0, padding_h, 0, padding_w, cv::BORDER_CONSTANT, value);
data->new_im_size_[0] = im->rows;
data->new_im_size_[1] = im->cols;
return true;
Expand Down

0 comments on commit c1c91a7

Please sign in to comment.