pub struct Camera<Ctrl, Strm, Ctxt = DefaultGenApiCtxt> {
pub ctrl: Ctrl,
pub strm: Strm,
pub ctxt: Option<Ctxt>,
/* private fields */
}
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. Channel capacity is set to 3.
let payload_rx = camera.start_streaming(3).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§
source§impl<Ctrl, Strm, Ctxt> Camera<Ctrl, Strm, Ctxt>
impl<Ctrl, Strm, Ctxt> Camera<Ctrl, Strm, Ctxt>
sourcepub fn open(&mut self) -> CameleonResult<()>where
Ctrl: DeviceControl,
Strm: PayloadStream,
pub fn open(&mut self) -> CameleonResult<()>where Ctrl: DeviceControl, Strm: PayloadStream,
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();
sourcepub fn close(&mut self) -> CameleonResult<()>where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
pub fn close(&mut self) -> CameleonResult<()>where Ctrl: DeviceControl, Strm: PayloadStream, Ctxt: GenApiCtxt,
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();
sourcepub fn load_context(&mut self) -> CameleonResult<String>where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt + FromXml,
pub fn load_context(&mut self) -> CameleonResult<String>where Ctrl: DeviceControl, Strm: PayloadStream, Ctxt: GenApiCtxt + FromXml,
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();
sourcepub fn start_streaming(&mut self, cap: usize) -> CameleonResult<PayloadReceiver>where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
pub fn start_streaming(&mut self, cap: usize) -> CameleonResult<PayloadReceiver>where Ctrl: DeviceControl, Strm: PayloadStream, Ctxt: GenApiCtxt,
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. Channel capacity is set to 3.
let payload_rx = camera.start_streaming(3).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.
sourcepub fn stop_streaming(&mut self) -> CameleonResult<()>where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
pub fn stop_streaming(&mut self) -> CameleonResult<()>where Ctrl: DeviceControl, Strm: PayloadStream, Ctxt: GenApiCtxt,
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. Channel capacity is set to 3.
let payload_rx = camera.start_streaming(3).unwrap();
camera.stop_streaming().unwrap();
sourcepub fn params_ctxt(
&mut self
) -> CameleonResult<ParamsCtxt<&mut Ctrl, &mut Ctxt>>where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
pub fn params_ctxt( &mut self ) -> CameleonResult<ParamsCtxt<&mut Ctrl, &mut Ctxt>>where Ctrl: DeviceControl, Strm: PayloadStream, Ctxt: GenApiCtxt,
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();
}
sourcepub fn info(&self) -> &CameraInfo
pub fn info(&self) -> &CameraInfo
Returns basic information of the camera.
This information can be obtained without calling Self::open
.
Examples
let info = camera.info();
sourcepub fn new(ctrl: Ctrl, strm: Strm, ctxt: Option<Ctxt>, info: CameraInfo) -> Self
pub fn new(ctrl: Ctrl, strm: Strm, ctxt: Option<Ctxt>, info: CameraInfo) -> Self
Constructs a camera.
sourcepub fn convert_from<Ctrl2, Strm2, Ctxt2>(
from: Camera<Ctrl2, Strm2, Ctxt2>
) -> Selfwhere
Ctrl: From<Ctrl2>,
Strm: From<Strm2>,
Ctxt: From<Ctxt2>,
pub fn convert_from<Ctrl2, Strm2, Ctxt2>( from: Camera<Ctrl2, Strm2, Ctxt2> ) -> Selfwhere Ctrl: From<Ctrl2>, Strm: From<Strm2>, Ctxt: From<Ctxt2>,
Converts internal types.
This method works same as std::convert::From
, just hack to avoid
E0119
.
sourcepub fn convert_into<Ctrl2, Strm2, Ctxt2>(self) -> Camera<Ctrl2, Strm2, Ctxt2>where
Ctrl: Into<Ctrl2>,
Strm: Into<Strm2>,
Ctxt: Into<Ctxt2>,
pub fn convert_into<Ctrl2, Strm2, Ctxt2>(self) -> Camera<Ctrl2, Strm2, Ctxt2>where Ctrl: Into<Ctrl2>, Strm: Into<Strm2>, Ctxt: Into<Ctxt2>,
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();
sourcepub fn set_context<Ctxt2>(self, ctxt: Ctxt2) -> Camera<Ctrl, Strm, Ctxt2>
pub fn set_context<Ctxt2>(self, ctxt: Ctxt2) -> Camera<Ctrl, Strm, Ctxt2>
Set a context to the camera. It’s recommended to use Self::load_context
instead if Self::Ctxt
implements FromXml
trait.