RotateImage.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <highgui.h>
11 #include "RotateImage.h"
12 
13 // Module specification
14 // <rtc-template block="module_spec">
15 static const char* spec[] =
16  {
17  "implementation_id", "RotateImage",
18  "type_name", "RotateImage",
19  "description", "rotate 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.angle", "0.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_rotatedOut("rotated", m_rotated),
39  // </rtc-template>
40  m_angle(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 RotateImage::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("angle", m_angle, "0.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("rotated", m_rotatedOut);
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 RotateImage::onFinalize()
88 {
89  return RTC::RTC_OK;
90 }
91 */
92 
93 /*
94 RTC::ReturnCode_t RotateImage::onStartup(RTC::UniqueId ec_id)
95 {
96  return RTC::RTC_OK;
97 }
98 */
99 
100 /*
101 RTC::ReturnCode_t RotateImage::onShutdown(RTC::UniqueId ec_id)
102 {
103  return RTC::RTC_OK;
104 }
105 */
106 
107 RTC::ReturnCode_t RotateImage::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 RotateImage::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 
129  if (m_src && (m_src->width != idat.width
130  || m_src->height != idat.height)){
131  cvReleaseImage(&m_src);
132  cvReleaseImage(&m_dst);
133  m_src = m_dst = NULL;
134  }
135  if (!m_src){
136  m_src = cvCreateImage(cvSize(idat.width, idat.height),
137  IPL_DEPTH_8U, nchannels);
138  m_dst = cvCreateImage(cvSize(idat.width, idat.height),
139  IPL_DEPTH_8U, nchannels);
140  m_rotated.data.image.width = idat.width;
141  m_rotated.data.image.height = idat.height;
142  m_rotated.data.image.format = idat.format;
143  m_rotated.data.image.raw_data.length(idat.width*idat.height*nchannels);
144  }
145 
146  memcpy(m_src->imageData, idat.raw_data.get_buffer(),
147  idat.raw_data.length());
148 
149  CvMat *rotationMat = cvCreateMat(2,3, CV_32FC1);
150  cv2DRotationMatrix(cvPoint2D32f(idat.width/2, idat.height/2),
151  m_angle*180/M_PI, 1, rotationMat);
152  cvWarpAffine(m_src, m_dst, rotationMat);
153  cvReleaseMat(&rotationMat);
154 
155  memcpy(m_rotated.data.image.raw_data.get_buffer(),
156  m_dst->imageData, m_rotated.data.image.raw_data.length());
157 
159  }
160  return RTC::RTC_OK;
161 }
162 
163 /*
164 RTC::ReturnCode_t RotateImage::onAborting(RTC::UniqueId ec_id)
165 {
166  return RTC::RTC_OK;
167 }
168 */
169 
170 /*
171 RTC::ReturnCode_t RotateImage::onError(RTC::UniqueId ec_id)
172 {
173  return RTC::RTC_OK;
174 }
175 */
176 
177 /*
178 RTC::ReturnCode_t RotateImage::onReset(RTC::UniqueId ec_id)
179 {
180  return RTC::RTC_OK;
181 }
182 */
183 
184 /*
185 RTC::ReturnCode_t RotateImage::onStateUpdate(RTC::UniqueId ec_id)
186 {
187  return RTC::RTC_OK;
188 }
189 */
190 
191 /*
192 RTC::ReturnCode_t RotateImage::onRateChanged(RTC::UniqueId ec_id)
193 {
194  return RTC::RTC_OK;
195 }
196 */
197 
198 
199 
200 extern "C"
201 {
202 
204  {
206  manager->registerFactory(profile,
207  RTC::Create<RotateImage>,
208  RTC::Delete<RotateImage>);
209  }
210 
211 };
212 
213 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
RotateImage(RTC::Manager *manager)
Constructor.
Definition: RotateImage.cpp:34
InPort< Img::TimedCameraImage > m_originalIn
Definition: RotateImage.h:111
virtual RTC::ReturnCode_t onInitialize()
Definition: RotateImage.cpp:54
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Img::TimedCameraImage m_original
Definition: RotateImage.h:107
bool addOutPort(const char *name, OutPortBase &outport)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
static const char * spec[]
Definition: RotateImage.cpp:15
ExecutionContextHandle_t UniqueId
IplImage * m_dst
Definition: RotateImage.h:140
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
virtual ~RotateImage()
Destructor.
Definition: RotateImage.cpp:45
double m_angle
Definition: RotateImage.h:139
OutPort< Img::TimedCameraImage > m_rotatedOut
Definition: RotateImage.h:119
IplImage * m_src
Definition: RotateImage.h:140
#define M_PI
Img::TimedCameraImage m_rotated
Definition: RotateImage.h:115
void RotateImageInit(RTC::Manager *manager)
virtual bool isNew()
virtual bool write(DataType &value)
rotate image component
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)


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