Page 199 - The Definitive Guide to Building Java Robots
P. 199
Preston_5564C06.fm Page 180 Friday, September 23, 2005 5:13 AM
180 CHAPTER 6 ■ VISION
// get frame from GetFrame
public void getPic() {
try {
// set to image panel and repaint called from ImagePanel
imagePanel.setImage(getFrame.getBufferedImage());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
// get the frame grabber
public GetFrame getGetFrame() {
return getFrame;
}
// get frames per second
public int getFps() {
return fps;
}
//sets frames per second
public void setFps(int fps) {
this.fps = fps;
}
public static void main(String[] args) {
try {
WebCamViewer webcam = new WebCamViewer();
webcam.start();
Utils.pause(2000);
webcam.stop();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
Section Summary
In this section, I used the Java Media Framework to get an image from a webcam and display it
inside a viewer. Classes created in this section were
• FindCamera: Tests the JMF installation
• GetFrame: Gets a frame from the webcam
• WebCamViewer: Gets successive frames from the webcam at a defined interval
Now that we have images that can be processed, it’s time to start processing them.