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

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



                 212    CHAPTER 6  ■  VISION



                            // sample program
                            public static void main(String[] args) {
                                try {
                                    // load image
                                    ColorGramCalibration cg2 = new ColorGramCalibration(
                                            "sample_images//coke.jpg", true);
                                    // optimize it
                                    cg2.optimize();
                                    // print colorgram for cut-paste if needed
                                    System.out.println(cg2.getBestColorGram().toString());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.exit(1);
                                }
                            }


                        }












                        Figure 6-20. All ColorGrams after optimization (Coke, 7-Up, and Pepsi)

                        Section Summary

                        In this section, I showed you a few ways to use color to identify objects. For my goal of getting
                        a beverage from the refrigerator, this was all I needed. The six methods and two classes created
                        in this section were
                            • ImageProcessor.thresholdColor(): A method to get the color thresholds of certain
                              minimum and maximum values for a particular color band: RED, GREEN, or BLUE
                            • ImageProcessor.filterColor(): A method to filter colors of a particular band

                            • ImageProcessor.getMean(): A method to compute some image statistics and get the
                              average colors of each band

                            • ImageProcessor.getHistogram(): A method that offers an alternative method of getting
                              the same statistics using Java Advanced Imaging and the histogram operation
                            • ImageProcessor.colorRatio(): A method that processes an image by colors’ ratios
                              between one another
                            • ImageProcessor.colorRatioCount(): A method that counts the colors in a ratio
   226   227   228   229   230   231   232   233   234   235   236