Search code examples
eclipsejavacv

using cvScalar in javacv?


I want to identify unique colours from an image. I use CvScalar loc = cvGet2D(img, i, j);, and to check whether the location is red or green I use CvScalar red = CvScalar.RED;. However, a boolean evaluation never returns true because my image contains shades of red. Is there any way of either modifying CvScalar so it ignores shade, or maybe fiddling with the loc variable?


Solution

  • since the slightest bits in the red channel will wreck your (binary) question: 'is it green' ? you might get better results using some kind of 'distance' here.

    taking the l2 norm of each the 'found' and the 'desired' color, like:

    sqrt( r*r + b*b + g*g );

    and thresholding the diff(to decide if it's 'close enough') might work much nicer