What is the best way to detect white color?
Posted
by dnul
on Stack Overflow
See other posts from Stack Overflow
or by dnul
Published on 2010-06-17T20:58:35Z
Indexed on
2010/06/17
21:03 UTC
Read the original article
Hit count: 279
I'm trying to detect white objects in a video. The first step is to filter the image so that it leaves only white-color pixels. My first approach was using HSV color space and then checking for high level of VAL channel. Here is the code:
//convert image to hsv
cvCvtColor( src, hsv, CV_BGR2HSV );
cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
for(int x=0;x<srcSize.width;x++){
for(int y=0;y<srcSize.height;y++){
uchar * hue=&((uchar*) (h_plane->imageData+h_plane->widthStep*y))[x];
uchar * sat=&((uchar*) (s_plane->imageData+s_plane->widthStep*y))[x];
uchar * val=&((uchar*) (v_plane->imageData+v_plane->widthStep*y))[x];
if((*val>170))
*hue=255;
else
*hue=0;
}
}
leaving the result in the hue channel. Unfortunately, this approach is very sensitive to lighting. I'm sure there is a better way. Any suggestions?
© Stack Overflow or respective owner