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

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





                        CHAPTER 6

                        ■ ■ ■

                        Vision












                            Vision: the art of seeing things invisible.

                                                                                    — Jonathan Swift

                        6.0 Introduction

                        To get my robot to see, I’ll start with a webcam that has a resolution of 320×240 pixels. We’ll
                        also need the Java Media Framework and the Java Advanced Imaging APIs. The Java Media
                        Framework is available for download from

                        http://java.sun.com/products/java-media/jmf/2.1.1/download.html
                            The Java Advanced Imaging API can be downloaded from
                        http://java.sun.com/products/java-media/jai/index.jsp

                            To make sure all your classes compile, go to your JRE or IDE and add the following JARs:
                           • jmf.jar: Java Media Framework

                           • jai_core.jar: Java Advanced Imaging Core
                           • jai_codec.jar: Java Advanced Imaging Codec
                            Up until now we’ve only used command-line programs, so the first thing we need to do is
                        create a GUI (graphical user interface) in which to render the images we’ll process. From there,
                        we’ll introduce a simple Swing class because up until now all we’ve used are command-line
                        programs. Then we’ll extend this class and use it to display an image. From there, we’ll discuss
                        how to capture images from the webcam and display and process those images.
                            Some of the processing performed in this chapter will include
                           • Thresholding: Picking color values in ranges

                           • Resizing: Resizing an image
                           • Color operations: Working with filtering and color ratios

                           • Smoothing: Smoothing/blurring an image


                                                                                                         165
   179   180   181   182   183   184   185   186   187   188   189