18 "implementation_id",
"USBCameraAcquire",
19 "type_name",
"USBCameraAcquire",
20 "description",
"USB Camera Acquire component",
22 "vendor",
"Noriaki Ando, AIST",
23 "category",
"example",
24 "activity_type",
"DataFlowComponent",
27 "lang_type",
"compile",
35 m_outOut(
"out", m_out),
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;
111 static int count = 0;
112 IplImage* cam_frame = NULL;
115 if(NULL == cam_frame)
117 std::cout <<
"画像がキャプチャできません!!" << std::endl;
121 IplImage* frame = cvCreateImage(cvGetSize(cam_frame), 8, 3);
123 if(cam_frame ->origin == IPL_ORIGIN_TL)
124 cvCopy(cam_frame, frame);
126 cvFlip(cam_frame, frame);
128 int len = frame->nChannels * frame->width * frame->height;
130 m_out.data.length(len);
131 memcpy((
void *)&(
m_out.data[0]),frame->imageData,len);
132 cvReleaseImage(&frame);
141 double sec(tm - tm_pre);
142 if (sec > 1.0 && sec < 1000.0)
144 std::cout << 100/sec <<
" [FPS]" << std::endl;
199 RTC::Create<USBCameraAcquire>,
200 RTC::Delete<USBCameraAcquire>);
virtual RTC::ReturnCode_t onFinalize()
Callback function to finalize.
#define RTC_ERROR(fmt)
Error log output macro.
DataFlowComponentBase class.
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Callback function to activate.
static const char * usbcameraacquire_spec[]
void USBCameraAcquireInit(RTC::Manager *manager)
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.
ExecutionContextHandle_t UniqueId
OutPort< TimedOctetSeq > m_outOut
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
USB Camera Acquire component.
Class represents a set of properties.
USBCameraAcquire(RTC::Manager *manager)
virtual bool write(DataType &value)
Write data.
void registerOutPort(const char *name, OutPortBase &outport)
[local interface] Register DataOutPort
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.