
Chapter NUI-1. Webcam Snaps

From:
  'Killer Game Programming in Java' website
  http://fivedots.coe.psu.ac.th/~ad/jg


Contact Address:
  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat Yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th
  http://fivedots.coe.psu.ac.th/~ad/jg


If you use this code, please mention my name, and include a link
to the book's Web site.

Thanks,
  Andrew

---------------------------------
Example Files:
  * 3 Java files: ShowJPics.java, JPicsPanel.java, JMFCapture.java

Two batch files:
  * compile.bat, run.bat

One directory:    Old_JMFCapture\
  - contains the previous version of JMFCapture.java
  - the current version restricts thelargest video format 
    to use RGB encoding, which is assumed by the other
    image manipulation code

---------------------------------
Compilation: 

$ javac *.java
    // you must have JMF installed

JMF is available from http://java.sun.com/products/java-media/jmf/
I installed the JMF Performance Pack for Windows v.2.1.1e 


----- Errors? ---
If this gives you errors, such as:

    package javax.media does not exist

then it means that javac cannot find jmf.jar
In that case try using compile.bat:

$ compile *.java

It contains a classpath setting for jmf.jar, which you should modify to fit your
directory structure.

---------------------------------
Execution: 

$ java ShowJPics

The capture device must be registered with "JMF Registry"
before ShowJPics will see it. You'll find the application below 
the JMF menu item in Windows. See section 5.2. of the chapter for
more details. 

Check the device name using "JMF Registry", and update the 
CAP_DEVICE string in JMFCapture.java accordingly. Currently it
has the value: "vfw:Microsoft WDM Image Capture (Win32):0",
which is a commonly used name in WinXP.

On my test machine, it sometimes takes 5 seconds for the first
picture to appear, but only 10-20ms for each subsequent one.

The application 'freezes' for a few seconds when the application's
close box is pressed, to wait for the JMF link to be completely
shut down.

----- Errors? ---
If this gives you errors, such as:
    Exception in thread "Thread-2" java.lang.NoClassDefFoundError: 
                                        javax/media/ControllerListener
then it means that java cannot find jmf.jar
In that case try using run.bat:

$ run ShowJPics

It contains a classpath setting for jmf.jar, which you should modify to fit your
directory structure.

---------
Last updated: 16th December 2011