pub struct VideoCapture { /* private fields */ }
Expand 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 samples/cpp/videocapture_basic.cpp

Note: In @ref videoio_c “C API” the black-box structure CvCapture is used instead of %VideoCapture.

Note:

  • (C++) A basic sample on using the %VideoCapture interface can be found at OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp
  • (Python) A basic sample on using the %VideoCapture interface can be found at OPENCV_SOURCE_CODE/samples/python/video.py
  • (Python) A multi threaded video processing sample can be found at OPENCV_SOURCE_CODE/samples/python/video_threaded.py
  • (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend OPENCV_SOURCE_CODE/samples/python/video_v4l2.py

Implementations

Default constructor

Note: In @ref videoio_c “C API”, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

Default constructor

Note: In @ref videoio_c “C API”, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

Overloaded parameters

Opens a video file or a capturing device or an IP video stream for video capturing with API Preference

Parameters
  • filename: it can be:
    • name of video file (eg. video.avi)
    • or image sequence (eg. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
    • or URL of video stream (eg. protocol://host:port/script_name?script_params|auth)
    • or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend Note that each video stream or IP camera feed has its own URL scheme. Please refer to the documentation of source stream to know the right URL.
  • apiPreference: preferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW.
See also

cv::VideoCaptureAPIs

C++ default parameters
  • api_preference: CAP_ANY

Default constructor

Note: In @ref videoio_c “C API”, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

Overloaded parameters

Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

Default constructor

Note: In @ref videoio_c “C API”, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

Overloaded parameters

Opens a camera for video capturing

Parameters
  • index: id of the video capturing device to open. To open default camera using default backend just pass 0. (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY)
  • apiPreference: preferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L.
See also

cv::VideoCaptureAPIs

C++ default parameters
  • api_preference: CAP_ANY

Default constructor

Note: In @ref videoio_c “C API”, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

Overloaded parameters

Opens a camera for video capturing with API Preference and parameters

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

Wait for ready frames from VideoCapture.

Parameters
  • streams: input video streams
  • readyIndex: stream indexes with grabbed frames (ready to use .retrieve() to fetch actual frame)
  • timeoutNs: number of nanoseconds (0 - infinite)
Returns

true if streamReady is not empty

@throws Exception %Exception on stream errors (check .isOpened() to filter out malformed streams) or VideoCapture type is not supported

The primary use of the function is in multi-camera environments. The method fills the ready state vector, grabs video frame, if camera is ready.

After this call use VideoCapture::retrieve() to decode and fetch frame data.

C++ default parameters
  • timeout_ns: 0

Trait Implementations

Wrap the specified raw pointer Read more
Return an the underlying raw pointer while consuming this wrapper. Read more
Return the underlying raw pointer. Read more
Return the underlying mutable raw pointer Read more
Executes the destructor for this type. Read more
Opens a video file or a capturing device or an IP video stream for video capturing. Read more
Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters Read more
Opens a camera for video capturing Read more
Opens a camera for video capturing with API Preference and parameters Read more
Closes video file or capturing device. Read more
Grabs the next frame from video file or capturing device. Read more
Decodes and returns the grabbed video frame. Read more
Grabs, decodes and returns the next video frame. Read more
Sets a property in the VideoCapture. Read more
Switches exceptions mode Read more
query if exception mode is active
Returns true if video capturing has been initialized already. Read more
Returns the specified VideoCapture property Read more
Returns used backend API name Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.