本文主要是介绍提取某种颜色的像素点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 洗刷掉某种颜色
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;
}
}
}
}
}
这篇关于提取某种颜色的像素点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!