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


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