选定图像中一个patch,然后将这个方块按我们的想法赋值(如全黑、全白等)
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
Mat rawImage = imread("d:/fodder/3.jpg");
Mat cloneImage = rawImage.clone();
int nr = cloneImage.rows;
int nc = cloneImage.cols * cloneImage.channels();
for(int j=nr/4; j<nr/2; j++)
{
uchar* data = cloneImage.ptr<uchar>(j); //uchar: Unicode characters loggram
for(int i = nc/3; i < nc/2; i++)
{
data[i] = 0;
}
}
namedWindow("原始图像");
imshow("原始图像", rawImage);
namedWindow("操作后的图像");
imshow("操作后的图像", cloneImage);
imwrite("操作后的图像.jpg", cloneImage);
waitKey(0);
destroyAllWindows();
}