USBCameraMonitor.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "USBCameraMonitor.h"
11 #include <iostream>
12 using namespace std;
13 
14 // Module specification
15 // <rtc-template block="module_spec">
16 static const char* usbcameramonitor_spec[] =
17  {
18  "implementation_id", "USBCameraMonitor",
19  "type_name", "USBCameraMonitor",
20  "description", "USB Camera Acquire component",
21  "version", "1.0",
22  "vendor", "Noriaki Ando, 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.image_height", "240",
30  "conf.default.image_width", "320",
31  ""
32  };
33 // </rtc-template>
34 
36  : RTC::DataFlowComponentBase(manager),
37  // <rtc-template block="initializer">
38  m_inIn("in", m_in),
39 
40  // </rtc-template>
41  dummy(0)
42 {
43  // Registration: InPort/OutPort/Service
44  // <rtc-template block="registration">
45  // Set InPort buffers
46  registerInPort("in", m_inIn);
47 
48  /* RTM-Win-113 add 20070404 SEC)T.Shimoji */
49  m_in.data = 0;
50  // m_inIn.write(m_in);
51 
52 
53  // Set OutPort buffer
54 
55  // Set service provider to Ports
56 
57  // Set service consumers to Ports
58 
59  // Set CORBA Service Ports
60 
61  // </rtc-template>
62 }
63 
65 {
66 }
67 
68 
70 {
71  bindParameter("image_height", m_img_height, "240");
72  bindParameter("image_width", m_img_width, "320");
73  return RTC::RTC_OK;
74 }
75 
76 /*
77  RTC::ReturnCode_t USBCameraMonitor::onFinalize()
78  {
79  //return RTC::OK;
80  return RTC::RTC_OK;
81  }
82 */
83 
84 /*
85  RTC::ReturnCode_t USBCameraMonitor::onStartup(RTC::UniqueId ec_id)
86  {
87  //return RTC::OK;
88  return RTC::RTC_OK;
89  }
90 */
91 
92 /*
93  RTC::ReturnCode_t USBCameraMonitor::onShutdown(RTC::UniqueId ec_id)
94  {
95  //return RTC::OK;
96  return RTC::RTC_OK;
97  }
98 */
99 
100 
102 {
103  m_img=cvCreateImage(cvSize(m_img_width,m_img_height),IPL_DEPTH_8U,3);
104 
105  //画像表示用ウィンドウの作成
106  cvNamedWindow("CaptureImage", CV_WINDOW_AUTOSIZE);
107 
108  std::cout << "m_img->nChannels :" << m_img->nChannels << std::endl;
109  std::cout << "m_img->width :" << m_img->width << std::endl;
110  std::cout << "m_img->height :" << m_img->height << std::endl;
111 
112  return RTC::RTC_OK;
113 }
114 
115 
116 
118 {
119  cvReleaseImage(&m_img);
120  //表示ウィンドウの消去
121  cvDestroyWindow("CaptureImage");
122  return RTC::RTC_OK;
123 }
124 
125 
126 
128 {
129  static coil::TimeValue tm_pre;
130  static int count = 0;
131 
132  if (!m_inIn.isNew())
133  {
134  return RTC::RTC_OK;
135  }
136 
137  m_inIn.read();
138  if (!(m_in.data.length() > 0))
139  {
140  return RTC::RTC_OK;
141  }
142 
143  memcpy(m_img->imageData,(void *)&(m_in.data[0]),m_in.data.length());
144 
145  //画像表示
146  cvShowImage("CaptureImage", m_img);
147 
148  cvWaitKey(1);
149  if (count > 100)
150  {
151  count = 0;
152  coil::TimeValue tm;
153  tm = coil::gettimeofday();
154  double sec(tm - tm_pre);
155  if (sec > 1.0 && sec < 1000.0)
156  {
157  std::cout << 100.0/sec << " [FPS]" << std::endl;
158  }
159  tm_pre = tm;
160  }
161  ++count;
162 
163  return RTC::RTC_OK;
164 }
165 
166 
167 /*
168  RTC::ReturnCode_t USBCameraMonitor::onAborting(RTC::UniqueId ec_id)
169  {
170  //return RTC::OK;
171  return RTC::RTC_OK;
172  }
173 */
174 
175 /*
176  RTC::ReturnCode_t USBCameraMonitor::onError(RTC::UniqueId ec_id)
177  {
178  //return RTC::OK;
179  return RTC::RTC_OK;
180  }
181 */
182 
183 /*
184  RTC::ReturnCode_t USBCameraMonitor::onReset(RTC::UniqueId ec_id)
185  {
186  //return RTC::OK;
187  return RTC::RTC_OK;
188  }
189 */
190 
191 /*
192  RTC::ReturnCode_t USBCameraMonitor::onStateUpdate(RTC::UniqueId ec_id)
193  {
194  //return RTC::OK;
195  return RTC::RTC_OK;
196  }
197 */
198 
199 /*
200  RTC::ReturnCode_t USBCameraMonitor::onRateChanged(RTC::UniqueId ec_id)
201  {
202  //return RTC::OK;
203  return RTC::RTC_OK;
204  }
205 */
206 
207 
208 
209 extern "C"
210 {
211 
213  {
215  manager->registerFactory(profile,
216  RTC::Create<USBCameraMonitor>,
217  RTC::Delete<USBCameraMonitor>);
218  }
219 
220 };
221 
222 
RT-Component.
DataFlowComponentBase class.
ReturnCode_t
Definition: doil.h:53
static const char * usbcameramonitor_spec[]
Manager class.
Definition: Manager.h:80
TimeValue class.
Definition: TimeValue.h:40
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
InPort< TimedOctetSeq > m_inIn
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
Setup for configuration parameters.
Definition: RTObject.h:2251
virtual RTC::ReturnCode_t onInitialize()
Callback function to initialize.
Class represents a set of properties.
Definition: Properties.h:101
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Callback function to deactivate.
&#39;hellow
void registerInPort(const char *name, InPortBase &inport)
[local interface] Register DataInPort
Definition: RTObject.cpp:1627
virtual bool isNew()
Check whether the data is newest.
Definition: InPort.h:225
USBCameraMonitor(RTC::Manager *manager)
TimedOctetSeq m_in
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433
bool read()
Readout the value from DataPort.
Definition: InPort.h:378
void USBCameraMonitorInit(RTC::Manager *manager)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Callback function to activate.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:56