1. 程式人生 > >opencv 簡單的實現二值化

opencv 簡單的實現二值化

//灰度圖二值化 傳入的影象  閾值
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;
        }  
    }  
}