USBCameraAcquire.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "USBCameraAcquire.h"
11 #include <iostream>
12 using namespace std;
13 
14 // Module specification
15 // <rtc-template block="module_spec">
16 static const char* usbcameraacquire_spec[] =
17  {
18  "implementation_id", "USBCameraAcquire",
19  "type_name", "USBCameraAcquire",
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  ""
29  };
30 // </rtc-template>
31 
33  : RTC::DataFlowComponentBase(manager),
34  // <rtc-template block="initializer">
35  m_outOut("out", m_out),
36  // </rtc-template>
37  dummy(0)
38 {
39  // Registration: InPort/OutPort/Service
40  // <rtc-template block="registration">
41  // Set InPort buffers
42 
43  // Set OutPort buffer
44  registerOutPort("out", m_outOut);
45  //registerOutPort("OutPortPicture", mOutPortPicture);
46 
47  // Set service provider to Ports
48 
49  // Set service consumers to Ports
50 
51  // Set CORBA Service Ports
52 
53  // </rtc-template>
54 
55 }
56 
58 {
59 }
60 /*
61  RTC::ReturnCode_t USBCameraAcquire::onInitialize()
62  {
63 
64  return RTC::RTC_OK;
65  }
66 */
67 
69 {
70  return RTC::RTC_OK;
71 }
72 
73 /*
74  RTC::ReturnCode_t USBCameraAcquire::onStartup(RTC::UniqueId ec_id)
75  {
76 
77  }
78 */
79 
80 /*
81  RTC::ReturnCode_t USBCameraAcquire::onShutdown(RTC::UniqueId ec_id)
82  {
83  return RTC::OK;
84  }
85 */
86 
88 {
89  //カメラデバイスの探索 if(NULL==(m_capture = cvCreateCameraCapture(CV_CAP_ANY))){ cout<<"カメラがみつかりません"<<endl; return RTC::RTC_ERROR; } return RTC::RTC_OK; } RTC::ReturnCode_t USBCameraAcquire::onDeactivated(RTC::UniqueId ec_id) { //カメラ用メモリの解放 cvReleaseCapture(&m_capture); return RTC::RTC_OK; } RTC::ReturnCode_t USBCameraAcquire::onExecute(RTC::UniqueId ec_id) { static coil::TimeValue tm_pre; static int count = 0; IplImage* cam_frame = NULL; cam_frame = cvQueryFrame(m_capture); if(NULL == cam_frame) { std::cout << "画像がキャプチャできません!!" << std::endl; return RTC::RTC_ERROR; } IplImage* frame = cvCreateImage(cvGetSize(cam_frame), 8, 3); if(cam_frame ->origin == IPL_ORIGIN_TL) cvCopy(cam_frame, frame); else cvFlip(cam_frame, frame); int len = frame->nChannels * frame->width * frame->height; m_out.data.length(len); memcpy((void *)&(m_out.data[0]),frame->imageData,len); cvReleaseImage(&frame); m_outOut.write(); if (count > 100) { count = 0; coil::TimeValue tm; tm = coil::gettimeofday(); double sec(tm - tm_pre); if (sec > 1.0 && sec < 1000.0) { std::cout << 100/sec << " [FPS]" << std::endl; } tm_pre = tm; } ++count; return RTC::RTC_OK; } /* RTC::ReturnCode_t USBCameraAcquire::onAborting(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onError(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onReset(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onStateUpdate(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onRateChanged(RTC::UniqueId ec_id) { return RTC::OK; } */ extern "C" { void USBCameraAcquireInit(RTC::Manager* manager) { coil::Properties profile(usbcameraacquire_spec); manager->registerFactory(profile, RTC::Create<USBCameraAcquire>, RTC::Delete<USBCameraAcquire>); } };
90  if(NULL==(m_capture = cvCreateCameraCapture(CV_CAP_ANY))){
91  cout<<"カメラがみつかりません<<endl; return RTC::RTC_ERROR; } return RTC::RTC_OK; } RTC::ReturnCode_t USBCameraAcquire::onDeactivated(RTC::UniqueId ec_id) { //カメラ用メモリの解放 cvReleaseCapture(&m_capture); return RTC::RTC_OK; } RTC::ReturnCode_t USBCameraAcquire::onExecute(RTC::UniqueId ec_id) { static coil::TimeValue tm_pre; static int count = 0; IplImage* cam_frame = NULL; cam_frame = cvQueryFrame(m_capture); if(NULL == cam_frame) { std::cout << "画像がキャプチャできません!!" << std::endl; return RTC::RTC_ERROR; } IplImage* frame = cvCreateImage(cvGetSize(cam_frame), 8, 3); if(cam_frame ->origin == IPL_ORIGIN_TL) cvCopy(cam_frame, frame); else cvFlip(cam_frame, frame); int len = frame->nChannels * frame->width * frame->height; m_out.data.length(len); memcpy((void *)&(m_out.data[0]),frame->imageData,len); cvReleaseImage(&frame); m_outOut.write(); if (count > 100) { count = 0; coil::TimeValue tm; tm = coil::gettimeofday(); double sec(tm - tm_pre); if (sec > 1.0 && sec < 1000.0) { std::cout << 100/sec << " [FPS]" << std::endl; } tm_pre = tm; } ++count; return RTC::RTC_OK; } /* RTC::ReturnCode_t USBCameraAcquire::onAborting(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onError(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onReset(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onStateUpdate(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onRateChanged(RTC::UniqueId ec_id) { return RTC::OK; } */ extern "C" { void USBCameraAcquireInit(RTC::Manager* manager) { coil::Properties profile(usbcameraacquire_spec); manager->registerFactory(profile, RTC::Create<USBCameraAcquire>, RTC::Delete<USBCameraAcquire>); } }; "<<endl;
92  return RTC::RTC_ERROR;
93  }
94  return RTC::RTC_OK;
95 }
96 
97 
98 
100 {
101  //カメラ用メモリの解放 cvReleaseCapture(&m_capture); return RTC::RTC_OK; } RTC::ReturnCode_t USBCameraAcquire::onExecute(RTC::UniqueId ec_id) { static coil::TimeValue tm_pre; static int count = 0; IplImage* cam_frame = NULL; cam_frame = cvQueryFrame(m_capture); if(NULL == cam_frame) { std::cout << "画像がキャプチャできません!!" << std::endl; return RTC::RTC_ERROR; } IplImage* frame = cvCreateImage(cvGetSize(cam_frame), 8, 3); if(cam_frame ->origin == IPL_ORIGIN_TL) cvCopy(cam_frame, frame); else cvFlip(cam_frame, frame); int len = frame->nChannels * frame->width * frame->height; m_out.data.length(len); memcpy((void *)&(m_out.data[0]),frame->imageData,len); cvReleaseImage(&frame); m_outOut.write(); if (count > 100) { count = 0; coil::TimeValue tm; tm = coil::gettimeofday(); double sec(tm - tm_pre); if (sec > 1.0 && sec < 1000.0) { std::cout << 100/sec << " [FPS]" << std::endl; } tm_pre = tm; } ++count; return RTC::RTC_OK; } /* RTC::ReturnCode_t USBCameraAcquire::onAborting(RTC::UniqueId ec_id) { return RTC::RTC_OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onError(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onReset(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onStateUpdate(RTC::UniqueId ec_id) { return RTC::OK; } */ /* RTC::ReturnCode_t USBCameraAcquire::onRateChanged(RTC::UniqueId ec_id) { return RTC::OK; } */ extern "C" { void USBCameraAcquireInit(RTC::Manager* manager) { coil::Properties profile(usbcameraacquire_spec); manager->registerFactory(profile, RTC::Create<USBCameraAcquire>, RTC::Delete<USBCameraAcquire>); } };
102  cvReleaseCapture(&m_capture);
103  return RTC::RTC_OK;
104 }
105 
106 
107 
109 {
110  static coil::TimeValue tm_pre;
111  static int count = 0;
112  IplImage* cam_frame = NULL;
113 
114  cam_frame = cvQueryFrame(m_capture);
115  if(NULL == cam_frame)
116  {
117  std::cout << "画像がキャプチャできません!!" << std::endl;
118  return RTC::RTC_ERROR;
119  }
120 
121  IplImage* frame = cvCreateImage(cvGetSize(cam_frame), 8, 3);
122 
123  if(cam_frame ->origin == IPL_ORIGIN_TL)
124  cvCopy(cam_frame, frame);
125  else
126  cvFlip(cam_frame, frame);
127 
128  int len = frame->nChannels * frame->width * frame->height;
129 
130  m_out.data.length(len);
131  memcpy((void *)&(m_out.data[0]),frame->imageData,len);
132  cvReleaseImage(&frame);
133 
134  m_outOut.write();
135 
136  if (count > 100)
137  {
138  count = 0;
139  coil::TimeValue tm;
140  tm = coil::gettimeofday();
141  double sec(tm - tm_pre);
142  if (sec > 1.0 && sec < 1000.0)
143  {
144  std::cout << 100/sec << " [FPS]" << std::endl;
145  }
146  tm_pre = tm;
147  }
148  ++count;
149 
150  return RTC::RTC_OK;
151 }
152 
153 
154 /*
155  RTC::ReturnCode_t USBCameraAcquire::onAborting(RTC::UniqueId ec_id)
156  {
157 
158  return RTC::RTC_OK;
159  }
160 */
161 
162 /*
163  RTC::ReturnCode_t USBCameraAcquire::onError(RTC::UniqueId ec_id)
164  {
165  return RTC::OK;
166  }
167 */
168 
169 /*
170  RTC::ReturnCode_t USBCameraAcquire::onReset(RTC::UniqueId ec_id)
171  {
172  return RTC::OK;
173  }
174 */
175 
176 /*
177  RTC::ReturnCode_t USBCameraAcquire::onStateUpdate(RTC::UniqueId ec_id)
178  {
179  return RTC::OK;
180  }
181 */
182 
183 /*
184  RTC::ReturnCode_t USBCameraAcquire::onRateChanged(RTC::UniqueId ec_id)
185  {
186  return RTC::OK;
187  }
188 */
189 
190 
191 
192 extern "C"
193 {
194 
196  {
198  manager->registerFactory(profile,
199  RTC::Create<USBCameraAcquire>,
200  RTC::Delete<USBCameraAcquire>);
201  }
202 
203 };
204 
205 
virtual RTC::ReturnCode_t onFinalize()
Callback function to finalize.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
RT-Component.
DataFlowComponentBase class.
ReturnCode_t
Definition: doil.h:53
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Callback function to activate.
static const char * usbcameraacquire_spec[]
CvCapture * m_capture
Manager class.
Definition: Manager.h:80
void USBCameraAcquireInit(RTC::Manager *manager)
TimeValue class.
Definition: TimeValue.h:40
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Callback function to deactivate.
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
ExecutionContextHandle_t UniqueId
OutPort< TimedOctetSeq > m_outOut
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
TimedOctetSeq m_out
USB Camera Acquire component.
Class represents a set of properties.
Definition: Properties.h:101
USBCameraAcquire(RTC::Manager *manager)
virtual bool write(DataType &value)
Write data.
Definition: OutPort.h:203
void registerOutPort(const char *name, OutPortBase &outport)
[local interface] Register DataOutPort
Definition: RTObject.cpp:1668
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:01