Example usage for org.opencv.videoio VideoWriter write

List of usage examples for org.opencv.videoio VideoWriter write

Introduction

In this page you can find the example usage for org.opencv.videoio VideoWriter write.

Prototype

public void write(Mat image) 

Source Link

Usage

From source file:ConfOpenCV_Java.ConfOpenCV_Java.java

/**
 * @param args the command line arguments
 *///from w  ww . j  ava2s.c o  m
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();

}