opencv 简单的实现二值化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38204686/article/details/79284008
//灰度图二值化 传入的图像  阈值
void erzhi(Mat &img,uchar gray)
{
	//行列
	int row = img.rows;
	int col = img.cols;
	//遍历图像
	int i,j;
	uchar *p;  
    for( i = 0; i < row; ++i)  
    {  
        p = img.ptr<uchar>(i);  
        for ( j = 0; j < col; ++j)  
        {
            if(p[j] > gray) 
				p[j] = 255;
			else 
				p[j] = 0;
        }  
    }  
}

猜你喜欢

转载自blog.csdn.net/qq_38204686/article/details/79284008