图像扩充边界 #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); // 在BGR颜色空间中,红色边界// 使用copyMakeBorder函数扩充边界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; }