diff --git a/deploy/cpp/include/paddlex/transforms.h b/deploy/cpp/include/paddlex/transforms.h index c1ffd7e1de8a28f88a571e7b9d029585806cf59d..7e936dc17f4b6e58cdb8cdc36639173ccc24177c 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 99a73ee7345bbc8cc672d1c42627a9326ded0cf7..626b2053d2473bcf66fcb1a760d9ce2e101324f4 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;