Hey guys, I have a TCS3472 from Adafruit wired up and working on a Propeller:
I created a table of roughly 50 colors (RGB), and I am trying to take the sensor readings and match it up with the most similar color.
Here is what I tried so far:
I first looped through the table of colors, and calculated a new table that is based off percentages of RGB.
repeat i from 0 to 49
Data_Red_Percent[i] := (Data_Red[i] * 100) / (Data_Red[i] + Data_Green[i] + Data_Blue[i])
Data_Green_Percent[i] := (Data_Green[i] * 100) / (Data_Red[i] + Data_Green[i] + Data_Blue[i])
Data_Blue_Percent[i] := (Data_Blue[i] * 100) / (Data_Red[i] + Data_Green[i] + Data_Blue[i])
So for example, RGB(255,255,255) would now be 33%, 33%, 33%. A RGB(255,127,127) would be 50%, 25%, 25%. I figured this would be a way for normalizing the colors.... if a color came out a little darker or a little lighter, its ratios might still be the same.
I then do the same thing with the RGB sensor readings. Next I create a table of differences.
repeat i from 0 to 50
Compare_Red_Variance[i] := ||(Red_Percentage - Data_Red_Percent[i])
Compare_Green_Variance[i] := ||(Green_Percentage - Data_Green_Percent[i])
Compare_Blue_Variance[i] := ||(Blue_Percentage - Data_Blue_Percent[i])
The color that has the less amount of variance should be the color that is the closest match right?
So this sort of works, but it doesn't seem to be all that accurate. I am having a hard time telling if this is even a good method/algorithm or not, or if the external lighting near the sensor might be the problem? The sensor is equipped with a white LED directly to the side of the sensor. The intention is to light up the material you are measuring, so the sensor can get a good reading. I understand there are a lot of different wavelengths for "white" LED, which could shift the sensor readings slightly.
Are you aware of a better algorithm for finding colors, or is this the correct method?
Thanks and any help or advice is greatly appreciated!