RGB2Gray.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <opencv2/highgui/highgui.hpp>
11 #include <opencv2/imgproc/imgproc.hpp>
12 #include <opencv2/core/core.hpp>
13 #include "RGB2Gray.h"
14 
15 // Module specification
16 // <rtc-template block="module_spec">
17 static const char* jpegdecoder_spec[] =
18  {
19  "implementation_id", "RGB2Gray",
20  "type_name", "RGB2Gray",
21  "description", "rgb2gray component",
22  "version", HRPSYS_PACKAGE_VERSION,
23  "vendor", "AIST",
24  "category", "example",
25  "activity_type", "DataFlowComponent",
26  "max_instance", "10",
27  "language", "C++",
28  "lang_type", "compile",
29  // Configuration variables
30 
31  ""
32  };
33 // </rtc-template>
34 
36  : RTC::DataFlowComponentBase(manager),
37  // <rtc-template block="initializer">
38  m_rgbIn("rgb", m_rgb),
39  m_grayOut("gray", m_gray),
40  // </rtc-template>
41  dummy(0)
42 {
43 }
44 
46 {
47 }
48 
49 
50 
51 RTC::ReturnCode_t RGB2Gray::onInitialize()
52 {
53  std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
54  // <rtc-template block="bind_config">
55  // Bind variables and configuration variable
56 
57  // </rtc-template>
58 
59  // Registration: InPort/OutPort/Service
60  // <rtc-template block="registration">
61  // Set InPort buffers
62  addInPort("rgbIn", m_rgbIn);
63 
64  // Set OutPort buffer
65  addOutPort("grayOut", m_grayOut);
66 
67  // Set service provider to Ports
68 
69  // Set service consumers to Ports
70 
71  // Set CORBA Service Ports
72 
73  // </rtc-template>
74 
75  //RTC::Properties& prop = getProperties();
76 
77  return RTC::RTC_OK;
78 }
79 
80 
81 
82 /*
83 RTC::ReturnCode_t RGB2Gray::onFinalize()
84 {
85  return RTC::RTC_OK;
86 }
87 */
88 
89 /*
90 RTC::ReturnCode_t RGB2Gray::onStartup(RTC::UniqueId ec_id)
91 {
92  return RTC::RTC_OK;
93 }
94 */
95 
96 /*
97 RTC::ReturnCode_t RGB2Gray::onShutdown(RTC::UniqueId ec_id)
98 {
99  return RTC::RTC_OK;
100 }
101 */
102 
103 RTC::ReturnCode_t RGB2Gray::onActivated(RTC::UniqueId ec_id)
104 {
105  std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
106  return RTC::RTC_OK;
107 }
108 
109 RTC::ReturnCode_t RGB2Gray::onDeactivated(RTC::UniqueId ec_id)
110 {
111  std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
112  return RTC::RTC_OK;
113 }
114 
115 RTC::ReturnCode_t RGB2Gray::onExecute(RTC::UniqueId ec_id)
116 {
117  //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
118  if (m_rgbIn.isNew()){
119  m_rgbIn.read();
120 
121  Img::ImageData& idat = m_rgb.data.image;
122 
123  cv::Mat src(idat.height, idat.width, CV_8UC3,
124  idat.raw_data.get_buffer());
125  cv::Mat dst;
126  cv::cvtColor(src, dst, CV_RGB2GRAY);
127 
128  m_gray.data.image.width = idat.width;
129  m_gray.data.image.height = idat.height;
130  m_gray.data.image.format = Img::CF_GRAY;
131  m_gray.data.image.raw_data.length(idat.width*idat.height);
132  memcpy(m_gray.data.image.raw_data.get_buffer(),
133  dst.data, idat.width*idat.height);
134 
135  m_grayOut.write();
136  }
137  return RTC::RTC_OK;
138 }
139 
140 /*
141 RTC::ReturnCode_t RGB2Gray::onAborting(RTC::UniqueId ec_id)
142 {
143  return RTC::RTC_OK;
144 }
145 */
146 
147 /*
148 RTC::ReturnCode_t RGB2Gray::onError(RTC::UniqueId ec_id)
149 {
150  return RTC::RTC_OK;
151 }
152 */
153 
154 /*
155 RTC::ReturnCode_t RGB2Gray::onReset(RTC::UniqueId ec_id)
156 {
157  return RTC::RTC_OK;
158 }
159 */
160 
161 /*
162 RTC::ReturnCode_t RGB2Gray::onStateUpdate(RTC::UniqueId ec_id)
163 {
164  return RTC::RTC_OK;
165 }
166 */
167 
168 /*
169 RTC::ReturnCode_t RGB2Gray::onRateChanged(RTC::UniqueId ec_id)
170 {
171  return RTC::RTC_OK;
172 }
173 */
174 
175 
176 
177 extern "C"
178 {
179 
180  void RGB2GrayInit(RTC::Manager* manager)
181  {
183  manager->registerFactory(profile,
184  RTC::Create<RGB2Gray>,
185  RTC::Delete<RGB2Gray>);
186  }
187 
188 };
189 
190 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
Img::TimedCameraImage m_rgb
Definition: RGB2Gray.h:106
InPort< Img::TimedCameraImage > m_rgbIn
Definition: RGB2Gray.h:110
static const char * jpegdecoder_spec[]
Definition: RGB2Gray.cpp:17
virtual ~RGB2Gray()
Destructor.
Definition: RGB2Gray.cpp:45
RGB2Gray(RTC::Manager *manager)
Constructor.
Definition: RGB2Gray.cpp:35
void RGB2GrayInit(RTC::Manager *manager)
Definition: RGB2Gray.cpp:180
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Definition: RGB2Gray.cpp:115
bool addOutPort(const char *name, OutPortBase &outport)
virtual RTC::ReturnCode_t onInitialize()
Definition: RGB2Gray.cpp:51
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Definition: RGB2Gray.cpp:103
ExecutionContextHandle_t UniqueId
OutPort< Img::TimedCameraImage > m_grayOut
Definition: RGB2Gray.h:118
jpeg encoder component
virtual bool isNew()
virtual bool write(DataType &value)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Definition: RGB2Gray.cpp:109
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Img::TimedCameraImage m_gray
Definition: RGB2Gray.h:114


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51