开发者

What is the best way to detect white color? [closed]

开发者 https://www.devze.com 2023-01-04 01:39 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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 t开发者_StackOverflow社区he result in the hue channel. Unfortunately, this approach is very sensitive to lighting. I'm sure there is a better way. Any suggestions?


Why are you using HSV? It would make more sense to convert to HSL and use the luminance channel. Of course you will not get only white, but every color with high luminance over a threshold. After all, you can't rely on pure white unless your source image has been overexposed.


It's going to be sensitive to lighting - what happens if you view it under a red light!
I don't know if using YUV space is much easier than looking for similar RGB values.

edit - normally you would call something with no color gray (might help you with searches).
If you have a choice this is the worst color to search for because it will reflect any other lighting in the scene. So you will have to detect the overall lighting color and adjust for that.

So what you are looking for are pixels with simlar RGB values, or RGB values in the ratio of the average for objects in the scene.


Another way would be turn your image into grayscale. White will have very high values (almost >225).

Yet another way would be to AND the R, G and B planes. Only the whites will remain in the resultant image. This way, you're not spending time calculating converting to the HSV colour space. You're just doing a simple AND operation at each pixel.

0

精彩评论

暂无评论...
验证码 换一张
取 消