pub struct Webcam(/* private fields */);Expand description
Webcam struct definition.
The struct wraps the VideoCapture type, and has custom functions for it.
You can create a new instance with the new functions.
Implementations§
Source§impl Webcam
impl Webcam
Sourcepub fn new(camera_idx: i32, api_preference: i32) -> Result<Self>
pub fn new(camera_idx: i32, api_preference: i32) -> Result<Self>
Create new Webcam instance with api preference and camera index.
If you want to use the default api_preference you should use new_def(i32) instead
§Behavior
Creates a new webcam instance with a set index and an api_preference.
§Error
Returns an error if the inpt device could not be found based on the camera_idx, or if the api preference was invalid.
§Information
API preference consts are available at the opencv documentation. Some exmaples for this const are: CAP_MSMF, CAP_V4L.
Sourcepub fn new_def_auto_detect() -> Result<Self>
pub fn new_def_auto_detect() -> Result<Self>
Create new Webcam instance with automatic camera detection.
If you have more than one camera you should use the Self::new_def function to define which camera you are wanting to use.
§Behavior
Creates a new Webcam instance while automaticly detecting the camera input.
§Error
This returns an error if it could not find the input device.
Sourcepub fn get_frame(&mut self) -> Result<(Vec<u8>, Size_<i32>)>
pub fn get_frame(&mut self) -> Result<(Vec<u8>, Size_<i32>)>
Requests a frame from the Webcam instance.
§Behavior
Reads an image out of the VideoCapture buffer, this removes the bytes of the image from the buffer.
Returns a tuple of the raw image bytes and the size of the image.
§Information
Please note the image’s bytes returned by this function are automaticly converted from BRG8 (Which is returned by opencv by default) to RGB8
§Error
Returns an error if it:
* failed to read from the webcam.
* the color format conversion failed.
* there was some kind of error when getting the image bytes / the size of the image from the Mat.
* the Webcam instance was invalid. (It got released before requesting this frame)
Sourcepub fn get_backend_name(&self) -> Result<String>
pub fn get_backend_name(&self) -> Result<String>
Sourcepub fn release(&mut self) -> Result<()>
pub fn release(&mut self) -> Result<()>
This function drops the inner VideoCapture instance.
§Behavior
This function releases the Webcam’s underlying VideoCapture instance.
§Information
The underlying VideoCapture instance is invalidated, thus requesting frames on this Webcam instance will be unsuccessful.
§Error
Returns an error if it could not invalidate the instance.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Webcam
impl RefUnwindSafe for Webcam
impl Send for Webcam
impl !Sync for Webcam
impl Unpin for Webcam
impl UnwindSafe for Webcam
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more