Page 1 of 1

Detecting reddish color areas

Posted: Tue Jul 08, 2014 10:41 pm
by Hcds
Hello,
my Raspberry Pi Robot should detect reddish color areas on the floor by using Adafruit I2C-RGB Color sensor.
I've written a Python Script for doing this. It works partially, I can get the red, green and blue value from the sensor (a number between 0 and 255 in each case).

But with this informations I cannot say 'this is a reddish color area'.
Maybe I must define fixed intervals for red / green/ blue values, do you know any empirical valus here?
Or would you say 'this approach is a bad idea'?

Thank you for your efforts!
Christoph

Re: Detecting reddish color areas

Posted: Tue Jul 08, 2014 11:03 pm
by riklaunim
Reddish area is when red is very high and blue/green very low. You could set some minimal ratio of red to green/blue.

Re: Detecting reddish color areas

Posted: Tue Jul 08, 2014 11:06 pm
by Douglas6
Sounds like a good idea to me. I've always wanted to build a colored line-following robot, myself.
I would convert the RGB values to HSL (Hue, Saturation, Lightness) color space. Then just test the H value to fall in a suitable range towards 0 and maybe a range near 1 to get purple-reds. In Python there's a handy colorsys library to do the conversion, plenty of C code on the web.
[EDIT: You might want to put thresholds on S and L too, to rule out pinks.]

Re: Detecting reddish color areas

Posted: Tue Jul 08, 2014 11:08 pm
by AndrewS
I've never done it myself, but I imagine detecting 'reddish' colours will simply be a case of

Code: Select all

if red > red_threshold and green < green_threshold and blue < blue_threshold:
    print "This colour (%d, %d, %d) looks reddish" % (red, green, blue)
else:
    print "(%d, %d, %d) is a boring colour"
Obviously you'll need to experiment to find suitable values for the thresholds (the thresholds may vary depending on the sensor).