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  */
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
cv_bridge::toCvCopy
CvImagePtr toCvCopy(const sensor_msgs::CompressedImage &source, const std::string &encoding=std::string())
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::GPS::ros2mrpt
bool ros2mrpt(const sensor_msgs::NavSatFix &msg, CObservationGPS &obj)
Definition: GPS.cpp:23
cv_bridge::CvImage::image
cv::Mat image


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