CameraImageLoader.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <cv.h>
11 #include <highgui.h>
12 #include "CameraImageLoader.h"
13 
14 // Module specification
15 // <rtc-template block="module_spec">
16 static const char* spec[] =
17  {
18  "implementation_id", "CameraImageLoader",
19  "type_name", "CameraImageLoader",
20  "description", "camera image loader",
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 
30  ""
31  };
32 // </rtc-template>
33 
35  : RTC::DataFlowComponentBase(manager),
36  // <rtc-template block="initializer">
37  m_imageOut("image", m_image),
38  // </rtc-template>
39  dummy(0)
40 {
41 }
42 
44 {
45 }
46 
47 
48 
50 {
51  //std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
52  // <rtc-template block="bind_config">
53  // Bind variables and configuration variable
54 
55  // </rtc-template>
56 
57  // Registration: InPort/OutPort/Service
58  // <rtc-template block="registration">
59  // Set InPort buffers
60 
61  // Set OutPort buffer
62  addOutPort("image", m_imageOut);
63 
64  // Set service provider to Ports
65 
66  // Set service consumers to Ports
67 
68  // Set CORBA Service Ports
69 
70  // </rtc-template>
71 
73 
74  return RTC::RTC_OK;
75 }
76 
77 
78 
79 /*
80 RTC::ReturnCode_t CameraImageLoader::onFinalize()
81 {
82  return RTC::RTC_OK;
83 }
84 */
85 
86 /*
87 RTC::ReturnCode_t CameraImageLoader::onStartup(RTC::UniqueId ec_id)
88 {
89  return RTC::RTC_OK;
90 }
91 */
92 
93 /*
94 RTC::ReturnCode_t CameraImageLoader::onShutdown(RTC::UniqueId ec_id)
95 {
96  return RTC::RTC_OK;
97 }
98 */
99 
101 {
102  std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
103  return RTC::RTC_OK;
104 }
105 
107 {
108  std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
109  return RTC::RTC_OK;
110 }
111 
113 {
114  //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
115  std::cerr << "image filename: " << std::flush;
116  std::string filename;
117  std::cin >> filename;
118 
119  IplImage *image = cvLoadImage(filename.c_str(), CV_LOAD_IMAGE_COLOR);
120  if (!image) {
121  std::cerr << m_profile.instance_name << ": failed to load("
122  << filename << ")" << std::endl;
123  return RTC::RTC_OK;
124  }
125 
126  m_image.data.image.width = image->width;
127  m_image.data.image.height = image->height;
128  m_image.data.image.raw_data.length(image->imageSize);
129  switch(image->nChannels){
130  case 3:
131  m_image.data.image.format = Img::CF_RGB;
132  {
133  // BGR -> RGB
134  char *src;
135  unsigned char *dst = m_image.data.image.raw_data.get_buffer();
136  for (int i=0; i<image->height; i++){
137  for (int j=0; j<image->width; j++){
138  src = image->imageData + image->widthStep*i + j*3;
139  dst[2] = src[0];
140  dst[1] = src[1];
141  dst[0] = src[2];
142  dst += 3;
143  }
144  }
145  break;
146  }
147  case 1:
148  m_image.data.image.format = Img::CF_GRAY;
149  memcpy(m_image.data.image.raw_data.get_buffer(),
150  image->imageData,
151  m_image.data.image.raw_data.length());
152  break;
153  default:
154  break;
155  }
156 
157  cvReleaseImage (&image);
158 
159  m_imageOut.write();
160 
161  return RTC::RTC_OK;
162 }
163 
164 /*
165 RTC::ReturnCode_t CameraImageLoader::onAborting(RTC::UniqueId ec_id)
166 {
167  return RTC::RTC_OK;
168 }
169 */
170 
171 /*
172 RTC::ReturnCode_t CameraImageLoader::onError(RTC::UniqueId ec_id)
173 {
174  return RTC::RTC_OK;
175 }
176 */
177 
178 /*
179 RTC::ReturnCode_t CameraImageLoader::onReset(RTC::UniqueId ec_id)
180 {
181  return RTC::RTC_OK;
182 }
183 */
184 
185 /*
186 RTC::ReturnCode_t CameraImageLoader::onStateUpdate(RTC::UniqueId ec_id)
187 {
188  return RTC::RTC_OK;
189 }
190 */
191 
192 /*
193 RTC::ReturnCode_t CameraImageLoader::onRateChanged(RTC::UniqueId ec_id)
194 {
195  return RTC::RTC_OK;
196 }
197 */
198 
199 
200 
201 extern "C"
202 {
203 
205  {
207  manager->registerFactory(profile,
208  RTC::Create<CameraImageLoader>,
209  RTC::Delete<CameraImageLoader>);
210  }
211 
212 };
213 
214 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
void CameraImageLoaderInit(RTC::Manager *manager)
char * filename
static const char * spec[]
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
png_uint_32 i
virtual ~CameraImageLoader()
Destructor.
coil::Properties & getProperties()
png_bytepp image
bool addOutPort(const char *name, OutPortBase &outport)
camera image loader
ExecutionContextHandle_t UniqueId
def j(str, encoding="cp932")
CameraImageLoader(RTC::Manager *manager)
Constructor.
OutPort< Img::TimedCameraImage > m_imageOut
virtual RTC::ReturnCode_t onInitialize()
prop
virtual bool write(DataType &value)
Img::TimedCameraImage m_image
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:49