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: image.cpp
13  AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
14  ---------------------------------------------------------------*/
15 
16 #include "ros/ros.h"
17 #include "mrpt_bridge/image.h"
18 #include <opencv/highgui.h>
19 #include <cv_bridge/cv_bridge.h>
20 
21 #include <sensor_msgs/Image.h>
23 
24 #include <mrpt/version.h>
25 #if MRPT_VERSION>=0x199
26 using namespace mrpt::img;
27 #else
28 using namespace mrpt::utils;
29 #endif
30 
31 using namespace ros;
32 using namespace sensor_msgs;
33 using namespace cv;
34 using namespace cv_bridge;
35 
36 
37 namespace mrpt_bridge
38 {
39  namespace image
40  {
41  bool ros2mrpt(const sensor_msgs::Image &msg, CObservationImage &obj)
42  {
43  CvImage *frame1 = cv_bridge::toCvCopy(msg, "bgr8").get(); //CvShare(msg,"bgr8").image;
44  if (!frame1) return false;
45  IplImage ipl = frame1->image;
46  obj.image.loadFromIplImage(&ipl);
47 
48  return true;
49  }
50 
51  /************************************************************************
52  * mrpt2ros *
53  ************************************************************************/
54  bool mrpt2ros(const CObservationImage &obj, const std_msgs::Header &msg_header, sensor_msgs::Image &msg)
55  {
56  CImage temp_img = obj.image;
57  Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
58 
59  cv_bridge::CvImage img_bridge;
60  sensor_msgs::Image img_msg;
61 
62  img_bridge = CvImage(msg.header, sensor_msgs::image_encodings::BGR8, cvImg);
63  img_bridge.toImageMsg(msg);
64 
65  msg.encoding = "bgr8";
66  msg.header = msg_header;
67  msg.height = (int) obj.image.getHeight();
68  msg.width = (int) obj.image.getWidth();
69 
70  return true;
71  }
72  }
73 }
74 
75 //
76 /*
77 std_msgs/Header header
78 uint32 height
79 uint32 width
80 string encoding
81 uint8 is_bigendian
82 uint32 step
83 uint8[] data
84  */
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...
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
sensor_msgs::ImagePtr toImageMsg() const
bool ros2mrpt(const sensor_msgs::NavSatFix &msg, CObservationGPS &obj)
Definition: GPS.cpp:24


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