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

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



                                                                                   CHAPTER 6  ■  VISION  173



                                // in case this is overloaded later
                                imagePanel.setImage(currentImage);

                            }


                            public static void main(String[] args) {
                                try {
                                  ImageViewer imageViewer = new ImageViewer("sample_images/stonehenge.jpg");
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.exit(1);
                                }
                            }
                        }

                            These are the basics. Now it’s time to view images captured from a webcam. In the next
                        section, I’ll show you how to configure the Java Media Framework, use that to get the image
                        from your webcam inside the ImageViewer, and then create a class for viewing the webcam
                        image in real time.
                            So far, the classes created were
                           • WindowUtilities: Makes it easier to create a native look and feel for your Swing components

                           • ExitListener: Provides a listener to exit the program when the window exits
                           • SimpleSwing: Creates a simple-to-use Swing component
                           • ImagePanel: Provides a canvas to display and repaint images

                           • ImageViewer: Renders and displays images
                            In the next chapter, we’ll use the classes created here, as well as the Java Media Frame-
                        work, to display images and video from a webcam.

                        6.1 Image Capture


                        Once you install the Java Media Framework, test the installation by running JMStudio. JMStudio
                        detects your capture devices (both audio and video). Go to File ➤ Preferences (see Figure 6-4).
                        This brings up the JMF Registry Editor (see Figure 6-5). Select the Capture Devices tab and then
                        click Detect Capture Devices. After a moment, the right pane will display the capture devices
                        details.



                        ■Note  The Locator identifier is on the second line of text. This locator will be what we use in the rest of the
                        chapter to identify your webcam.
   187   188   189   190   191   192   193   194   195   196   197