[Webcam Snap PIC] Chapter VBI-2.   Webcam Snaps Using JavaCV

 

This chapter does not appear in the book.

 

The webcam is at the heart of all the image processing and computer vision techniques that I'll be explaining in this book. This chapter is about implementing the basic webcam capabilities needed by those examples.

What's required is not a video stream coming from the camera, but a series of pictures or snaps, generated fairly infrequently (e.g. 10 images per second). Very often those pictures should be rendered as grayscales rather than in full color to help simplify the subsequent processing. It's also useful to have a way to store selected images to files.

In previous versions of this chapter, I implemented webcam snapping using JMF (the Java Media Framework). Unfortunately, JMF has become something of a dinosaur, that hasn't been updated since the last century. It can't play popular modern formats, such as MPEG-2, MPEG-4, Windows Media, RealMedia, or most QuickTime and Flash files. Its content editing functionality is feeble. More seriously for my snapping needs is that JMF's cross-platform support is becoming a problem it appears to be impossible (or very, very difficult) to get JMF to run on the 64-bit version of Windows.

It's time to move on from dear old JMF. Not unsurprisingly, there are a number of alternatives, conveniently listed on the JMF Wikipedia page. Since my key requirement is good support for image processing and computer vision techniques, I've decided to use JavaCV, a Java binding for the OpenCV vision library.

The aim is to grab images at a reasonable speed of ten image per second, and display them in succession in a JPanel. The panel output includes the average time to take a snap and do any processing upon it, which will help me adjust the snapping rate in later examples. The picture at the top of this page shows the JavaCV application in action.

The information about the picture is written in yellow in the bottom-left corner; in the picture it says "Snap Avg. Time 13.5 ms". This shows that a frame is being processed in much less time than the 100 ms interval between redraws, which leaves plenty of time for additional image processing before the next picture arrives from the camera.

One of the irritations of working with a webcam is making sure that it's been correctly installed and identified by the operating system. Section 4 of this chapter describes three standalone tools ( CommandCam, DevCon, and FFmpeg) that can check out a webcam independently of OpenCV and Java.

Although almost all of this book's examples employ OpenCV in some way, there are situations when it's massive capabilities (and size) aren't needed. The next chapter briefly puts OpenCV to one side, and implements snapping using vlcj, the Java API for the popular VLC media player.

 

Downloads


Navigation:


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