Example usage for org.opencv.videoio VideoCapture release

List of usage examples for org.opencv.videoio VideoCapture release

Introduction

In this page you can find the example usage for org.opencv.videoio VideoCapture release.

Prototype

public void release() 

Source Link

Usage

From source file:OCV_CntrlUvcCamera.java

License:Open Source License

@Override
public void run(ImageProcessor arg0) {
    boolean bret = true;

    // ----- stop dialog during continuous grabbing -----
    diag_free = new JDialog(diag_free, title, false);
    JButton but_stop_cont = new JButton("Stop");

    but_stop_cont.addMouseListener(new MouseAdapter() {
        @Override/*from   w w  w. j  a va2 s  .  c o  m*/
        public void mouseClicked(MouseEvent e) {
            flag_fin_loop = true;
            diag_free.dispose();
        }
    });

    diag_free.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            flag_fin_loop = true;
        }
    });

    diag_free.add(but_stop_cont);
    diag_free.setSize(100, 75);
    // ----- end of stop dialog -----

    // initialize camera
    VideoCapture src_cap = new VideoCapture();
    Mat src_mat = new Mat();
    bret = src_cap.open(device);

    if (!bret) {
        IJ.error("Camera initialization is failed.");
        diag_free.dispose();
        return;
    }

    src_cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
    src_cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);

    // Setting the image display window
    width = (int) src_cap.get(CV_CAP_PROP_FRAME_WIDTH);
    height = (int) src_cap.get(CV_CAP_PROP_FRAME_HEIGHT);

    ImagePlus impDsp = IJ.createImage(title, width, height, 1, 24);

    int[] impdsp_intarray = (int[]) impDsp.getChannelProcessor().getPixels();

    impDsp.show();
    impDsp.setRoi(0, 0, impDsp.getWidth(), impDsp.getHeight());

    // show stop dialog
    diag_free.setVisible(true);

    // run
    for (;;) {
        if (flag_fin_loop) {
            break;
        }

        // grab
        impDsp.startTiming();
        bret = src_cap.read(src_mat);
        IJ.showTime(impDsp, impDsp.getStartTime(), title + " : ");

        if (!bret) {
            IJ.error("Error occurred in grabbing.");
            diag_free.dispose();
            break;
        }

        if (src_mat.empty()) {
            IJ.error("Mat is empty.");
            diag_free.dispose();
            break;
        }

        // display
        if (src_mat.type() == CvType.CV_8UC3) {
            OCV__LoadLibrary.mat2intarray(src_mat, impdsp_intarray, width, height);
        } else {
            IJ.error("Color camera is supported only.");
            diag_free.dispose();
            break;
        }

        impDsp.draw();

        // wait
        wait(wait_time);
    }

    diag_free.dispose();

    if (src_cap.isOpened()) {
        src_cap.release();
    }
}

From source file:Face_Reco.java

public static void main(String args[]) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    VideoCapture camera = new VideoCapture(0);

    if (!camera.isOpened()) {
        System.out.println("Error");
    } else {/*w ww.  j a va  2 s  . c  o m*/

        Mat frame = new Mat();
        while (true) {

            if (camera.read(frame)) {

                System.out.println("Frame Obtained");
                System.out.println("Captured Frame Width" + frame.width() + "Height" + frame.height());
                Imgcodecs.imwrite("Camera.jpg", frame);
                Imgcodecs.imread("camera.jpg");
                Imgcodecs.imread("camera.jpg", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
                System.out.println("Done!");
                break;
            }
        }

    }
    camera.release();

}

From source file:bikecalibration.VideoInfo.java

