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


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