Trait opencv::prelude::VideoCaptureTrait
source · pub trait VideoCaptureTrait: VideoCaptureTraitConst {
// Required method
fn as_raw_mut_VideoCapture(&mut self) -> *mut c_void;
// Provided methods
fn open_file(&mut self, filename: &str, api_preference: i32) -> Result<bool> { ... }
fn open_file_with_params(
&mut self,
filename: &str,
api_preference: i32,
params: &Vector<i32>
) -> Result<bool> { ... }
fn open(&mut self, index: i32, api_preference: i32) -> Result<bool> { ... }
fn open_with_params(
&mut self,
index: i32,
api_preference: i32,
params: &Vector<i32>
) -> Result<bool> { ... }
fn release(&mut self) -> Result<()> { ... }
fn grab(&mut self) -> Result<bool> { ... }
fn retrieve(
&mut self,
image: &mut dyn ToOutputArray,
flag: i32
) -> Result<bool> { ... }
fn read(&mut self, image: &mut dyn ToOutputArray) -> Result<bool> { ... }
fn set(&mut self, prop_id: i32, value: f64) -> Result<bool> { ... }
fn set_exception_mode(&mut self, enable: bool) -> Result<()> { ... }
fn get_exception_mode(&mut self) -> Result<bool> { ... }
}
Expand description
Mutable methods for crate::videoio::VideoCapture
Required Methods§
fn as_raw_mut_VideoCapture(&mut self) -> *mut c_void
Provided Methods§
sourcefn open_file(&mut self, filename: &str, api_preference: i32) -> Result<bool>
fn open_file(&mut self, filename: &str, api_preference: i32) -> Result<bool>
Opens a video file or a capturing device or an IP video stream for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
Returns
true
if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera.
C++ default parameters
- api_preference: CAP_ANY
sourcefn 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>
Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The params
parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)
.
See cv::VideoCaptureProperties
Returns
true
if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera.
sourcefn open(&mut self, index: i32, api_preference: i32) -> Result<bool>
fn open(&mut self, index: i32, api_preference: i32) -> Result<bool>
Opens a camera for video capturing
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
Returns
true
if the camera has been successfully opened.
The method first calls VideoCapture::release to close the already opened file or camera.
C++ default parameters
- api_preference: CAP_ANY
sourcefn 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>
Opens a camera for video capturing with API Preference and parameters
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The params
parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)
.
See cv::VideoCaptureProperties
Returns
true
if the camera has been successfully opened.
The method first calls VideoCapture::release to close the already opened file or camera.
sourcefn release(&mut self) -> Result<()>
fn release(&mut self) -> Result<()>
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.
sourcefn grab(&mut self) -> Result<bool>
fn grab(&mut self) -> Result<bool>
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.
[tutorial_kinect_openni]
sourcefn retrieve(&mut self, image: &mut dyn ToOutputArray, flag: i32) -> Result<bool>
fn retrieve(&mut self, image: &mut dyn ToOutputArray, flag: i32) -> Result<bool>
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 [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
sourcefn read(&mut self, image: &mut dyn ToOutputArray) -> Result<bool>
fn read(&mut self, image: &mut dyn ToOutputArray) -> Result<bool>
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 [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.
sourcefn set(&mut self, prop_id: i32, value: f64) -> Result<bool>
fn set(&mut self, prop_id: i32, value: f64) -> Result<bool>
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 [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()
sourcefn set_exception_mode(&mut self, enable: bool) -> Result<()>
fn set_exception_mode(&mut self, enable: bool) -> Result<()>
Switches exceptions mode
methods raise exceptions if not successful instead of returning an error code
sourcefn get_exception_mode(&mut self) -> Result<bool>
fn get_exception_mode(&mut self) -> Result<bool>
query if exception mode is active