'videowriter'에 해당되는 글 1건

  1. 2019.06.29 How to extract video from a video file 영상 추출 하기
반응형

Explains how to extract video from a video file using OpenCV VideoWriter.

OpenCV의 VideoWriter를 이용해 비디오 파일의 영상 부분만 추출 한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main()
{
    VideoCapture capture("Earth.mp4");
    CV_Assert(capture.isOpened());
    
    int fourcc = VideoWriter::fourcc('m''p''4''v');
    double fps = capture.get(CAP_PROP_FPS);
    Size size((int)capture.get(CAP_PROP_FRAME_WIDTH), (int)capture.get(CAP_PROP_FRAME_HEIGHT));
    int delay = cvRound(1000.0 / fps);
 
    cout << "FPS: " << fps << endl << "Size: " << size << endl
        << "Number of frames: " << capture.get(CAP_PROP_FRAME_COUNT) << endl;
 
    VideoWriter writer;
    writer.open("copy.mp4", fourcc, fps, size);
    CV_Assert(writer.isOpened());
 
    while (true)
    {
        Mat frame;
        capture >> frame;
        if (frame.empty())
            break;
 
        writer << frame;
 
        imshow("Earth", frame);
 
        if (waitKey(delay) >= 0)
            break;
    }
 
    return 0;
}






반응형
Posted by J-sean
: