pub struct CallbackCamera { /* private fields */ }
Available on crate feature output-threaded only.
Expand description

Creates a camera that runs in a different thread that you can use a callback to access the frames of. It uses a Arc and a Mutex to ensure that this feels like a normal camera, but callback based. See Camera for more details on the camera itself.

Your function is called every time there is a new frame. In order to avoid frame loss, it should complete before a new frame is available. If you need to do heavy image processing, it may be beneficial to directly pipe the data to a new thread to process it there.

Note that this does not have WGPU capabilities. This should be implemented in your callback.

SAFETY

The Mutex guarantees exclusive access to the underlying camera struct. They should be safe to impl Send on.

Implementations§

source§

impl CallbackCamera

source

pub fn new( index: CameraIndex, format: RequestedFormat<'_>, callback: impl FnMut(Buffer) + Send + 'static ) -> Result<Self, NokhwaError>

Create a new ThreadedCamera from a CameraIndex and format

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

source

pub fn with_custom( camera: Camera, callback: impl FnMut(Buffer) + Send + 'static ) -> Self

Allows creation of a Camera with a custom backend. This is useful if you are creating e.g. a custom module.

You must have set a format beforehand.

source

pub fn index(&self) -> &CameraIndex

Gets the current Camera’s index.

source

pub fn set_index(&mut self, new_idx: &CameraIndex) -> Result<(), NokhwaError>

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

Errors

The Backend may fail to initialize.

source

pub fn backend(&self) -> Result<ApiBackend, NokhwaError>

Gets the current Camera’s backend

source

pub fn set_backend( &mut self, new_backend: ApiBackend ) -> Result<(), NokhwaError>

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.

source

pub fn info(&self) -> &CameraInfo

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

source

pub fn camera_format(&self) -> Result<CameraFormat, NokhwaError>

Gets the current CameraFormat.

source

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

👎Deprecated since 0.10.0: please use set_camera_requset instead.

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.

source

pub fn set_camera_requset( &mut self, request: RequestedFormat<'_> ) -> Result<CameraFormat, NokhwaError>

Will set the current CameraFormat, using a [RequestedFormat.] This will reset the current stream if used while stream is opened.

This will also update the cache.

This will return the new CameraFormat

Errors

If nothing fits the requested criteria, this will return an error.

source

pub fn compatible_list_by_resolution( &mut self, fourcc: FrameFormat ) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>

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

source

pub fn compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>

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

source

pub fn resolution(&self) -> Result<Resolution, NokhwaError>

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

source

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

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.

source

pub fn frame_rate(&self) -> Result<u32, NokhwaError>

Gets the current camera framerate (See: CameraFormat).

source

pub fn set_frame_rate(&mut self, new_fps: u32) -> Result<(), NokhwaError>

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.

source

pub fn frame_format(&self) -> Result<FrameFormat, NokhwaError>

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

source

pub fn set_frame_format( &mut self, fourcc: FrameFormat ) -> Result<(), NokhwaError>

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 format, this will return an error.

source

pub fn supported_camera_controls( &self ) -> Result<Vec<KnownCameraControl>, NokhwaError>

Gets the current supported list of KnownCameraControl

Errors

If the list cannot be collected, this will error. This can be treated as a “nothing supported”.

source

pub fn camera_controls(&self) -> Result<Vec<CameraControl>, NokhwaError>

Gets the current supported list of CameraControls keyed by its name as a String.

Errors

If the list cannot be collected, this will error. This can be treated as a “nothing supported”.

source

pub fn camera_controls_string( &self ) -> Result<HashMap<String, CameraControl>, NokhwaError>

Gets the current supported list of CameraControls keyed by its name as a String.

Errors

If the list cannot be collected, this will error. This can be treated as a “nothing supported”.

source

pub fn camera_controls_known_camera_controls( &self ) -> Result<HashMap<KnownCameraControl, CameraControl>, NokhwaError>

Gets the current supported list of CameraControls keyed by its name as a String.

Errors

If the list cannot be collected, this will error. This can be treated as a “nothing supported”.

source

pub fn camera_control( &self, control: KnownCameraControl ) -> Result<CameraControl, NokhwaError>

Gets the value of KnownCameraControl.

Errors

If the control is not supported or there is an error while getting the camera control values (e.g. unexpected value, too high, etc) this will error.

source

pub fn set_camera_control( &mut self, id: KnownCameraControl, control: ControlValueSetter ) -> Result<(), NokhwaError>

Sets the control to control in the camera. Usually, the pipeline is calling camera_control(), getting a camera control that way then calling value() to get a ControlValueSetter and setting the value that way.

Errors

If the control is not supported, the value is invalid (less than min, greater than max, not in step), or there was an error setting the control, this will error.

source

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

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

Errors

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

source

pub fn set_callback( &mut self, callback: impl FnMut(Buffer) + Send + 'static ) -> Result<(), NokhwaError>

Sets the frame callback to the new specified function. This function will be called instead of the previous one(s).

source

pub fn poll_frame(&mut self) -> Result<Buffer, NokhwaError>

Polls the camera for a frame, analogous to Camera::frame

Errors

This will error if the camera fails to capture a frame.

source

pub fn last_frame(&self) -> Result<Buffer, NokhwaError>

Gets the last frame captured by the camera.

source

pub fn is_stream_open(&self) -> Result<bool, NokhwaError>

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

source

pub fn stop_stream(&mut self) -> Result<(), NokhwaError>

Will drop the stream.

Errors

Please check the Quirks section of each backend.

Trait Implementations§

source§

impl Drop for CallbackCamera

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>