stereo_image.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*---------------------------------------------------------------
11  APPLICATION: mrpt_ros bridge
12  FILE: stereo_image.cpp
13  AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
14  ---------------------------------------------------------------*/
15 
16 #include "ros/ros.h"
18 #include "mrpt_bridge/image.h"
19 #include <opencv/highgui.h>
20 #include <cv_bridge/cv_bridge.h>
21 
22 #include <sensor_msgs/Image.h>
24 
25 #include <mrpt/version.h>
26 #if MRPT_VERSION >= 0x199
27 using namespace mrpt::img;
28 #else
29 using namespace mrpt::utils;
30 #endif
31 
32 using namespace ros;
33 using namespace sensor_msgs;
34 using namespace cv;
35 using namespace cv_bridge;
36 
37 namespace mrpt_bridge
38 {
39 namespace stereo_image
40 {
41 /*bool ros2mrpt(const sensor_msgs::Image &msg, CObservationImage &obj)
42 {
43  CvImage *frame1 = cv_bridge::toCvCopy(msg, "bgr8").get();
44 //CvShare(msg,"bgr8").image;
45 
46 }
47 */
48 /************************************************************************
49  * mrpt2ros *
50  ************************************************************************/
51 bool mrpt2ros(
52  const CObservationStereoImages& obj, const std_msgs::Header& msg_header,
53  sensor_msgs::Image& left, sensor_msgs::Image& right,
54  stereo_msgs::DisparityImage& disparity)
55 {
57  CImage temp_img = obj.imageLeft;
58 #if MRPT_VERSION>=0x199
59  Mat cvImg = temp_img.asCvMatRef();
60 #else
61  Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
62 #endif
63  cv_bridge::CvImage img_bridge;
64  img_bridge =
65  CvImage(left.header, sensor_msgs::image_encodings::BGR8, cvImg);
66  img_bridge.toImageMsg(left);
67  left.encoding = "bgr8";
68  left.header = msg_header;
69  left.height = (int)obj.imageLeft.getHeight();
70  left.width = (int)obj.imageRight.getWidth();
71 
73  CImage temp_img2 = obj.imageRight;
74 #if MRPT_VERSION>=0x199
75  Mat cvImg2 = temp_img2.asCvMatRef();
76 #else
77  Mat cvImg2 = cv::cvarrToMat(temp_img2.getAs<IplImage>());
78 #endif
79  cv_bridge::CvImage img_bridge2;
80  img_bridge2 =
81  CvImage(right.header, sensor_msgs::image_encodings::BGR8, cvImg2);
82  img_bridge2.toImageMsg(right);
83  right.encoding = "bgr8";
84  right.header = msg_header;
85  right.height = (int)obj.imageLeft.getHeight();
86  right.width = (int)obj.imageRight.getWidth();
87 
88  if (obj.hasImageDisparity)
89  {
90  CImage temp_disp = obj.imageDisparity;
91 #if MRPT_VERSION>=0x199
92  Mat cvImg3 = temp_disp.asCvMatRef();
93 #else
94  Mat cvImg3 = cv::cvarrToMat(temp_disp.getAs<IplImage>());
95 #endif
96  cv_bridge::CvImage img_bridge3;
97  img_bridge3 = CvImage(
98  disparity.header, sensor_msgs::image_encodings::BGR8, cvImg3);
99  img_bridge3.toImageMsg(disparity.image);
100  disparity.image.encoding = "bgr8";
101  disparity.image.header = msg_header;
102  disparity.image.height = (int)obj.imageDisparity.getHeight();
103  disparity.image.width = (int)obj.imageDisparity.getWidth();
104  }
105  return true;
106 }
107 } // namespace stereo_image
108 } // namespace mrpt_bridge
109 
110 //
111 /*
112 std_msgs/Header header
113 uint32 height
114 uint32 width
115 string encoding
116 uint8 is_bigendian
117 uint32 step
118 uint8[] data
119  */
stereo_image.h
mrpt_bridge::GPS::mrpt2ros
bool mrpt2ros(const CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Definition: GPS.cpp:54
image_encodings.h
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
ros
ros.h
image.h
std_msgs::Header_
Definition: map.h:24
cv_bridge.h
cv_bridge::CvImage
mrpt::utils
Definition: map.h:52
sensor_msgs::image_encodings::BGR8
const std::string BGR8
cv_bridge
mrpt_bridge
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types.
Definition: include/mrpt_bridge/beacon.h:52
sensor_msgs


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Sun Mar 6 2022 03:48:10