Struct cameleon::camera::Camera

source ·
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>

source

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();
source

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();
source

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();
source

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.

source

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();
source

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(&params_ctxt)` instead of `as_float(&params_ctxt).
let gain_node = params_ctxt.node("Gain").unwrap().as_float(&params_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();
}
source

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();
source

pub fn new(ctrl: Ctrl, strm: Strm, ctxt: Option<Ctxt>, info: CameraInfo) -> Self

Constructs a camera.

source

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.

source

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();
source

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.

Trait Implementations§

source§

impl<Ctrl: Clone, Strm: Clone, Ctxt: Clone> Clone for Camera<Ctrl, Strm, Ctxt>

source§

fn clone(&self) -> Camera<Ctrl, Strm, Ctxt>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Ctrl: Debug, Strm: Debug, Ctxt: Debug> Debug for Camera<Ctrl, Strm, Ctxt>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Ctrl, Strm, Ctxt> RefUnwindSafe for Camera<Ctrl, Strm, Ctxt>where Ctrl: RefUnwindSafe, Ctxt: RefUnwindSafe, Strm: RefUnwindSafe,

§

impl<Ctrl, Strm, Ctxt> Send for Camera<Ctrl, Strm, Ctxt>where Ctrl: Send, Ctxt: Send, Strm: Send,

§

impl<Ctrl, Strm, Ctxt> Sync for Camera<Ctrl, Strm, Ctxt>where Ctrl: Sync, Ctxt: Sync, Strm: Sync,

§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more