Struct nokhwa::backends::capture::OpenCvCaptureDevice
source · pub struct OpenCvCaptureDevice { /* private fields */ }
input-opencv
only.Expand description
The backend struct that interfaces with OpenCV
. Note that an opencv
matching the version that this was either compiled on must be present on the user’s machine. (usually 4.5.2 or greater)
For more information, please see opencv-rust
and OpenCV VideoCapture Docs
.
To see what this does, please see CaptureBackendTrait
Quirks
- Some features don’t work properly on this backend (yet)! Setting
Resolution
, FPS,FrameFormat
does not work and will default to 640x480 30FPS. This is being worked on. - This is a cross-platform backend. This means that it will work on most platforms given that
OpenCV
is present. - This backend can also do IP Camera input.
- The backend’s backend will default to system level APIs on Linux(V4L2), Mac(AVFoundation), and Windows(Media Foundation). Otherwise, it will decide for itself.
- If the
OpenCvCaptureDevice
is initialized as aIPCamera
, theCameraFormat
’sindex
value will beu32::MAX
(4294967295). OpenCV
does not support camera querying. Camera Name and Camera supported resolution/fps/fourcc is aUnsupportedOperationError
. Note:resolution()
,frame_format()
, andframe_rate()
is not affected.CameraInfo
’s human name will be “OpenCV
Capture Device {location}”CameraInfo
’s description will contain the Camera’s Index or IP.- The API Preference order is the native OS API (linux =>
v4l2
, mac =>AVFoundation
, windows =>MSMF
) thanCAP_AUTO
Implementations§
source§impl OpenCvCaptureDevice
impl OpenCvCaptureDevice
sourcepub fn new(
index: &CameraIndex,
cam_fmt: RequestedFormat<'_>
) -> Result<Self, NokhwaError>
pub fn new( index: &CameraIndex, cam_fmt: RequestedFormat<'_> ) -> Result<Self, NokhwaError>
Creates a new capture device using the OpenCV
backend.
Indexes are gives to devices by the OS, and usually numbered by order of discovery.
IPCameras
follow the format
<protocol>://<IP>:<port>/
, but please refer to the manufacturer for the actual IP format.
Errors
If the backend fails to open the camera (e.g. Device does not exist at specified index/ip), Camera does not support specified CameraFormat
, and/or other OpenCV
Error, this will error.
Panics
If the API u32 -> i32 fails this will error
sourcepub fn is_ip_camera(&self) -> bool
pub fn is_ip_camera(&self) -> bool
Gets weather said capture device is an IPCamera
.
sourcepub fn is_index_camera(&self) -> bool
pub fn is_index_camera(&self) -> bool
Gets weather said capture device is an OS-based indexed camera.
sourcepub fn camera_location(&self) -> &CameraIndex
pub fn camera_location(&self) -> &CameraIndex
Gets the camera location
sourcepub fn opencv_preference(&self) -> i32
pub fn opencv_preference(&self) -> i32
Gets the OpenCV
API Preference number. Please refer to OpenCV VideoCapture Flag Docs
.
sourcepub fn raw_frame_vec(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
pub fn raw_frame_vec(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
Gets the RGB24 frame directly read from OpenCV
without any additional processing.
Errors
If the frame is failed to be read, this will error.
sourcepub fn raw_resolution(&self) -> Result<Resolution, NokhwaError>
pub fn raw_resolution(&self) -> Result<Resolution, NokhwaError>
Gets the resolution raw as read by OpenCV
.
Errors
If the resolution is failed to be read (e.g. invalid or not supported), this will error.
sourcepub fn raw_framerate(&self) -> Result<u32, NokhwaError>
pub fn raw_framerate(&self) -> Result<u32, NokhwaError>
Gets the framerate raw as read by OpenCV
.
Errors
If the framerate is failed to be read (e.g. invalid or not supported), this will error.
Trait Implementations§
source§impl CaptureBackendTrait for OpenCvCaptureDevice
impl CaptureBackendTrait for OpenCvCaptureDevice
source§fn backend(&self) -> ApiBackend
fn backend(&self) -> ApiBackend
source§fn camera_info(&self) -> &CameraInfo
fn camera_info(&self) -> &CameraInfo
CameraInfo
.source§fn refresh_camera_format(&mut self) -> Result<(), NokhwaError>
fn refresh_camera_format(&mut self) -> Result<(), NokhwaError>
source§fn camera_format(&self) -> CameraFormat
fn camera_format(&self) -> CameraFormat
CameraFormat
. This will force refresh to the current latest if it has changed.source§fn set_camera_format(
&mut self,
new_fmt: CameraFormat
) -> Result<(), NokhwaError>
fn set_camera_format( &mut self, new_fmt: CameraFormat ) -> Result<(), NokhwaError>
CameraFormat
This will reset the current stream if used while stream is opened. Read moresource§fn compatible_list_by_resolution(
&mut self,
_fourcc: FrameFormat
) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
fn compatible_list_by_resolution( &mut self, _fourcc: FrameFormat ) -> Result<HashMap<Resolution, Vec<u32>>, NokhwaError>
Resolution
s mapped to framerates. Not sorted! Read moresource§fn compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>
fn compatible_fourcc(&mut self) -> Result<Vec<FrameFormat>, NokhwaError>
FrameFormat
s. Will only return 2 elements at most. Read moresource§fn resolution(&self) -> Resolution
fn resolution(&self) -> Resolution
Resolution
, CameraFormat
). This will force refresh to the current latest if it has changed.source§fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>
fn set_resolution(&mut self, new_res: Resolution) -> Result<(), NokhwaError>
Resolution
This will reset the current stream if used while stream is opened. Read moresource§fn frame_rate(&self) -> u32
fn frame_rate(&self) -> u32
CameraFormat
). This will force refresh to the current latest if it has changed.source§fn set_frame_rate(&mut self, new_fps: u32) -> Result<(), NokhwaError>
fn set_frame_rate(&mut self, new_fps: u32) -> Result<(), NokhwaError>
source§fn frame_format(&self) -> FrameFormat
fn frame_format(&self) -> FrameFormat
FrameFormat
, CameraFormat
). This will force refresh to the current latest if it has changed.source§fn set_frame_format(&mut self, fourcc: FrameFormat) -> Result<(), NokhwaError>
fn set_frame_format(&mut self, fourcc: FrameFormat) -> Result<(), NokhwaError>
FrameFormat
This will reset the current stream if used while stream is opened. Read moresource§fn camera_control(
&self,
control: KnownCameraControl
) -> Result<CameraControl, NokhwaError>
fn camera_control( &self, control: KnownCameraControl ) -> Result<CameraControl, NokhwaError>
KnownCameraControl
. Read moresource§fn camera_controls(&self) -> Result<Vec<CameraControl>, NokhwaError>
fn camera_controls(&self) -> Result<Vec<CameraControl>, NokhwaError>
KnownCameraControl
Read moresource§fn set_camera_control(
&mut self,
id: KnownCameraControl,
value: ControlValueSetter
) -> Result<(), NokhwaError>
fn set_camera_control( &mut self, id: KnownCameraControl, value: ControlValueSetter ) -> Result<(), NokhwaError>
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. Read moresource§fn open_stream(&mut self) -> Result<(), NokhwaError>
fn open_stream(&mut self) -> Result<(), NokhwaError>
frame()
before you call open_stream()
. Read moresource§fn is_stream_open(&self) -> bool
fn is_stream_open(&self) -> bool
source§fn frame(&mut self) -> Result<Buffer, NokhwaError>
fn frame(&mut self) -> Result<Buffer, NokhwaError>
Buffer
. Depending on the backend, if you have not called open_stream()
before you called this,
it will either return an error. Read moresource§fn frame_raw(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
fn frame_raw(&mut self) -> Result<Cow<'_, [u8]>, NokhwaError>
source§fn stop_stream(&mut self) -> Result<(), NokhwaError>
fn stop_stream(&mut self) -> Result<(), NokhwaError>
source§fn compatible_camera_formats(
&mut self
) -> Result<Vec<CameraFormat, Global>, NokhwaError>
fn compatible_camera_formats( &mut self ) -> Result<Vec<CameraFormat, Global>, NokhwaError>
CameraFormat
of the camera Read moresource§fn decoded_buffer_size(&self, alpha: bool) -> usize
fn decoded_buffer_size(&self, alpha: bool) -> usize
alpha
is true, it will instead return the minimum size of the buffer with an alpha channel as well.
This assumes that you are decoding to RGB/RGBA for FrameFormat::MJPEG
or FrameFormat::YUYV
and Luma8/LumaA8 for FrameFormat::GRAY