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.
Implementations
pub fn new(
index: usize,
format: Option<CameraFormat>,
backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
pub fn new(
index: usize,
format: Option<CameraFormat>,
backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
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>
pub fn new_with(
index: usize,
width: u32,
height: u32,
fps: u32,
fourcc: FrameFormat,
backend: CaptureAPIBackend
) -> Result<Self, NokhwaError>
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).
Sets the current Camera’s index. Note that this re-initializes the camera.
Errors
The Backend may fail to initialize.
Gets the current Camera’s backend
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.
Gets the camera information such as Name and Index as a CameraInfo
.
Gets the current CameraFormat
.
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 compatible_list_by_resolution(
&self,
fourcc: FrameFormat
) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
pub fn compatible_list_by_resolution(
&self,
fourcc: FrameFormat
) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
A hashmap of Resolution
s 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
).
A Vector of compatible FrameFormat
s.
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
).
Gets the current camera resolution (See: Resolution
, CameraFormat
).
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.
Gets the current camera framerate (See: CameraFormat
).
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.
Gets the current camera’s frame format (See: FrameFormat
, CameraFormat
).
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.
Will open the camera stream with set parameters. This will be called internally if you try and call 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.
Checks if stream if open. If it is, it will return true.
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.
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.
The minimum buffer size needed to write the current frame (RGB24). If rgba
is true, it will instead return the minimum size of the RGBA buffer needed.
pub fn frame_to_buffer(
&self,
buffer: &mut [u8],
convert_rgba: bool
) -> Result<usize, NokhwaError>
pub fn frame_to_buffer(
&self,
buffer: &mut [u8],
convert_rgba: bool
) -> Result<usize, NokhwaError>
Directly writes the current frame(RGB24) into said buffer
. If convert_rgba
is true, the buffer written will be written as an RGBA frame instead of a RGB frame. Returns the amount of bytes written on successful capture.
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 frame_texture<'a>(
&mut self,
device: &WgpuDevice,
queue: &WgpuQueue,
label: Option<&'a str>
) -> Result<WgpuTexture, NokhwaError>
pub fn frame_texture<'a>(
&mut self,
device: &WgpuDevice,
queue: &WgpuQueue,
label: Option<&'a str>
) -> Result<WgpuTexture, NokhwaError>
Directly copies a frame to a Wgpu texture. This will automatically convert the frame into a RGBA frame.
Errors
If the frame cannot be captured or the resolution is 0 on any axis, this will error.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Camera
impl !UnwindSafe for Camera