矩阵的边界填充类型
Mat C =(Mat_<uchar>(3,3)<<1,2,3,4,5,6,7,8,9); uchar *data = NULL; for (int row = 0; row < C.rows; row++) { data = (uchar *)C.ptr<uchar>(row); cout << "["; for (int col = 0; col < C.cols; col++) { cout << (int)data[col] << " "; } cout << "]" << endl; } Mat D; copyMakeBorder(C, D, 2, 2, 2, 2, BORDER_REPLICATE); for (int row = 0; row < D.rows; row++) { data = (uchar *)D.ptr<uchar>(row); cout << "["; for (int col = 0; col < D.cols; col++) { cout << (int)data[col] << " "; } cout << "]" << endl; } cout << endl;
结果
其他填充类型:
//! Various border types, image boundaries are denoted with `|` //! @see borderInterpolate, copyMakeBorder 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 };