[TWAIN PIC] Chapter 9.  Webcam Snaps

 

This chapter looks at two ways to capture images from a webcam: with TWAIN (the Technology Without An Interesting Name), and using JMF (Java Media Framework). The aim is to grab images as quickly as possible, then display them in rapid succession in a JPanel, hopefully at movie-like frame rates. The panel output includes the number of pictures displayed so far and the average time to take a snap, information that'll help me judge the two technologies.

[JMF PIC]

The screenshots on the right of this page show the TWAIN and JMF applications.

The TWAIN text in the top screenshot is "Pic 26. 3.88 secs", and the JMF message is "Pic 1007. 19.3 ms". This highlights the most significant difference between the two approaches - TWAIN takes a lot longer to generate a picture.

Why Grab Frames?

Since the aim is to show images at video-like speeds in the panel, why not just access the webcam in video mode? One reason for obtaining frames is they can be easily pasted into a Java 3D scene, as in the "Playing Movies" chapters 28.3 and 28.5 of Killer Game Programming in Java.

Another reason is that image processing techniques can be applied to the frames prior to their display. Chapter 6 of Killer Game Programming in Java discusses a variety of visual effects for BufferedImages.

Another advantage of frame grabbing is that the capture rate can be adjusted to suit the application. For instance, a networked 3D chat room may only want to update a user's image every second in order to reduce the load on the network. An application monitoring plant growth may only want to take a picture every hour.

 

Downloads


Navigation:


Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page