Skip to content

Cv2.VideoCapture

Class for video capturing from video files, image sequences or cameras. The class provides C++ API for capturing video from cameras or for reading video files and image sequences.

Detailed Description

Class for video capturing from video files, image sequences or cameras. The class provides C++ API for capturing video from cameras or for reading video files and image sequences. Here is how the class can be used:

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;
    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, COLOR_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

In C API the black-box structure CvCapture is used instead of VideoCapture.

  • A basic sample on using the VideoCapture interface can be found at opencv_source_code/samples/cpp/starter_video.cpp
  • Another basic video processing sample can be found at opencv_source_code/samples/cpp/video_dmtx.cpp
  • (Python) A basic sample on using the VideoCapture interface can be found at opencv_source_code/samples/python/video.py
  • (Python) Another basic video processing sample can be found at opencv_source_code/samples/python/video_dmtx.py
  • (Python) A multi threaded video processing sample can be found at opencv_source_code/samples/python/video_threaded.py

카메라 주요 속성 식별자

Python 상수

속성 상수설명

cv2.CAP_PROP_POS_MSEC

동영상 파일의 현재 위치인 밀리초 (millisecond)

cv2.CAP_PROP_POS_FRAMES

캡처되는 프레임의 번호

cv2.CAP_PROP_POS_AVI_RATIO

동영상 파일의 상대적 위치 (0 -시작, 1 -끝)

cv2.CAP_PROP_FRAME_WIDTH

프레임의 너비

cv2.CAP_PROP_FRAME_HEIGHT

프레임의 높이

cv2.CAP_PROP_FPS

초당 프레임 수

cv2.CAP_PROP_FOURCC

코덱의 4문자

cv2.CAP_PROP_FRAME_COUNT

동영상 파알의 총 프레임 수

cv2.CAP_PROP_FORMAT

cv2.VideoCapture.retieve()이 반환하는 행렬 포맷

cv2.CAP_PROP_BRIGHTNESS

카메라에서 영상의 밝기

cv2.CAP_PROP_CONTRAST

카메라에서 영상의 대비

cv2.CAP_PROP_SATURATION

카메라에서 영상의 포화도

cv2.CAP_PROP_HUE

카메라에서 영사의 색상

cv2.CAP_PROP_GAIN

카메라에서 영상의 Gain

cv2.CAP_PROP_EXPOSURE

카메라에서 노출

cv2.CAP_PROP_AUTOFOCUS

자동초점 조절

See also

Favorive site