Sumo Player: Image Processing?
Hi,
I was going through the Source code of Sample SumoPlayer, and did not understand the below mentioned things:
Code Snippet
int threshold = 220 * 3;
Code Snippet
if (b + g + r > threshold)
Code Snippet
_state.LineThreshHoldLow = 600;
_state.LineThreshHoldHigh = 5001;
1. In the first snippets i think it is looking for the White Color in the image? Am i right? Can i change this to any RGB combination? (Let's say my opponent is having Blue color)
2. I quite did not understood this statement. Can any of you please elaborate?
3. Are this values in Hex? and Second thing Are they for the Red Color in the Ring?
Regards,
Jadeja Dushyantsinh Anopsinh.
The sum (r + g + b) / 3 is commonly called the Intensity of an image pixel. It measures how bright it is. Obviously, a value of zero would be black and a value of 255 (assuming rgb values are bytes) would mean white. However, pure yellow would be (255, 255, 0) in rgb, giving an intensity value of only 170 and it looks like
I assume that the threshold is initalized to 220 * 3 simply because the desired intensity is 220 and the programmer wanted to make this clear. This saves a division by three every time that the code is called. The value is not in hex. An intensity this high is close to white, but not pure white. In fact, it is more of a grey colour. Here is what it looks like but this is a long way from black!
You can examine the values of r, g and b separately if you are looking for red, green or blue. For other colours you need to have combinations, e.g. yellow is red plus green.
I don't understand the LineThreshHoldHigh because the maximum possible value of r + g + b is 765. The Low threshold of 600 is equivalent to 200 * 3 which is also very bright. If you consider that the range for r, g and b is only 0-255, then getting a total of 600 means that all the values must be high. For instance, pure red would be (255,0,0) so the sum is only 255.
To get a total of 600, each of the colours must contribute a fairly large amount. An extreme case would be (255,255,90) which totals to 600. Here is a sample:
To the human eye, this probably looks similar to the pure yellow above. (Look very closely and you might see that it is brighter.) However, cameras see even small differences in colour. Hence what we think is white will not always be pure white at the pixel level, which is why there is a threshold in the program for colours that are close enough to white.
Trevor