Page 230 - The Definitive Guide to Building Java Robots
P. 230
Preston_5564C06.fm Page 211 Friday, September 23, 2005 5:13 AM
CHAPTER 6 ■ VISION 211
// optimization
public void optimize() {
// sort values getting order of most color, 2nd and 3rd
Arrays.sort(meanValues);
Color[] colors = new Color[3];
// correct in case they are equal.
if (meanValues[0] == meanValues[1]) {
meanValues[1]++;
}
if (meanValues[0] == meanValues[2]) {
meanValues[2]++;
}
if (meanValues[1] == meanValues[2]) {
meanValues[2]++;
}
for (int i = 0; i < 3; i++) {
if (meanValues[i] == redAvg) {
colors[2 - i] = Color.RED;
}
if (meanValues[i] == greenAvg) {
colors[2 - i] = Color.GREEN;
}
if (meanValues[i] == blueAvg) {
colors[2 - i] = Color.BLUE;
}
}
// go in this order
// i want most of primary color
threshhold = .95;
optimizeMin(colors[0]);
System.out.println("done min");
optimizeMax(colors[0]);
System.out.println("done max");
// i don't want much of 2nd and 3rd colors
threshhold = .5;
optmizeRatio(colors[0], colors[1]);
System.out.println("done ratio 1");
optmizeRatio(colors[0], colors[2]);
System.out.println("done ratio 2");
}
public ColorGram getBestColorGram() {
return bestColorGram;
}