Ask Your Question

Revision history [back]

JavaCV: How to connect USB cam to system and capture?

Using the code posted below I've attempted to connect my Android device to my system. In hopes that I can execute this code and capture from there.

 public static void main(String[] args) {
    captureFrame();
}
    private static void captureFrame() {
    final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(CV_CAP_ANDROID_BACK);
    try {
        grabber.start();
        IplImage img = grabber.grab();
        if (img != null) {
            cvSaveImage("capture.jpg", img);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

This gives me the error of:

com.googlecode.javacv.FrameGrabber$Exception: cvCreateCameraCapture() Error: Could not create camera capture.
    at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:176)
    at javacv.demos.JavaCVDemos.captureFrame(JavaCVDemos.java:22)
    at javacv.demos.JavaCVDemos.main(JavaCVDemos.java:17)
BUILD SUCCESSFUL (total time: 1 second)