I need to get red, blue, green, yellow, black and white accurately detected, using the TCS34725 sensor, and have a few questions of what the code should look like. Red, blue and green can be detected now - the colour is red if red is greater than blue and green, true for blue and green cases as well. For yellow, red and green should be approximately equal, and greater than blue.
I want to be able to print out the colour the sensor is detecting to the observers when that colour is in front of the sensor, and my idea is to just create some if statements describing that if a certain colour has an RGB value greater than both other colours, then that colour is being detected. I'm using the less precise scale of 0-255 instead of the sensor's 0-65535 scale so that the setting up of these if statements is easier.
Are there any better, more efficient ideas with the possibility to expand to detection of more colours? I saw somewhere an approach in Python where a list of known colour values were defined, and the colour was detected if the "distance" or "closeness" of the detected colour to the defined colour was less than a certain value, but I'm not sure how to do that. If I proceed with my idea, how sure can I be that the value I set in my if statement as a comparator to the detected value, is good enough to detect that colour accurately?
It is quite difficult to "accurately" detect reflected colors, as the reflected light depends so strongly on the type and color of the illumination.
The sensor does not behave in the same way as the human eye, and can't perform the types of corrections to color perception that take place in the human eye and brain.
To see what I mean, test the sensor response to colored surfaces under different lighting conditions (e.g. direct sunlight, blue sky, fluorescent and incandescent lighting).
I totally agree with jremington it is more than tricky.
You might want to look at this website.
I have always had good colour recognition using the Lego colour sensor. Which can be used with an Arduino as it is just an I2C device, if I remember correctly.
Shine the colored light on an white, tight-weave cloth surface and compare the results against a smooth, bone-white, matte surface.
I would use samples of red, blue, green etc. We know that the RGB of red is 0xff0000, but that is just a very technical value. Find a good sample, some colour test chart that photographers use, use the reddest of the reds, scan it with your setup with the TCS34725, and record that value. It won't be 0xff0000, but maybe not far from that. Record all other colours you need. Then, to detect any colour, scan it with your TCS34725 and check which of your recorded colours is the nearest in your 3D colour space.
The RGB space might not be the right one to use. Maybe you want to use HSV. Convert your RGB values to HSV and use only the H value to check which colour it is.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.