USBCameraMonitor.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "USBCameraMonitor.h"
00011 #include <iostream>
00012 using namespace std;
00013 
00014 // Module specification
00015 // <rtc-template block="module_spec">
00016 static const char* usbcameramonitor_spec[] =
00017   {
00018     "implementation_id", "USBCameraMonitor",
00019     "type_name",         "USBCameraMonitor",
00020     "description",       "USB Camera Acquire component",
00021     "version",           "1.0",
00022     "vendor",            "Noriaki Ando, AIST",
00023     "category",          "example",
00024     "activity_type",     "DataFlowComponent",
00025     "max_instance",      "10",
00026     "language",          "C++",
00027     "lang_type",         "compile",
00028     // Configuration variables
00029     "conf.default.image_height", "240",
00030     "conf.default.image_width", "320",
00031     ""
00032   };
00033 // </rtc-template>
00034 
00035 USBCameraMonitor::USBCameraMonitor(RTC::Manager* manager)
00036   : RTC::DataFlowComponentBase(manager),
00037     // <rtc-template block="initializer">
00038     m_inIn("in", m_in),
00039     
00040     // </rtc-template>
00041     dummy(0)
00042 {
00043   // Registration: InPort/OutPort/Service
00044   // <rtc-template block="registration">
00045   // Set InPort buffers
00046   registerInPort("in", m_inIn);
00047   
00048   /* RTM-Win-113 add 20070404 SEC)T.Shimoji */
00049   m_in.data = 0;
00050   //  m_inIn.write(m_in);
00051   
00052   
00053   // Set OutPort buffer
00054   
00055   // Set service provider to Ports
00056   
00057   // Set service consumers to Ports
00058   
00059   // Set CORBA Service Ports
00060   
00061   // </rtc-template>
00062 }
00063 
00064 USBCameraMonitor::~USBCameraMonitor()
00065 {
00066 }
00067 
00068 
00069 RTC::ReturnCode_t USBCameraMonitor::onInitialize()
00070 {
00071   bindParameter("image_height", m_img_height, "240");
00072   bindParameter("image_width", m_img_width, "320");
00073   return RTC::RTC_OK;
00074 }
00075 
00076 /*
00077   RTC::ReturnCode_t USBCameraMonitor::onFinalize()
00078   {
00079   //return RTC::OK;
00080   return RTC::RTC_OK;
00081   }
00082 */
00083 
00084 /*
00085   RTC::ReturnCode_t USBCameraMonitor::onStartup(RTC::UniqueId ec_id)
00086   {
00087   //return RTC::OK;
00088   return RTC::RTC_OK;
00089   }
00090 */
00091 
00092 /*
00093   RTC::ReturnCode_t USBCameraMonitor::onShutdown(RTC::UniqueId ec_id)
00094   {
00095   //return RTC::OK;
00096   return RTC::RTC_OK;
00097   }
00098 */
00099 
00100 
00101 RTC::ReturnCode_t USBCameraMonitor::onActivated(RTC::UniqueId ec_id)
00102 {
00103   m_img=cvCreateImage(cvSize(m_img_width,m_img_height),IPL_DEPTH_8U,3);
00104   
00105   //画像表示用ウィンドウの作成
00106   cvNamedWindow("CaptureImage", CV_WINDOW_AUTOSIZE);
00107   
00108   std::cout << "m_img->nChannels :" << m_img->nChannels << std::endl;
00109   std::cout << "m_img->width :" << m_img->width << std::endl;
00110   std::cout << "m_img->height :" << m_img->height << std::endl;
00111   
00112   return RTC::RTC_OK;
00113 }
00114 
00115 
00116 
00117 RTC::ReturnCode_t USBCameraMonitor::onDeactivated(RTC::UniqueId ec_id)
00118 {
00119   cvReleaseImage(&m_img);
00120   //表示ウィンドウの消去
00121   cvDestroyWindow("CaptureImage");
00122   return RTC::RTC_OK;
00123 }
00124 
00125 
00126 
00127 RTC::ReturnCode_t USBCameraMonitor::onExecute(RTC::UniqueId ec_id)
00128 {
00129   static coil::TimeValue tm_pre;
00130   static int count = 0;
00131   
00132   if (!m_inIn.isNew())
00133     {
00134       return RTC::RTC_OK;
00135     }
00136   
00137   m_inIn.read();
00138   if (!(m_in.data.length() > 0))
00139     {
00140       return RTC::RTC_OK;
00141     }
00142   
00143   memcpy(m_img->imageData,(void *)&(m_in.data[0]),m_in.data.length());
00144   
00145   //画像表示
00146   cvShowImage("CaptureImage", m_img);
00147   
00148   cvWaitKey(1);
00149   if (count > 100)
00150     {
00151       count = 0;
00152       coil::TimeValue tm;
00153       tm = coil::gettimeofday();
00154       double sec(tm - tm_pre);
00155       if (sec > 1.0 && sec < 1000.0)
00156         {
00157           std::cout << 100.0/sec << " [FPS]" << std::endl;
00158         }
00159       tm_pre = tm;
00160     }
00161   ++count;
00162   
00163   return RTC::RTC_OK;
00164 }
00165 
00166 
00167 /*
00168   RTC::ReturnCode_t USBCameraMonitor::onAborting(RTC::UniqueId ec_id)
00169   {
00170   //return RTC::OK;
00171   return RTC::RTC_OK;
00172   }
00173 */
00174 
00175 /*
00176   RTC::ReturnCode_t USBCameraMonitor::onError(RTC::UniqueId ec_id)
00177   {
00178   //return RTC::OK;
00179   return RTC::RTC_OK;
00180   }
00181 */
00182 
00183 /*
00184   RTC::ReturnCode_t USBCameraMonitor::onReset(RTC::UniqueId ec_id)
00185   {
00186   //return RTC::OK;
00187   return RTC::RTC_OK;
00188   }
00189 */
00190 
00191 /*
00192   RTC::ReturnCode_t USBCameraMonitor::onStateUpdate(RTC::UniqueId ec_id)
00193   {
00194   //return RTC::OK;
00195   return RTC::RTC_OK;
00196   }
00197 */
00198 
00199 /*
00200   RTC::ReturnCode_t USBCameraMonitor::onRateChanged(RTC::UniqueId ec_id)
00201   {
00202   //return RTC::OK;
00203   return RTC::RTC_OK;
00204   }
00205 */
00206 
00207 
00208 
00209 extern "C"
00210 {
00211   
00212   void USBCameraMonitorInit(RTC::Manager* manager)
00213   {
00214     coil::Properties profile(usbcameramonitor_spec);
00215     manager->registerFactory(profile,
00216                              RTC::Create<USBCameraMonitor>,
00217                              RTC::Delete<USBCameraMonitor>);
00218   }
00219   
00220 };
00221 
00222 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07