Webcam

Struct Webcam 

Source
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

Source

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.

Source

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.

Source

pub fn new_def(camera_idx: i32) -> Result<Self>

Create new Webcam instance with api preference and camera index.

§Behavior

Creates a new webcam instance with a set index and the default api_preference (CAP_ANY).

§Error

Returns an error if the inpt device could not be found based on the camera_idx.

Source

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)

Source

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

Get the backend api’s name.

§Behavior

Gets the backend api’s name.

§Error

Returns an error if it failed to get the backend api’s name.

Source

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§

Source§

impl Debug for Webcam

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,