#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
// 1. 读取图像
cv::Mat image = cv::imread("path_to_your_image.jpg");
if (image.empty()) {
std::cerr << "无法读取图像!" << std::endl;
return -1;
}
// 2. 定义矩形区域的坐标
int topLeftX = 50;
int topLeftY = 50;
int width = 200;
int height = 100;
// 3. 使用cv::rectangle函数绘制一个全黑的矩形
cv::rectangle(image,
cv::Point(topLeftX, topLeftY),
cv::Point(topLeftX + width, topLeftY + height),
cv::Scalar(0, 0, 0), // 黑色
cv::FILLED); // 填充矩形
// 显示结果
cv::imshow("涂黑后的图像", image);
cv::waitKey(0);
return 0;
}
opencv C++将矩形区域涂黑
最新推荐文章于 2024-05-06 22:23:24 发布