Hcds
Posts: 18
Joined: Sat Aug 10, 2013 11:10 pm

Detecting reddish color areas

Tue Jul 08, 2014 10:41 pm

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

riklaunim
Posts: 265
Joined: Tue Apr 22, 2014 7:34 pm

Re: Detecting reddish color areas

Tue Jul 08, 2014 11:03 pm

Reddish area is when red is very high and blue/green very low. You could set some minimal ratio of red to green/blue.

User avatar
Douglas6
Posts: 4827
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Detecting reddish color areas

Tue Jul 08, 2014 11:06 pm

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.]
Last edited by Douglas6 on Tue Jul 08, 2014 11:39 pm, edited 3 times in total.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Detecting reddish color areas

Tue Jul 08, 2014 11:08 pm

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).

Return to “Automation, sensing and robotics”