From 5329c1f5dd7dab927063e8ce46b7c43433f258ab Mon Sep 17 00:00:00 2001 From: syyxsxx Date: Mon, 13 Jul 2020 11:40:58 +0000 Subject: [PATCH] add padding im_vaule --- deploy/cpp/include/paddlex/transforms.h | 7 +++++++ deploy/cpp/src/transforms.cpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deploy/cpp/include/paddlex/transforms.h b/deploy/cpp/include/paddlex/transforms.h index c1ffd7e1d..7e936dc17 100644 --- a/deploy/cpp/include/paddlex/transforms.h +++ b/deploy/cpp/include/paddlex/transforms.h @@ -214,6 +214,12 @@ class Padding : public Transform { height_ = item["target_size"].as>()[1]; } } + if (item["im_padding_value"].IsDefined()) { + im_value_ = item["im_padding_value"].as>(); + } + else { + im_value_ = {0, 0, 0}; + } } virtual bool Run(cv::Mat* im, ImageBlob* data); @@ -221,6 +227,7 @@ class Padding : public Transform { int coarsest_stride_ = -1; int width_ = 0; int height_ = 0; + std::vector im_value_; }; /* * @brief diff --git a/deploy/cpp/src/transforms.cpp b/deploy/cpp/src/transforms.cpp index 99a73ee73..626b2053d 100644 --- a/deploy/cpp/src/transforms.cpp +++ b/deploy/cpp/src/transforms.cpp @@ -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;