00001
00010 #include <highgui.h>
00011 #include "ResizeImage.h"
00012
00013
00014
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
00028 "conf.default.scale", "1.0",
00029
00030 ""
00031 };
00032
00033
00034 ResizeImage::ResizeImage(RTC::Manager* manager)
00035 : RTC::DataFlowComponentBase(manager),
00036
00037 m_originalIn("original", m_original),
00038 m_resizedOut("resized", m_resized),
00039
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
00058
00059 bindParameter("scale", m_scale, "1.0");
00060
00061
00062
00063
00064
00065
00066 addInPort("original", m_originalIn);
00067
00068
00069 addOutPort("resized", m_resizedOut);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 return RTC::RTC_OK;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
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
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
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
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