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

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



                                                                                   CHAPTER 6  ■  VISION  207



                        Example 6-23. ColorGramCalibration.java
                        package com.scottpreston.javarobot.chapter6;

                        import java.awt.BorderLayout;
                        import java.awt.Color;
                        import java.awt.image.BufferedImage;
                        import java.io.FileInputStream;
                        import java.util.Arrays;

                        import javax.swing.JFrame;

                        import com.sun.image.codec.jpeg.JPEGCodec;
                        import com.sun.image.codec.jpeg.JPEGImageDecoder;

                        public class ColorGramCalibration extends JFrame {

                            // image to calibrate
                            private BufferedImage currentImage;
                            // panel to hold image
                            private ImagePanel imagePanel;
                            // count of colors
                            private int maxCount = 0;
                            // values of histogram mean values
                            private int[] meanValues;
                            // current best ColorGram
                            private ColorGram bestColorGram = new ColorGram();
                            // mean values for color components
                            private int redAvg = 0;
                            private int greenAvg = 0;
                            private int blueAvg = 0;
                            // initial threshold
                            private double threshhold = .95;
                            // to display or not
                            private boolean toShow = true;
                            private ImageProcessor imageProcessor = new ImageProcessor();

                            public ColorGramCalibration(String fileName) throws Exception {
                                init(fileName, true);
                            }

                            public ColorGramCalibration(String fileName, boolean gui) throws Exception {
                                init(fileName, gui);
                            }
   221   222   223   224   225   226   227   228   229   230   231