public VideoInfo(String fileName) {
    FileName = new SimpleStringProperty();
    Width = new SimpleIntegerProperty();
    Height = new SimpleIntegerProperty();
    FPS = new SimpleDoubleProperty();
    TotalNumberOfFrames = new SimpleIntegerProperty();
    Duration = new SimpleDoubleProperty();
    FileSize = new SimpleLongProperty();

    File f = new File(fileName);
    VideoCapture cap = new VideoCapture(fileName);
    FileName.set(fileName);/*from  w ww  .j ava 2  s  .  c o  m*/
    Width.set((int) cap.get(Videoio.CAP_PROP_FRAME_WIDTH));
    Height.set((int) cap.get(Videoio.CAP_PROP_FRAME_HEIGHT));
    FPS.set(cap.get(Videoio.CAP_PROP_FPS));
    TotalNumberOfFrames.set((int) cap.get(Videoio.CAP_PROP_FRAME_COUNT));
    Duration.set(1 / cap.get(Videoio.CAP_PROP_FPS) * cap.get(Videoio.CAP_PROP_FRAME_COUNT));
    FileSize.set(f.length());
    cap.release();
}

From source file:ConfOpenCV_Java.ConfOpenCV_Java.java

/**
 * @param args the command line arguments
 *//* w w  w  .  ja  v  a 2 s . com*/
public static void main(String[] args) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    System.out.println("Welcome to OpenCV " + Core.VERSION);
    String outputFile = "mivideo.avi";
    VideoCapture vc = new VideoCapture(0);
    System.out.println("fps= " + Videoio.CAP_PROP_FPS);

    //vc.set(5, 50);
    //System.out.println(vc.set(3, 1280));
    //vc.set(4, 720);
    double fps = 30;
    System.out.println(fps);

    Size frameSize = new Size((int) vc.get(Videoio.CV_CAP_PROP_FRAME_WIDTH),
            (int) vc.get(Videoio.CV_CAP_PROP_FRAME_HEIGHT));
    System.out.println(frameSize);

    VideoWriter vw = new VideoWriter(outputFile, VideoWriter.fourcc('X', '2', '6', '4'), fps, frameSize, true);
    //System.out.println(VideoWriter.fourcc('X', '2', '6', '4'));
    //System.out.println(vw.isOpened());
    Mat frame = new Mat();

    //para cargar fotos
    //Imgcodecs.imread(outputFile)
    //Imgcodecs.imwrite(outputFile, m);
    int numFramesRemaining = 5 * (int) fps;

    NewJFrame ventana = new NewJFrame();
    ventana.setVisible(true);
    g = ventana.getjPanel1().getGraphics();
    ventana.pack();
    ventana.setVisible(true);

    while (vc.read(frame) && numFramesRemaining > 0) {
        vw.write(frame);
        mostrarImagen(frame);
        numFramesRemaining--;
    }

    vw.release();
    vc.release();
    ventana.dispose();

}

From source file:io.github.jakejmattson.facialrecognition.FacialRecognition.java

License:Open Source License

private static void capture() {
    File classifier = new File("lbpcascade_frontalface_improved.xml");

    if (!classifier.exists()) {
        displayFatalError("Unable to find classifier!");
        return;//from  w w  w.jav a2  s . c om
    }

    CascadeClassifier faceDetector = new CascadeClassifier(classifier.toString());
    VideoCapture camera = new VideoCapture(0);

    if (!camera.isOpened()) {
        displayFatalError("No camera detected!");
        return;
    }

    if (!DATABASE.exists())
        DATABASE.mkdir();

    ImageFrame frame = new ImageFrame();

    while (frame.isOpen() && camera.isOpened()) {
        Mat rawImage = new Mat();
        camera.read(rawImage);
        Mat newImage = detectFaces(rawImage, faceDetector, frame);
        frame.showImage(newImage);
    }

    camera.release();
}

From source file:spycam.Spycam.java

public static void main(String args[]) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    VideoCapture camera = new VideoCapture(0);

    if (!camera.isOpened()) {
        System.out.println("Error");
    } else {/*from w  w w .  ja v a  2 s . c  om*/
        Mat frame = new Mat();
        while (true) {
            if (camera.read(frame)) {
                System.out.println("Frame Obtained");
                System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height());
                Imgcodecs.imwrite("camera.jpg", frame);
                System.out.println("OK");
                break;
            }
        }
    }
    camera.release();
}