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

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



                                                                                   CHAPTER 6  ■  VISION  193



                                            // calculate difference
                                            int diff = Math.abs(srcPixel - diffPixel);
                                            // make difference color
                                            Color diffColor = new Color(diff, diff, diff);
                                            // set into image
                                            dstImg.setRGB(x, y, diffColor.getRGB());
                                        }
                                    }
                                }
                                // set last frame
                                lastImage = srcImg;
                                return dstImg;
                            }


















                        Figure 6-12. Motion detect

                        Section Summary

                        In this section, we performed some processing and provided a mechanism to add multiple
                        processing operations together. The classes created in this section were

                           • FilterParameters: Creates a parameter object that can be passed to the ImageProcessor
                           • DoubleWebCamViewer: Creates a dual-view webcam that shows the original image on
                             one side and the processed image on the other
                           • ImageProcessor: The class containing all image processing code. We looked at the
                             following methods:
                              • ImageProcessor.rgbToGrey(): Converts an image to greyscale
                              • ImageProcessor.resize(): Resizes an image

                              • ImageProcessor.threshold(): Gets a greyscale color range from a minimum and
                               maximum value

                              • ImageProcessor.backgroundSubtract(): Detects motion
                            Next, it’s time to look at some techniques for processing color images.
   207   208   209   210   211   212   213   214   215   216   217