OpenCV 简单马赛克实现

void MaskImg(Mat & img1_0)
{
	int nSize = 3; // 马赛克方块大小
	int nThr = 120;
	for (int i = 0; i < img1_0.rows / nSize; i++)
	{
		for (int j = 0; j < img1_0.cols / nSize; j++)
		{
			Mat matTmp = img1_0(Rect(i* nSize, j * nSize, nSize, nSize));
			Scalar nVal = cv::mean(matTmp);
			//img1_0(Rect(i* nSize, j * nSize, nSize, nSize)) = nVal[0];// 均值马赛克
			img1_0(Rect(i* nSize, j * nSize, nSize, nSize)) = nVal[0] > nThr ? 255 : 0;// 二值马赛克
		}
	}
}

 

你可能感兴趣的:(OpenCV)