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-2017, 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 
17 
18 
19 
20 #include "ros/ros.h"
21 #include "mrpt_bridge/image.h"
22 #include <opencv/highgui.h>
23 #include <cv_bridge/cv_bridge.h>
24 
25 #include <sensor_msgs/Image.h>
27 
28 #include <mrpt/version.h>
29 #if MRPT_VERSION>=0x199
30 using namespace mrpt::img;
31 #else
32 using namespace mrpt::utils;
33 #endif
34 
35 using namespace ros;
36 using namespace sensor_msgs;
37 using namespace cv;
38 using namespace cv_bridge;
39 
40 
41 namespace mrpt_bridge
42 {
43  namespace stereo_image
44  {
45  /*bool ros2mrpt(const sensor_msgs::Image &msg, CObservationImage &obj)
46  {
47  CvImage *frame1 = cv_bridge::toCvCopy(msg, "bgr8").get(); //CvShare(msg,"bgr8").image;
48 
49  }
50 */
51  /************************************************************************
52  * mrpt2ros *
53  ************************************************************************/
54  bool mrpt2ros(const CObservationStereoImages &obj,const std_msgs::Header &msg_header,
55  sensor_msgs::Image &left, sensor_msgs::Image &right,
56  stereo_msgs::DisparityImage &disparity)
57  {
58 
60  CImage temp_img = obj.imageLeft;
61  Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
62  cv_bridge::CvImage img_bridge;
63  img_bridge = CvImage(left.header, sensor_msgs::image_encodings::BGR8, cvImg);
64  img_bridge.toImageMsg(left);
65  left.encoding = "bgr8";
66  left.header = msg_header;
67  left.height = (int) obj.imageLeft.getHeight();
68  left.width = (int) obj.imageRight.getWidth();
69 
71  CImage temp_img2 = obj.imageRight;
72  Mat cvImg2 = cv::cvarrToMat(temp_img2.getAs<IplImage>());
73  cv_bridge::CvImage img_bridge2;
74  img_bridge2 = CvImage(right.header, sensor_msgs::image_encodings::BGR8, cvImg2);
75  img_bridge2.toImageMsg(right);
76  right.encoding = "bgr8";
77  right.header = msg_header;
78  right.height = (int) obj.imageLeft.getHeight();
79  right.width = (int) obj.imageRight.getWidth();
80 
81  if(obj.hasImageDisparity)
82  {
83  CImage temp_disp = obj.imageDisparity;
84  Mat cvImg3 = cv::cvarrToMat(temp_disp.getAs<IplImage>());
85  cv_bridge::CvImage img_bridge3;
86  img_bridge3 = CvImage(disparity.header, sensor_msgs::image_encodings::BGR8, cvImg3);
87  img_bridge3.toImageMsg(disparity.image);
88  disparity.image.encoding = "bgr8";
89  disparity.image.header = msg_header;
90  disparity.image.height = (int) obj.imageDisparity.getHeight();
91  disparity.image.width = (int) obj.imageDisparity.getWidth();
92  }
93  return true;
94  }
95  }
96 }
97 
98 //
99 /*
100 std_msgs/Header header
101 uint32 height
102 uint32 width
103 string encoding
104 uint8 is_bigendian
105 uint32 step
106 uint8[] data
107  */
bool mrpt2ros(const CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Definition: GPS.cpp:57
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...
sensor_msgs::ImagePtr toImageMsg() const


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Sat Apr 28 2018 02:49:17