Struct cameleon::camera::Camera [−][src]
pub struct Camera<Ctrl, Strm, Ctxt = DefaultGenApiCtxt> { pub ctrl: Ctrl, pub strm: Strm, pub ctxt: Option<Ctxt>, // some fields omitted }
Expand description
Provides easy-to-use access to a GenICam
compatible camera.
Examples
use cameleon::u3v; // Enumerates all cameras connected to the host. let mut cameras = u3v::enumerate_cameras().unwrap(); if cameras.is_empty() { println!("no camera found"); return; } let mut camera = cameras.pop().unwrap(); // Opens the camera. camera.open().unwrap(); // Loads `GenApi` context. This is necessary for streaming. camera.load_context().unwrap(); // Start streaming. let payload_rx = camera.start_streaming(10).unwrap(); let mut payload_count = 0; while payload_count < 10 { match payload_rx.try_recv() { Ok(payload) => { println!( "payload received! block_id: {:?}, timestamp: {:?}", payload.id(), payload.timestamp() ); if let Some(image_info) = payload.image_info() { println!("{:?}\n", image_info); let image = payload.image(); // do something with the image. // ... } payload_count += 1; // Send back payload to streaming loop to reuse the buffer. This is optional. payload_rx.send_back(payload); } Err(_err) => { continue; } } } // Closes the camera. camera.close().unwrap();
Fields
ctrl: Ctrl
Device control handle of the camera.
strm: Strm
Payload stream handle of the camera.
ctxt: Option<Ctxt>
GenApi context
of the camera.
Implementations
Opens the camera. Ensure calling this method before starting to use the camera.
See also close
which must be called when an opened camera is no more needed.
Examples
// Opens the camera before using it. camera.open().unwrap(); // .. Do something with camera. // Closes the camera after using it. camera.close().unwrap();
pub fn close(&mut self) -> CameleonResult<()> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]
pub fn close(&mut self) -> CameleonResult<()> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]Closes the camera.
Make sure to call this method before the camera is dropped.
To keep flexibility, this method is NOT automatically called when Camera::drop
is calles.
Examples
// Opens the camera before using it. camera.open().unwrap(); // .. Do something with camera. // Closes the camera after using it. camera.close().unwrap();
pub fn load_context(&mut self) -> CameleonResult<String> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt + FromXml,
[src]
pub fn load_context(&mut self) -> CameleonResult<String> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt + FromXml,
[src]Loads GenApi
xml from the device and builds the context, then returns the GenApi
xml
string.
Once the context has been built, the string itself is no longer needed. Therefore, you can drop the returned string at any time.
Examples
// Enumerates all cameras connected to the host. // Opens the camera before using it. camera.open().unwrap(); // Loads context. This enables you to edit parameters of the camera and start payload streaming. camera.load_context().unwrap(); // Closes the camera. camera.close().unwrap();
pub fn start_streaming(&mut self, cap: usize) -> CameleonResult<PayloadReceiver> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]
pub fn start_streaming(&mut self, cap: usize) -> CameleonResult<PayloadReceiver> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]Starts streaming and returns the receiver for the Payload
.
Make sure to load GenApi
context before calling this method.
See load_context
and set_context
how to configure GenApi
context.
NOTE: This method doesn’t change AcquisitionMode
which defined in GenICam SFNC
.
We recommend you to set the node to Continuous
if you don’t know which mode is the best.
See the GenICam SFNC
specification for more details.
Examples
camera.open().unwrap(); camera.load_context().unwrap(); // Start streaming, the capacity of the receiver is 10. let payload_rx = camera.start_streaming(10).unwrap(); // The streamed payload can be received like below: // payload_rx.recv().await.unwrap() or // payload.rx.try_recv().unwrap(); // Closes the camera. camera.close().unwrap();
Arguments
cap
- A capacity of the paylaod receiver, the sender will stop to send a payload when it gets full.
Panics
If cap
is zero, this method will panic.
pub fn stop_streaming(&mut self) -> CameleonResult<()> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]
pub fn stop_streaming(&mut self) -> CameleonResult<()> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]Stops the streaming.
The receiver returned from the previous Self::start_streaming
call will be invalidated.
This method is automatically called in close
, so no need to call
explicitly when you close the camera.
Examples
camera.open().unwrap(); // Loads `GenApi` context. This is necessary for streaming. camera.load_context().unwrap(); // Start streaming, the capacity of the receiver is 10. let payload_rx = camera.start_streaming(10).unwrap(); camera.stop_streaming().unwrap();
pub fn params_ctxt(
&mut self
) -> CameleonResult<ParamsCtxt<&mut Ctrl, &mut Ctxt>> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]
pub fn params_ctxt(
&mut self
) -> CameleonResult<ParamsCtxt<&mut Ctrl, &mut Ctxt>> where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
[src]Returns the context of the camera params.
Make sure to load GenApi
context before calling this method.
See load_context
and set_context
how to configure GenApi
context.
Examples
camera.open().unwrap(); camera.load_context().unwrap(); // Get params context. let mut params_ctxt = camera.params_ctxt().unwrap(); // Get `Gain` node of `GenApi`. // `GenApi SFNC` defines that `Gain` node should have `IFloat` interface, // so this conversion would be success if the camera follows that. // Some vendors may define `Gain` node as `IInteger`, in that case, use // `as_integer(¶ms_ctxt)` instead of `as_float(¶ms_ctxt). let gain_node = params_ctxt.node("Gain").unwrap().as_float(¶ms_ctxt).unwrap(); // Get the current value of `Gain`. if gain_node.is_readable(&mut params_ctxt).unwrap() { let value = gain_node.value(&mut params_ctxt).unwrap(); println!("{}", value); } // Set `0.1` to `Gain`. if gain_node.is_writable(&mut params_ctxt).unwrap() { gain_node.set_value(&mut params_ctxt, 0.1).unwrap(); }
Returns basic information of the camera.
This information can be obtained without calling Self::open
.
Examples
let info = camera.info();
Constructs a camera.
Converts internal types.
This method works same as std::convert::From
, just hack to avoid
E0119
.
Converts internal types. This method work same as std::convert::Into
, just hack to avoid
E0119
.
Examples
use cameleon::{DeviceControl, PayloadStream, Camera}; use cameleon::genapi::NoCacheGenApiCtxt; // Convert into `Camera<Box<dyn DeviceControl>, Box<dyn PayloadStream>, NoCacheGenApiCtxt>`. let dyn_camera: Camera<Box<dyn DeviceControl>, Box<dyn PayloadStream>, NoCacheGenApiCtxt> = camera.convert_into();
Set a context to the camera. It’s recommended to use Self::load_context
instead if Self::Ctxt
implements FromXml
trait.
Trait Implementations
Auto Trait Implementations
impl<Ctrl, Strm, Ctxt> RefUnwindSafe for Camera<Ctrl, Strm, Ctxt> where
Ctrl: RefUnwindSafe,
Ctxt: RefUnwindSafe,
Strm: RefUnwindSafe,
impl<Ctrl, Strm, Ctxt> Unpin for Camera<Ctrl, Strm, Ctxt> where
Ctrl: Unpin,
Ctxt: Unpin,
Strm: Unpin,
impl<Ctrl, Strm, Ctxt> UnwindSafe for Camera<Ctrl, Strm, Ctxt> where
Ctrl: UnwindSafe,
Ctxt: UnwindSafe,
Strm: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self