Page 228 - The Definitive Guide to Building Java Robots
P. 228

Preston_5564C06.fm  Page 209  Friday, September 23, 2005  5:13 AM



                                                                                   CHAPTER 6  ■  VISION  209



                                // set image
                                imagePanel.setImage(currentImage);

                            }


                            // move primary color minimum value up
                            public void optimizeMin(Color color) {
                                int min = 0;
                                for (min = 0; min < 256; min++) {
                                    ColorGram tempColorGram = new ColorGram();
                                    int[] rgb = null;
                                    // checks to see what color is primary
                                    if (color.equals(Color.RED)) {
                                        rgb = new int[] { min, 0, 0 };
                                    }
                                    if (color.equals(Color.GREEN)) {
                                        rgb = new int[] { 0, min, 0 };
                                    }
                                    if (color.equals(Color.BLUE)) {
                                        rgb = new int[] { 0, 0, min };
                                    }
                                    // adjust colorgram
                                    tempColorGram.setMins(rgb);
                                    // process colorgram in image
                                    doProcessing(tempColorGram);
                                }
                            }

                            // move maximum of primary color down to threshold
                            public void optimizeMax(Color color) {


                                // reset max count
                                maxCount = 0;
                                // make sure I start with copy of current best colorgram (getting min
                                // value)
                                ColorGram tempColorGram = (ColorGram) getBestColorGram().clone();
                                int max = 255;
                                for (max = 255; max > 0; max--) {
                                    int[] rgb = null;
                                    if (color.equals(Color.RED)) {
                                        rgb = new int[] { max, 255, 255 };
                                    }
                                    if (color.equals(Color.GREEN)) {
                                        rgb = new int[] { 255, max, 255 };
                                    }
   223   224   225   226   227   228   229   230   231   232   233