How to Capture and Store Images From a Webcam in Java
"Capturing Images and Video in a Library," otherwise known as LTI-CIVIL, allows Java to capture images and video from a capture device such as a USB webcam or virtual screencast of a desktop. Finding and implementing CIVIL is essential to using a webcam through Java.
Instructions
-
-
1
Download and install the LTI-CIVIL package from its website. For Windows computers, use the latest "ZIP" archives. For Mac and Linux, use the latest "TAR.GZ" archives.
-
2
Create a new stream by assigning "system.openCaptureDeviceStream(info.getDecideID());" to a variable. Within that stream, use the "setObserver(new CaptureObserver())" code to create an observer which will watch the stream. Within the code block you've created for the observer, make sure to add a "public void onNewImage(CaptureStream streamSource, Image image)" line to actually do the capturing. This will capture a basic image from the webcam. The resulting code will look like this:
yourStream = system.openCaptureDeviceStream(info.getDeviceID());
captureStream.setObserver(new CaptureObserver())
{
public void onNewImage(CaptureStream streamSource, Image image)
}
yourStream.start();
-
-
3
Invoke the start function of your stream by typing "streamName.start();" where streamName is the variable that you created earlier.
-
1
References
- Photo Credit Jupiterimages/Photos.com/Getty Images