Buscar..


Introducción

Siempre que trabaje con fuentes de video, es posible que desee guardar el resultado del procesamiento de la imagen en forma de un nuevo archivo de video. Para salidas de video simples, puede utilizar la clase VideoWriter incorporada de OpenCV, diseñada para esto. Es útil mirar algunos conceptos antes de usarlos. Estos conceptos son codec, es decir, decodificador y FourCC (código de cuatro caracteres).

Creando un video con OpenCV (Java)

VideoWriter videoWriter;
videoWriter = new VideoWriter(outputFile, VideoWriter.fourcc('x', '2','6','4'),
                fps, frameSize, isRGB);
//We have stated that we will use x264 as codec with FourCC
//For writing, we add the following method and it will write the image we give as parameter in this call.
 public void Write(Mat frame) {
        if(videoWriter.isOpened()==false){
            videoWriter.release();
            throw new IllegalArgumentException("Video Writer Exception: VideoWriter not opened,"
                    + "check parameters.");        
        }
        //Write video
        videoWriter.write(frame);
    }

//With Video Capture for example, we can read images from the camera and write the same video

VideoCapture videoCapture = new VideoCapture(0);
Size frameSize = new Size((int) videoCapture.get(Videoio.CAP_PROP_FRAME_WIDTH), (int) videoCapture.get(Videoio.CAP_PROP_FRAME_HEIGHT));
VideoWriter videoWriter = new VideoWriter("test.avi", VideoWriter.fourcc('x', '2','6','4'),
                videoCapture.get(Videoio.CAP_PROP_FPS), frameSize, true);
while (videoCapture.read(mat)) {
            videoWriter.write(mat);         
        }
        videoCapture.release();
        videoWriter.release();


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow