Struct nokhwa::Camera[][src]

pub struct Camera { /* fields omitted */ }
Expand description

The main Camera struct. This is the struct that abstracts over all the backends, providing a simplified interface for use. For more details, please refer to CaptureBackendTrait

Implementations

impl Camera[src]

pub fn new(
    index: usize,
    format: Option<CameraFormat>,
    backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
[src]

Create a new camera from an index, format, and backend. format can be None.

Errors

This will error if you either have a bad platform configuration (e.g. input_v4l but not on linux) or the backend cannot create the camera (e.g. permission denied).

pub fn new_with(
    index: usize,
    width: u32,
    height: u32,
    fps: u32,
    fourcc: FrameFormat,
    backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
[src]

Create a new Camera from raw values.

Errors

This will error if you either have a bad platform configuration (e.g. input_v4l but not on linux) or the backend cannot create the camera (e.g. permission denied).

pub fn index(&self) -> usize[src]

Gets the current Camera’s index.

pub fn set_index(self, new_idx: usize) -> Result<Self, NokhwaError>[src]

Sets the current Camera’s index. Note that this re-initializes the camera.

Errors

The Backend may fail to initialize.

pub fn backend(&self) -> CaptureAPIBackend[src]

Gets the current Camera’s backend

pub fn set_backend(
    self,
    new_backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
[src]

Sets the current Camera’s backend. Note that this re-initializes the camera.

Errors

The new backend may not exist or may fail to initialize the new camera.

pub fn get_info(&self) -> CameraInfo[src]

Gets the camera information such as Name and Index as a CameraInfo.

pub fn get_camera_format(&self) -> CameraFormat[src]

Gets the current CameraFormat.

pub fn set_camera_format(
    &mut self,
    new_fmt: CameraFormat
) -> Result<(), NokhwaError>
[src]

Will set the current CameraFormat This will reset the current stream if used while stream is opened.

Errors

If you started the stream and the camera rejects the new camera format, this will return an error.

pub fn get_compatible_list_by_resolution(
    &self,
    fourcc: FrameFormat
) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
[src]

A hashmap of Resolutions mapped to framerates

Errors

This will error if the camera is not queryable or a query operation has failed. Some backends will error this out as a Unsupported Operation (NokhwaError::UnsupportedOperation).

pub fn get_compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>[src]

A Vector of compatible FrameFormats.

Errors

This will error if the camera is not queryable or a query operation has failed. Some backends will error this out as a Unsupported Operation (NokhwaError::UnsupportedOperation).

pub fn get_resolution(&self) -> Resolution[src]

Gets the current camera resolution (See: Resolution, CameraFormat).

pub fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>[src]

Will set the current Resolution This will reset the current stream if used while stream is opened.

Errors

If you started the stream and the camera rejects the new resolution, this will return an error.

pub fn get_framerate(&self) -> u32[src]

Gets the current camera framerate (See: CameraFormat).

pub fn set_framerate(&mut self, new_fps: u32) -> Result<(), NokhwaError>[src]

Will set the current framerate This will reset the current stream if used while stream is opened.

Errors

If you started the stream and the camera rejects the new framerate, this will return an error.

pub fn get_frameformat(&self) -> FrameFormat[src]

Gets the current camera’s frame format (See: FrameFormat, CameraFormat).

pub fn set_frameformat(
    &mut self,
    fourcc: FrameFormat
) -> Result<(), NokhwaError>
[src]

Will set the current FrameFormat This will reset the current stream if used while stream is opened.

Errors

If you started the stream and the camera rejects the new frame foramt, this will return an error.

pub fn open_stream(&mut self) -> Result<(), NokhwaError>[src]

Will open the camera stream with set parameters. This will be called internally if you try and call get_frame() before you call open_stream().

Errors

If the specific backend fails to open the camera (e.g. already taken, busy, doesn’t exist anymore) this will error.

pub fn is_stream_open(&self) -> bool[src]

Checks if stream if open. If it is, it will return true.

pub fn get_frame(&self) -> Result<ImageBuffer<Rgb<u8>, Vec<u8>>, NokhwaError>[src]

Will get a frame from the camera as a Raw RGB image buffer. Depending on the backend, if you have not called open_stream() before you called this, it will either return an error.

Errors

If the backend fails to get the frame (e.g. already taken, busy, doesn’t exist anymore), the decoding fails (e.g. MJPEG -> u8), or open_stream() has not been called yet, this will error.

pub fn get_frame_raw(&self) -> Result<Vec<u8>, NokhwaError>[src]

Will get a frame from the camera without any processing applied, meaning you will usually get a frame you need to decode yourself.

Errors

If the backend fails to get the frame (e.g. already taken, busy, doesn’t exist anymore), or open_stream() has not been called yet, this will error.

pub fn stop_stream(&self) -> Result<(), NokhwaError>[src]

Will drop the stream.

Errors

Please check the Quirks section of each backend.

Auto Trait Implementations

impl !RefUnwindSafe for Camera

impl !Send for Camera

impl !Sync for Camera

impl Unpin for Camera

impl !UnwindSafe for Camera

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T

pub const ALIGN: usize

The alignment of pointer.

type Init = T

The type for initializers.

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

Initializes a with the given initializer. Read more

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

Dereferences the given pointer. Read more

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

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)

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

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.

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

Performs the conversion.

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.

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

Performs the conversion.