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

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



                                                                                   CHAPTER 6  ■  VISION  219



                                // draw line from end of direction one, to end of direction 2
                                Graphics2D g = img.createGraphics();
                                g.setColor(Color.GREEN);
                                g.drawLine((int)x1,(int) y1, (int) x2, (int) y2);

                            }



















                        Figure 6-24. The Hough transform of the three cans

                        Section Summary
                        In this section, I used a combination of filters from pixel processing and some from Java’s
                        Advanced Imaging API to process images. The methods created were
                           • ImageProcessor.smooth(): Uses JAI to smooth an image using a low-pass filter

                           • ImageProcessor.sharpen(): Uses JAI to sharpen an image using a high-pass filter
                           • ImageProcessor.sobelGradMag(): Uses JAI to find the edges of an image
                           • ImageProcessor.getHoughLines(): Uses the Hough transform to find the lines in an image

                           • ImageProcessor.drawHoughLines(): Iterates through the Hough array to create lines on
                             the processed image


                        6.5 Chapter Summary

                        In this chapter, I wanted to show you how to process images from a web camera. By the final
                        chapter, you should be able to do some complex analysis and give your robot a lot of information
                        about its world using a few algorithms and data structures.
                            In the introduction, I created two utility classes—WindowUtilities and ExitListener—to
                        assist with Swing class creation. I created an ImagePanel to provide a canvas for working with
                        processed images and generated a sample ImageViewer that renders JPEGs.
                            In section 6.1, I showed you how to install and test the Java Media Framework with
                        FindCamera, and then created a class to get a single frame from the camera called GetFrame.
                        Finally, in this chapter I created a WebCamViewer to show images in real time from your webcam.
   233   234   235   236   237   238   239   240   241   242   243