Class.VideoCap.java Source code

Java tutorial

Introduction

Here is the source code for Class.VideoCap.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Class;

import java.io.File;
import org.opencv.core.*;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;

public class VideoCap {

    public static void Capture() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture camera = new VideoCapture(0);

        if (!camera.isOpened()) {
            System.out.println("Error");
        } else {
            Mat frame = new Mat();
            while (true) {
                if (camera.read(frame)) {
                    File f = new File("src/PicturesWarning/intruso.jpg");
                    Highgui.imwrite(f.getPath(), frame);

                    break;
                }
            }
        }
        camera.release();
    }
}