图像扩充边界
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
cv::Mat image = cv::imread("1.jpg", cv::IMREAD_COLOR);
if (image.empty()) {
std::cerr << "Could not open or find the image!" << std::endl;
return -1;
}
int top_border = 20;
int bottom_border = 20;
int left_border = 30;
int right_border = 30;
cv::Scalar border_color(0, 0, 255);
cv::Mat bordered_image;
cv::copyMakeBorder(image, bordered_image, top_border, bottom_border, left_border, right_border, cv::BORDER_CONSTANT, border_color);
cv::namedWindow("Original Image", cv::WINDOW_NORMAL);
cv::namedWindow("Bordered Image", cv::WINDOW_NORMAL);
cv::imshow("Original Image", image);
cv::imshow("Bordered Image", bordered_image);
cv::waitKey(0);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/14c1770a08e42744701ef46bdd6f0341.png)