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