2

Possible Duplicate:
Capturing image from webcam in java?

What are the options for capturing image from webcam in java?

I know that JMF is a useful library for this, but it hasn't been updated in the past few years and I would rather not use it.

Community
  • 1
  • 1
Alina Danila
  • 1,683
  • 1
  • 24
  • 60

2 Answers2

2

May be old, but it is quite reliable and simple. Give it a try!

You can find alternatives like FMJ, which is API-compatible with JMF.

Xuggle is very good too.

Costis Aivalis
  • 13,680
  • 3
  • 46
  • 47
2

This JavaCV implementation works fine.

CODE:

import com.googlecode.javacv.OpenCVFrameGrabber;

import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

public class CaptureImage {
    private static void captureFrame() {
        // 0-default camera, 1 - next...so on
        final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        try {
            grabber.start();
            IplImage img = grabber.grab();
            if (img != null) {
                cvSaveImage("capture.jpg", img);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        captureFrame();
    }
}

There is also post on viewing live video from Camera .And configuration for JavaCV : You can modify the codes and be able to save the images in regular interval and do rest of the processing you want.

gtiwari333
  • 24,554
  • 15
  • 75
  • 102