RGB2Gray.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include <opencv2/highgui/highgui.hpp>
00011 #include <opencv2/imgproc/imgproc.hpp>
00012 #include <opencv2/core/core.hpp>
00013 #include "RGB2Gray.h"
00014 
00015 // Module specification
00016 // <rtc-template block="module_spec">
00017 static const char* jpegdecoder_spec[] =
00018   {
00019     "implementation_id", "RGB2Gray",
00020     "type_name",         "RGB2Gray",
00021     "description",       "rgb2gray component",
00022     "version",           HRPSYS_PACKAGE_VERSION,
00023     "vendor",            "AIST",
00024     "category",          "example",
00025     "activity_type",     "DataFlowComponent",
00026     "max_instance",      "10",
00027     "language",          "C++",
00028     "lang_type",         "compile",
00029     // Configuration variables
00030 
00031     ""
00032   };
00033 // </rtc-template>
00034 
00035 RGB2Gray::RGB2Gray(RTC::Manager* manager)
00036   : RTC::DataFlowComponentBase(manager),
00037     // <rtc-template block="initializer">
00038     m_rgbIn("rgb",  m_rgb),
00039     m_grayOut("gray", m_gray),
00040     // </rtc-template>
00041     dummy(0)
00042 {
00043 }
00044 
00045 RGB2Gray::~RGB2Gray()
00046 {
00047 }
00048 
00049 
00050 
00051 RTC::ReturnCode_t RGB2Gray::onInitialize()
00052 {
00053   std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
00054   // <rtc-template block="bind_config">
00055   // Bind variables and configuration variable
00056   
00057   // </rtc-template>
00058 
00059   // Registration: InPort/OutPort/Service
00060   // <rtc-template block="registration">
00061   // Set InPort buffers
00062   addInPort("rgbIn", m_rgbIn);
00063 
00064   // Set OutPort buffer
00065   addOutPort("grayOut", m_grayOut);
00066   
00067   // Set service provider to Ports
00068   
00069   // Set service consumers to Ports
00070   
00071   // Set CORBA Service Ports
00072   
00073   // </rtc-template>
00074 
00075   //RTC::Properties& prop = getProperties();
00076 
00077   return RTC::RTC_OK;
00078 }
00079 
00080 
00081 
00082 /*
00083 RTC::ReturnCode_t RGB2Gray::onFinalize()
00084 {
00085   return RTC::RTC_OK;
00086 }
00087 */
00088 
00089 /*
00090 RTC::ReturnCode_t RGB2Gray::onStartup(RTC::UniqueId ec_id)
00091 {
00092   return RTC::RTC_OK;
00093 }
00094 */
00095 
00096 /*
00097 RTC::ReturnCode_t RGB2Gray::onShutdown(RTC::UniqueId ec_id)
00098 {
00099   return RTC::RTC_OK;
00100 }
00101 */
00102 
00103 RTC::ReturnCode_t RGB2Gray::onActivated(RTC::UniqueId ec_id)
00104 {
00105   std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00106   return RTC::RTC_OK;
00107 }
00108 
00109 RTC::ReturnCode_t RGB2Gray::onDeactivated(RTC::UniqueId ec_id)
00110 {
00111   std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00112   return RTC::RTC_OK;
00113 }
00114 
00115 RTC::ReturnCode_t RGB2Gray::onExecute(RTC::UniqueId ec_id)
00116 {
00117     //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
00118   if (m_rgbIn.isNew()){
00119       m_rgbIn.read();
00120 
00121       Img::ImageData& idat = m_rgb.data.image;
00122 
00123       cv::Mat src(idat.height, idat.width, CV_8UC3, 
00124                   idat.raw_data.get_buffer());
00125       cv::Mat dst;
00126       cv::cvtColor(src, dst, CV_RGB2GRAY);
00127 
00128       m_gray.data.image.width  = idat.width;
00129       m_gray.data.image.height = idat.height;
00130       m_gray.data.image.format = Img::CF_GRAY;
00131       m_gray.data.image.raw_data.length(idat.width*idat.height);
00132       memcpy(m_gray.data.image.raw_data.get_buffer(),
00133              dst.data, idat.width*idat.height);
00134 
00135       m_grayOut.write();
00136   }
00137   return RTC::RTC_OK;
00138 }
00139 
00140 /*
00141 RTC::ReturnCode_t RGB2Gray::onAborting(RTC::UniqueId ec_id)
00142 {
00143   return RTC::RTC_OK;
00144 }
00145 */
00146 
00147 /*
00148 RTC::ReturnCode_t RGB2Gray::onError(RTC::UniqueId ec_id)
00149 {
00150   return RTC::RTC_OK;
00151 }
00152 */
00153 
00154 /*
00155 RTC::ReturnCode_t RGB2Gray::onReset(RTC::UniqueId ec_id)
00156 {
00157   return RTC::RTC_OK;
00158 }
00159 */
00160 
00161 /*
00162 RTC::ReturnCode_t RGB2Gray::onStateUpdate(RTC::UniqueId ec_id)
00163 {
00164   return RTC::RTC_OK;
00165 }
00166 */
00167 
00168 /*
00169 RTC::ReturnCode_t RGB2Gray::onRateChanged(RTC::UniqueId ec_id)
00170 {
00171   return RTC::RTC_OK;
00172 }
00173 */
00174 
00175 
00176 
00177 extern "C"
00178 {
00179 
00180   void RGB2GrayInit(RTC::Manager* manager)
00181   {
00182     RTC::Properties profile(jpegdecoder_spec);
00183     manager->registerFactory(profile,
00184                              RTC::Create<RGB2Gray>,
00185                              RTC::Delete<RGB2Gray>);
00186   }
00187 
00188 };
00189 
00190 


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:55