[][src]Struct opencv::videoio::VideoCapture

pub struct VideoCapture { /* fields omitted */ }

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

Methods

impl VideoCapture[src]

pub fn as_raw_VideoCapture(&self) -> *mut c_void[src]

pub unsafe fn from_raw_ptr(ptr: *mut c_void) -> Self[src]

impl VideoCapture[src]

pub fn default() -> Result<VideoCapture>[src]

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.

pub fn new_from_file(filename: &str) -> Result<VideoCapture>[src]

Open video file or a capturing device or a IP video stream for video capturing

Same as VideoCapture(const String& filename, int apiPreference) but using default Capture API backends

pub fn new_from_file_with_backend(
    filename: &str,
    api_preference: i32
) -> Result<VideoCapture>
[src]

Open video file or a capturing device or a 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). 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

The list of supported API backends cv::VideoCaptureAPIs

pub fn new(index: i32) -> Result<VideoCapture>[src]

Open a camera for video capturing

Parameters

  • index: camera_id + domain_offset (CAP_*) id of the video capturing device to open. To open default camera using default backend just pass 0. Use a domain_offset to enforce a specific reader implementation if multiple are available like cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. e.g. to open Camera 1 using the MS Media Foundation API use index = 1 + cv::CAP_MSMF

See also

The list of supported API backends cv::VideoCaptureAPIs

pub fn new_with_backend(index: i32, api_preference: i32) -> Result<VideoCapture>[src]

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_V4L2.

See also

The list of supported API backends cv::VideoCaptureAPIs

pub fn open_file(&mut self, filename: &str) -> Result<bool>[src]

Open video file or a capturing device or a IP video stream for video capturing

Parameters are same as the constructor VideoCapture(const String& filename)

Returns

true if the file has been successfully opened

The method first calls VideoCapture::release to close the already opened file or camera.

pub fn open(&mut self, index: i32) -> Result<bool>[src]

Open a camera for video capturing

Parameters are same as the constructor VideoCapture(int index)

Returns

true if the camera has been successfully opened.

The method first calls VideoCapture::release to close the already opened file or camera.

pub fn open_with_backend(
    &mut self,
    camera_num: i32,
    api_preference: i32
) -> Result<bool>
[src]

Open a camera for video capturing

Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference. Definitely, is same as open(int index) where index=cameraNum + apiPreference

Returns

true if the camera has been successfully opened.

pub fn is_opened(&self) -> Result<bool>[src]

Returns true if video capturing has been initialized already.

If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.

pub fn release(&mut self) -> Result<()>[src]

Closes video file or capturing device.

The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor.

The C function also deallocates memory and clears *capture pointer.

pub fn grab(&mut self) -> Result<bool>[src]

Grabs the next frame from video file or capturing device.

Returns

true (non-zero) in the case of success.

The method/function grabs the next frame from video file or camera and returns true (non-zero) in the case of success.

The primary use of the function is in multi-camera environments, especially when the cameras do not have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames from different cameras will be closer in time.

Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the correct way of retrieving data from it is to call VideoCapture::grab() first and then call VideoCapture::retrieve() one or more times with different values of the channel parameter.

@ref tutorial_kinect_openni

pub fn retrieve(
    &mut self,
    image: &mut dyn ToOutputArray,
    flag: i32
) -> Result<bool>
[src]

Decodes and returns the grabbed video frame.

Parameters

  • image: [out] the video frame is returned here. If no frames has been grabbed the image will be empty.
  • flag: it could be a frame index or a driver specific flag

Returns

false if no frames has been grabbed

The method decodes and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns an empty image (with %cv::Mat, test it with Mat::empty()).

See also

read()

Note: In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.

C++ default parameters

  • flag: 0

pub fn read(&mut self, image: &mut dyn ToOutputArray) -> Result<bool>[src]

Grabs, decodes and returns the next video frame.

Parameters

  • image: [out] the video frame is returned here. If no frames has been grabbed the image will be empty.

Returns

false if no frames has been grabbed

The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()).

Note: In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.

pub fn set(&mut self, prop_id: i32, value: f64) -> Result<bool>[src]

Sets a property in the VideoCapture.

Parameters

  • propId: Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others
  • value: Value of the property.

Returns

true if the property is supported by backend used by the VideoCapture instance.

Note: Even if it returns true this doesn't ensure that the property value has been accepted by the capture device. See note in VideoCapture::get()

pub fn get(&self, prop_id: i32) -> Result<f64>[src]

Returns the specified VideoCapture property

Parameters

  • propId: Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others

Returns

Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoCapture instance.

Note: Reading / writing properties involves many layers. Some unexpected result might happens along this chain.

This example is not tested
VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware

The returned value might be different from what really used by the device or it could be encoded using device dependent rules (eg. steps or percentage). Effective behaviour depends from device driver and API Backend

pub fn open_file_with_backend(
    &mut self,
    filename: &str,
    api_preference: i32
) -> Result<bool>
[src]

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

Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference)

Returns

true if the file has been successfully opened

The method first calls VideoCapture::release to close the already opened file or camera.

pub fn get_backend_name(&self) -> Result<String>[src]

Returns used backend API name

Note: Stream should be opened.

Trait Implementations

impl Send for VideoCapture[src]

impl Drop for VideoCapture[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]