水印定位
需要根据图像特征获取水印的位置。
如图所示,图像左下角、右下角有水印。第一步,我们首先得定位水印所在位置。
Mat gray;
cvtColor(src, gray, COLOR_BGR2GRAY);
//图像二值化,筛选出白色区域部分
Mat thresh;
threshold(gray, thresh, 220, 255, THRESH_BINARY);
如图为二值化后得到的效果图。接下来,我们需要提取水印区域的像素。
//提取图片下方的水印,制作掩模图像
Mat mask = Mat::zeros(src.size(), CV_8U);
int height = src.rows;
int width = src.cols;
int start = 0.9*height;
//遍历图像像素,提取出水印部分像素,制作掩模图像
for (int i = start; i < height; i++)
{
uchar*data = thresh.ptr<uchar>(i);
for (int j = 0; j < width; j++)
{