pub struct CvImage { /* private fields */ }Implementations§
Source§impl CvImage
impl CvImage
Sourcepub fn from_imgmsg(image: Image) -> Result<CvImage, Box<dyn Error>>
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::Imagemessage
§Returns
CvImageobject
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}Sourcepub fn from_cvmat(mat: Mat, encoding: &str) -> Result<CvImage, Box<dyn Error>>
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::Matobjectencoding- Encoding of the image. Note thatMatdoes not contain any metadata about the image encoding, so it must be tracked by the user.
§Returns
CvImageobject
Sourcepub fn into_imgmsg(self, is_bigendian: u8) -> Result<Image, Box<dyn Error>>
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::Imagemessage
Sourcepub fn to_cvimage(
&mut self,
desired_encoding: &str,
) -> Result<CvImage, Box<dyn Error>>
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 theimage_encodingsmodule.
§Returns
CvImageobject
Sourcepub fn as_cvmat(&mut self) -> Result<Mat, Box<dyn Error>>
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::Matobject
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}Sourcepub fn as_container(&self) -> &DataContainer
pub fn as_container(&self) -> &DataContainer
Returns the immutable internal vector container containing the image data.
§Returns
DataContainerobject
Sourcepub fn as_mut_container(&mut self) -> &mut DataContainer
pub fn as_mut_container(&mut self) -> &mut DataContainer
Returns the mutable internal vector container containing the image data.
§Returns
DataContainerobject
Sourcepub fn header_mut(&mut self) -> &mut Header
pub fn header_mut(&mut self) -> &mut Header
Sourcepub fn encoding(&self) -> &String
pub fn encoding(&self) -> &String
Returns the immutable encoding string. Check the supported encodings in the
image_encodings module.
§Returns
Stringobject
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CvImage
impl RefUnwindSafe for CvImage
impl Send for CvImage
impl Sync for CvImage
impl Unpin for CvImage
impl UnwindSafe for CvImage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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