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: 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 namespace mrpt_bridge
37 {
38 namespace image
39 {
40 bool ros2mrpt(const sensor_msgs::Image& msg, CObservationImage& obj)
41 {
42  CvImage* frame1 =
43  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(
55  const CObservationImage& obj, const std_msgs::Header& msg_header,
56  sensor_msgs::Image& msg)
57 {
58  CImage temp_img = obj.image;
59 #if MRPT_VERSION>=0x199
60  Mat cvImg = temp_img.asCvMatRef();
61 #else
62  Mat cvImg = cv::cvarrToMat(temp_img.getAs<IplImage>());
63 #endif
64 
65  cv_bridge::CvImage img_bridge;
66 
67  img_bridge = CvImage(msg.header, sensor_msgs::image_encodings::BGR8, cvImg);
68  img_bridge.toImageMsg(msg);
69 
70  msg.encoding = "bgr8";
71  msg.header = msg_header;
72  msg.height = (int)obj.image.getHeight();
73  msg.width = (int)obj.image.getWidth();
74 
75  return true;
76 }
77 } // namespace image
78 } // namespace mrpt_bridge
79 
80 //
81 /*
82 std_msgs/Header header
83 uint32 height
84 uint32 width
85 string encoding
86 uint8 is_bigendian
87 uint32 step
88 uint8[] data
89  */
bool mrpt2ros(const CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Definition: GPS.cpp:54
void loadFromIplImage(void *iplImage)
const T * getAs() const
File includes methods for converting CNetworkOfPoses*DInf <=> NetworkOfPoses message types...
GLhandleARB obj
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
GLenum GLsizei GLenum GLenum const GLvoid * image
size_t getWidth() const MRPT_OVERRIDE
mrpt::utils::CImage image
sensor_msgs::ImagePtr toImageMsg() const
size_t getHeight() const MRPT_OVERRIDE
bool ros2mrpt(const sensor_msgs::NavSatFix &msg, CObservationGPS &obj)
Definition: GPS.cpp:23


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Fri Feb 28 2020 03:22:14