MRPT  2.0.1
image.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*---------------------------------------------------------------
11  APPLICATION: mrpt_ros bridge
12  FILE: image.cpp
13  AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
14  ---------------------------------------------------------------*/
15 
16 #include <cv_bridge/cv_bridge.h>
17 #include <mrpt/ros1bridge/image.h>
18 #include <sensor_msgs/Image.h>
19 #include <sensor_msgs/image_encodings.h>
20 
21 using namespace mrpt::img;
22 using namespace ros;
23 using namespace sensor_msgs;
24 using namespace cv;
25 using namespace cv_bridge;
26 
27 namespace mrpt::ros1bridge
28 {
29 mrpt::img::CImage fromROS(const sensor_msgs::Image& i)
30 {
31  return mrpt::img::CImage(
32  cv_bridge::toCvCopy(i, "bgr8").get()->image, mrpt::img::DEEP_COPY);
33 }
34 
35 sensor_msgs::Image toROS(
36  const mrpt::img::CImage& i, const std_msgs::Header& msg_header)
37 {
38  const Mat& cvImg = i.asCvMatRef();
39 
40  cv_bridge::CvImage img_bridge;
41 
42  sensor_msgs::Image msg;
43  img_bridge = CvImage(msg.header, sensor_msgs::image_encodings::BGR8, cvImg);
44 
45  img_bridge.toImageMsg(msg);
46 
47  msg.encoding = "bgr8";
48  msg.header = msg_header;
49  msg.height = i.getHeight();
50  msg.width = i.getWidth();
51 
52  return msg;
53 }
54 } // namespace mrpt::ros1bridge
55 
56 //
57 /*
58 std_msgs/Header header
59 uint32 height
60 uint32 width
61 string encoding
62 uint8 is_bigendian
63 uint32 step
64 uint8[] data
65  */
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition: CImage.cpp:227
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:849
Definition: img/CImage.h:23
mrpt::img::CImage CImage
Definition: utils/CImage.h:5
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:818
bool toROS(const mrpt::obs::CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Convert mrpt::obs::CObservationGPS -> sensor_msgs/NavSatFix The user must supply the "msg_header" fie...
Definition: gps.cpp:48
ROS message: http://docs.ros.org/api/sensor_msgs/html/msg/NavSatFix.html MRPT message: https://github...
Definition: gps.h:28
Deep copy: the copied object has a duplicate of all data, becoming independent.
Definition: img/CImage.h:78
bool fromROS(const sensor_msgs::NavSatFix &msg, mrpt::obs::CObservationGPS &obj)
Convert sensor_msgs/NavSatFix -> mrpt::obs::CObservationGPS.
Definition: gps.cpp:20
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020