[−][src]Crate uvc
Safe wrapper around libuvc
This crate gives access to webcams connected to the computer, allowing one to stream and capture video.
How to use this crate
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::time::Duration; // Get a libuvc context let ctx = uvc::Context::new().expect("Could not get context"); // Get a default device let dev = ctx .find_device(None, None, None) .expect("Could not find device"); // Or create an iterator over all available devices let mut _devices = ctx.devices().expect("Could not enumerate devices"); // The device must be opened to create a handle to the device let devh = dev.open().expect("Could not open device"); // Most webcams support this format let format = uvc::StreamFormat { width: 640, height: 480, fps: 30, format: uvc::FrameFormat::YUYV, }; // Get the necessary stream information let mut streamh = devh .get_stream_handle_with_format(format) .expect("Could not open a stream with this format"); // This is a counter, increasing by one for every frame // This data must be 'static + Send + Sync to be used in // the callback used in the stream let counter = Arc::new(AtomicUsize::new(0)); // Get a stream, calling the closure as callback for every frame let stream = streamh .start_stream( |_frame, count| { count.fetch_add(1, Ordering::SeqCst); }, counter.clone(), ).expect("Could not start stream"); // Wait 10 seconds std::thread::sleep(Duration::new(10, 0)); // Explicitly stop the stream // The stream would also be stopped // when going out of scope (dropped) stream.stop(); println!("Counter: {}", counter.load(Ordering::SeqCst));
See also mirror.rs
in the examples to get an example of how to capture and display a stream
Structs
ActiveStream | Active stream |
Context | Contains the |
Device | Device that can be opened |
DeviceDescription | Describes the device |
DeviceHandle | Open handle to a device |
DeviceList | List of camera devices, iterate to get the device(s) |
FormatDescriptor | Describes possible formats |
FormatDescriptors | Iterate to get a |
Frame | Frame containing the image data |
FrameDescriptor | Describes possible frames |
FrameDescriptors | Iterate to get a |
StreamFormat | Format one can request a stream to produce |
StreamHandle | Stream handle |
Enums
AutoExposureMode | |
AutoExposurePriority | |
DescriptionSubtype | Describes what frame or format is supported |
Error | Error codes from |
FrameFormat | Format of a frame |
ScanningMode |
Type Definitions
Result | Result type of functions in this crate |