Trait nokhwa::CaptureBackendTrait[][src]

pub trait CaptureBackendTrait {
Show methods fn get_info(&self) -> CameraInfo;
fn get_camera_format(&self) -> CameraFormat;
fn set_camera_format(
        &mut self,
        new_fmt: CameraFormat
    ) -> Result<(), NokhwaError>;
fn get_compatible_list_by_resolution(
        &self,
        fourcc: FrameFormat
    ) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>;
fn get_compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>;
fn get_resolution(&self) -> Resolution;
fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>;
fn get_framerate(&self) -> u32;
fn set_framerate(&mut self, new_fps: u32) -> Result<(), NokhwaError>;
fn get_frameformat(&self) -> FrameFormat;
fn set_frameformat(
        &mut self,
        fourcc: FrameFormat
    ) -> Result<(), NokhwaError>;
fn open_stream(&mut self) -> Result<(), NokhwaError>;
fn is_stream_open(&self) -> bool;
fn get_frame(
        &mut self
    ) -> Result<ImageBuffer<Rgb<u8>, Vec<u8>>, NokhwaError>;
fn get_frame_raw(&mut self) -> Result<Vec<u8>, NokhwaError>;
fn stop_stream(&mut self) -> Result<(), NokhwaError>;
}
Expand description

This trait is for any backend that allows you to grab and take frames from a camera. Many of the backends are blocking, if the camera is occupied the library will block while it waits for it to become availible.

Note:

  • Backends, if not provided with a camera format, will be spawned with 640x480@15 FPS, MJPEG CameraFormat.
  • Behaviour can differ from backend to backend. While the [Cameraa] struct abstracts most of this away, if you plan to use the raw backend structs please read the Quirks section of each backend.

Required methods

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

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

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

Gets the current CameraFormat.

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.

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).

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).

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

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

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.

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

Gets the current camera framerate (See: CameraFormat).

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.

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

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

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.

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.

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

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

fn get_frame(&mut 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.

fn get_frame_raw(&mut 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.

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

Will drop the stream.

Errors

Please check the Quirks section of each backend.

Implementors

impl<'a> CaptureBackendTrait for UVCCaptureDevice<'a>[src]

impl<'a> CaptureBackendTrait for V4LCaptureDevice<'a>[src]