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 [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§
Source§impl VideoCapture
impl VideoCapture
Sourcepub fn default() -> Result<VideoCapture>
pub fn default() -> Result<VideoCapture>
Default constructor
Note: In [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.
Sourcepub fn from_file(filename: &str, api_preference: i32) -> Result<VideoCapture>
pub fn from_file(filename: &str, api_preference: i32) -> Result<VideoCapture>
Default constructor
Note: In [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 likeimg_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
Sourcepub fn from_file_def(filename: &str) -> Result<VideoCapture>
pub fn from_file_def(filename: &str) -> Result<VideoCapture>
@overload 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 likeimg_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
§Note
This alternative version of [from_file] function uses the following default values for its arguments:
- api_preference: CAP_ANY
Sourcepub fn from_file_with_params(
filename: &str,
api_preference: i32,
params: &Vector<i32>,
) -> Result<VideoCapture>
pub fn from_file_with_params( filename: &str, api_preference: i32, params: &Vector<i32>, ) -> Result<VideoCapture>
Default constructor
Note: In [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
Sourcepub fn new(index: i32, api_preference: i32) -> Result<VideoCapture>
pub fn new(index: i32, api_preference: i32) -> Result<VideoCapture>
Default constructor
Note: In [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
Sourcepub fn new_def(index: i32) -> Result<VideoCapture>
pub fn new_def(index: i32) -> Result<VideoCapture>
@overload 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
§Note
This alternative version of [new] function uses the following default values for its arguments:
- api_preference: CAP_ANY
Sourcepub fn new_with_params(
index: i32,
api_preference: i32,
params: &Vector<i32>,
) -> Result<VideoCapture>
pub fn new_with_params( index: i32, api_preference: i32, params: &Vector<i32>, ) -> Result<VideoCapture>
Default constructor
Note: In [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
Sourcepub fn new_1(
source: &Ptr<IStreamReader>,
api_preference: i32,
params: &Vector<i32>,
) -> Result<VideoCapture>
pub fn new_1( source: &Ptr<IStreamReader>, api_preference: i32, params: &Vector<i32>, ) -> Result<VideoCapture>
Default constructor
Note: In [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 using data stream.
The params
parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)
.
See cv::VideoCaptureProperties
Sourcepub fn wait_any(
streams: &Vector<VideoCapture>,
ready_index: &mut Vector<i32>,
timeout_ns: i64,
) -> Result<bool>
pub fn wait_any( streams: &Vector<VideoCapture>, ready_index: &mut Vector<i32>, timeout_ns: i64, ) -> Result<bool>
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
Sourcepub fn wait_any_def(
streams: &Vector<VideoCapture>,
ready_index: &mut Vector<i32>,
) -> Result<bool>
pub fn wait_any_def( streams: &Vector<VideoCapture>, ready_index: &mut Vector<i32>, ) -> Result<bool>
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.
§Note
This alternative version of VideoCapture::wait_any function uses the following default values for its arguments:
- timeout_ns: 0
Trait Implementations§
Source§impl Boxed for VideoCapture
impl Boxed for VideoCapture
Source§unsafe fn from_raw(
ptr: <VideoCapture as OpenCVFromExtern>::ExternReceive,
) -> Self
unsafe fn from_raw( ptr: <VideoCapture as OpenCVFromExtern>::ExternReceive, ) -> Self
Source§fn into_raw(self) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSendMut
Source§fn as_raw(&self) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSend
Source§fn as_raw_mut(
&mut self,
) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self, ) -> <VideoCapture as OpenCVTypeExternContainer>::ExternSendMut
Source§impl Debug for VideoCapture
impl Debug for VideoCapture
Source§impl Drop for VideoCapture
impl Drop for VideoCapture
Source§impl VideoCaptureTrait for VideoCapture
impl VideoCaptureTrait for VideoCapture
fn as_raw_mut_VideoCapture(&mut self) -> *mut c_void
Source§fn open_file(&mut self, filename: &str, api_preference: i32) -> Result<bool>
fn open_file(&mut self, filename: &str, api_preference: i32) -> Result<bool>
Source§fn open_file_def(&mut self, filename: &str) -> Result<bool>
fn open_file_def(&mut self, filename: &str) -> Result<bool>
Source§fn open_file_with_params(
&mut self,
filename: &str,
api_preference: i32,
params: &Vector<i32>,
) -> Result<bool>
fn open_file_with_params( &mut self, filename: &str, api_preference: i32, params: &Vector<i32>, ) -> Result<bool>
Source§fn open(&mut self, index: i32, api_preference: i32) -> Result<bool>
fn open(&mut self, index: i32, api_preference: i32) -> Result<bool>
Source§fn open_def(&mut self, index: i32) -> Result<bool>
fn open_def(&mut self, index: i32) -> Result<bool>
Source§fn open_with_params(
&mut self,
index: i32,
api_preference: i32,
params: &Vector<i32>,
) -> Result<bool>
fn open_with_params( &mut self, index: i32, api_preference: i32, params: &Vector<i32>, ) -> Result<bool>
Source§fn open_1(
&mut self,
source: &Ptr<IStreamReader>,
api_preference: i32,
params: &Vector<i32>,
) -> Result<bool>
fn open_1( &mut self, source: &Ptr<IStreamReader>, api_preference: i32, params: &Vector<i32>, ) -> Result<bool>
Source§fn grab(&mut self) -> Result<bool>
fn grab(&mut self) -> Result<bool>
Source§fn retrieve(
&mut self,
image: &mut impl ToOutputArray,
flag: i32,
) -> Result<bool>
fn retrieve( &mut self, image: &mut impl ToOutputArray, flag: i32, ) -> Result<bool>
Source§fn retrieve_def(&mut self, image: &mut impl ToOutputArray) -> Result<bool>
fn retrieve_def(&mut self, image: &mut impl ToOutputArray) -> Result<bool>
Source§fn read(&mut self, image: &mut impl ToOutputArray) -> Result<bool>
fn read(&mut self, image: &mut impl ToOutputArray) -> Result<bool>
Source§impl VideoCaptureTraitConst for VideoCapture
impl VideoCaptureTraitConst for VideoCapture
fn as_raw_VideoCapture(&self) -> *const c_void
Source§fn is_opened(&self) -> Result<bool>
fn is_opened(&self) -> Result<bool>
Source§fn get(&self, prop_id: i32) -> Result<f64>
fn get(&self, prop_id: i32) -> Result<f64>
Source§fn get_exception_mode(&self) -> Result<bool>
fn get_exception_mode(&self) -> Result<bool>
impl Send for VideoCapture
Auto Trait Implementations§
impl Freeze for VideoCapture
impl RefUnwindSafe for VideoCapture
impl !Sync for VideoCapture
impl Unpin for VideoCapture
impl UnwindSafe for VideoCapture
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
Source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
Mat
or another similar object. By passing
a mutable reference to the Mat
to this function your closure will get called with the read reference and a write references
to the same Mat
. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data,
but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place
modification is imgproc::threshold
. Read more