今天看啥
热点:

提取某种颜色的像素点


// 洗刷掉某种颜色
void WashOffTheColor( IplImage* src )
{
	if ( src == NULL )  
    {  
        return ;  
    }  
      
    const int width     = src->width;  
    const int height    = src->height;  
    const int widthStep = src->widthStep;  
    const int channels  = src->nChannels;  
    uchar *data = (uchar *)src->imageData;  
    
	if ( channels != 3 )
	{
		return ;
	}

	uchar* bgr[3];
	for ( int row = 0; row < height; ++row )
	{
		for ( int col = 0; col < width; ++col )
		{
			for ( int cha = 0; cha < channels; ++cha )
			{
				bgr[cha] = &data[cha + col * channels + row * widthStep];
			}
			CvScalar rgb = CV_RGB(*bgr[2], *bgr[1], *bgr[0]);
			int r = rgb.val[2];
			int g = rgb.val[1];
			int b = rgb.val[0];

			*bgr[0] = 0;
			*bgr[1] = 0;
			*bgr[2] = 0;

			if ( (g + b < r && r > 200) ||
				(g + b < r && g < b) )
			{
				if ( g < r / 2 && b < r / 2 )
				{ // 红色的判断条件
					*bgr[0] = 255;
					*bgr[1] = 255;
					*bgr[2] = 255;
				}
	
			}
		}
	}
}

www.bkjia.comtruehttp://www.bkjia.com/Javabc/974784.htmlTechArticle提取某种颜色的像素点 // 洗刷掉某种颜色void WashOffTheColor( IplImage* src ){if ( src == NULL ) { return ; } const int width = src-width; const int height = src-hei...

相关文章

相关搜索: 像素 颜色

帮客评论

视觉看点