CvImage

Struct CvImage 

Source
pub struct CvImage { /* private fields */ }

Implementations§

Source§

impl CvImage

Source

pub fn from_imgmsg(image: Image) -> Result<CvImage, Box<dyn Error>>

Constructs a new CvImage from a sensor_msgs::Image message.

§Example
let image = rosrust_msg::sensor_msgs::Image::default();
// set the image data
let cv_image = CvImage::from_imgmsg(image).unwrap();
§Arguments
  • image - rosrust_msg::sensor_msgs::Image message
§Returns
  • CvImage object
Examples found in repository?
examples/image_viewer.rs (line 17)
7fn main() {
8    // Initialize ros node
9    rosrust::init("image_viewer");
10
11    // Create image subscriber
12    let _subscriber_raii = rosrust::subscribe(
13        "/camera/image_raw",
14        5,
15        move |image: Image| {
16            // Convert ros Image to opencv Mat
17            let mut cv_image = CvImage::from_imgmsg(image).expect("failed to construct CvImage from ros Image"); 
18            let mat = cv_image.as_cvmat().expect("failed to convert CvImage to Mat");
19
20            // Display image
21            let window = "view";
22            highgui::named_window(window, highgui::WINDOW_AUTOSIZE).unwrap();
23            highgui::imshow(window, &mat).unwrap();
24            highgui::wait_key(1).unwrap();
25        }
26    );
27
28    rosrust::spin();
29}
Source

pub fn from_cvmat(mat: Mat, encoding: &str) -> Result<CvImage, Box<dyn Error>>

Constructs a new CvImage from a cv::Mat object.

§Example
let mat = opencv::core::Mat::default();
// set the image data
let cv_image = CvImage::from_cvmat(mat, "bgr8").unwrap();
§Arguments
  • mat - opencv::core::Mat object
  • encoding - Encoding of the image. Note that Mat does not contain any metadata about the image encoding, so it must be tracked by the user.
§Returns
  • CvImage object
Source

pub fn into_imgmsg(self, is_bigendian: u8) -> Result<Image, Box<dyn Error>>

Converts the CvImage to a sensor_msgs::Image message.

§Example:
let mut cv_image = CvImage::from_imgmsg(image_msg).unwrap();
let image_msg = cv_image.to_imgmsg(0).unwrap();
§Arguments
  • is_bigendian - Endianness of the image data. 0 for little-endian, 1 for big-endian.
§Returns
  • sensor_msgs::Image message
Source

pub fn to_cvimage( &mut self, desired_encoding: &str, ) -> Result<CvImage, Box<dyn Error>>

Converts the CvImage to a CvImage with a different encoding. It will copy the data into the new buffer.

§Example:
let mut cv_image = CvImage::from_imgmsg(image_msg).unwrap();
let cv_image = cv_image.to_cvimage("mono8").unwrap();
§Arguments
  • desired_encoding - Encoding of the new image. Check the supported encodings in the image_encodings module.
§Returns
  • CvImage object
Source

pub fn as_cvmat(&mut self) -> Result<Mat, Box<dyn Error>>

Returns the image as a cv::Mat object. This is a cheap operation as the data is shared between the CvImage and the Mat object.

§Returns
  • opencv::core::Mat object
Examples found in repository?
examples/image_viewer.rs (line 18)
7fn main() {
8    // Initialize ros node
9    rosrust::init("image_viewer");
10
11    // Create image subscriber
12    let _subscriber_raii = rosrust::subscribe(
13        "/camera/image_raw",
14        5,
15        move |image: Image| {
16            // Convert ros Image to opencv Mat
17            let mut cv_image = CvImage::from_imgmsg(image).expect("failed to construct CvImage from ros Image"); 
18            let mat = cv_image.as_cvmat().expect("failed to convert CvImage to Mat");
19
20            // Display image
21            let window = "view";
22            highgui::named_window(window, highgui::WINDOW_AUTOSIZE).unwrap();
23            highgui::imshow(window, &mat).unwrap();
24            highgui::wait_key(1).unwrap();
25        }
26    );
27
28    rosrust::spin();
29}
Source

pub fn as_container(&self) -> &DataContainer

Returns the immutable internal vector container containing the image data.

§Returns
  • DataContainer object
Source

pub fn as_mut_container(&mut self) -> &mut DataContainer

Returns the mutable internal vector container containing the image data.

§Returns
  • DataContainer object
Source

pub fn header(&self) -> &Header

Returns the immutable header message used by ROS.

§Returns
  • std_msgs::Header message
Source

pub fn header_mut(&mut self) -> &mut Header

Returns the mutable header message used by ROS.

§Returns
  • std_msgs::Header message
Source

pub fn encoding(&self) -> &String

Returns the immutable encoding string. Check the supported encodings in the image_encodings module.

§Returns
  • String object
Source

pub fn width(&self) -> usize

Returns the immutable width of the image.

§Returns
  • usize object containing the width
Source

pub fn height(&self) -> usize

Returns the immutable height of the image.

§Returns
  • usize object containing the height

Trait Implementations§

Source§

impl Debug for CvImage

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,