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