Сделайте границу некоторого размера, чтобы матрица выходного размера имела желаемый размер.
/*
enum BorderTypes {
BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i`
BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb`
BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg`
BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno`
BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
BORDER_ISOLATED = 16 //!< do not look outside of ROI
};
*/
cv::Mat out;
int top_border = ...
int bottom_border = ...
int left_border = ...
int right_border = ...
// Not sure that BORDER_TRANSPARENT is the best choice for
// your particular case. Check the other above (BORDER_CONSTANT may be better).
cv::copyMakeBorder(img, out, top_border, bottom_border,
left_border, right_border, cv::BORDER_TRANSPARENT);