10 #include <opencv2/highgui/highgui.hpp> 11 #include <opencv2/imgproc/imgproc.hpp> 12 #include <opencv2/core/core.hpp> 19 "implementation_id",
"JpegEncoder",
20 "type_name",
"JpegEncoder",
21 "description",
"null component",
22 "version", HRPSYS_PACKAGE_VERSION,
24 "category",
"example",
25 "activity_type",
"DataFlowComponent",
28 "lang_type",
"compile",
30 "conf.default.quality",
"95",
39 m_decodedIn(
"decoded", m_decoded),
40 m_encodedOut(
"encoded", m_encoded),
55 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
108 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
114 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
124 Img::ImageData& idat =
m_decoded.data.image;
125 std::vector<uchar>
buf;
126 std::vector<int> param = std::vector<int>(2);
127 param[0] = CV_IMWRITE_JPEG_QUALITY;
134 uchar r,g,
b, *raw=idat.raw_data.get_buffer();
135 for (
unsigned int i=0;
i<idat.raw_data.length();
i+=3, raw+=3){
136 r = raw[0]; g = raw[1]; b = raw[2];
137 raw[0] =
b; raw[1] = g; raw[2] = r;
140 cv::Mat src(idat.height, idat.width, CV_8UC3,
141 idat.raw_data.get_buffer());
142 cv::imencode(
".jpg", src, buf, param);
143 m_encoded.data.image.format = Img::CF_RGB_JPEG;
148 cv::Mat src(idat.height, idat.width, CV_8U,
149 idat.raw_data.get_buffer());
150 cv::imencode(
".jpg", src, buf, param);
151 m_encoded.data.image.format = Img::CF_GRAY_JPEG;
155 m_encoded.data.image.raw_data.length(buf.size());
156 unsigned char *dst =
m_encoded.data.image.raw_data.get_buffer();
157 memcpy(dst, &buf[0], buf.size());
160 std::cout <<
"JpegEncoder:" << idat.raw_data.length() <<
"->" 161 <<
m_encoded.data.image.raw_data.length() << std::endl;
212 RTC::Create<JpegEncoder>,
213 RTC::Delete<JpegEncoder>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
Img::TimedCameraImage m_decoded
virtual RTC::ReturnCode_t onInitialize()
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
InPort< Img::TimedCameraImage > m_decodedIn
bool addOutPort(const char *name, OutPortBase &outport)
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
OutPort< Img::TimedCameraImage > m_encodedOut
void JpegEncoderInit(RTC::Manager *manager)
Img::TimedCameraImage m_encoded
virtual bool write(DataType &value)
virtual ~JpegEncoder()
Destructor.
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
bool addInPort(const char *name, InPortBase &inport)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
static const char * jpegdecoder_spec[]
JpegEncoder(RTC::Manager *manager)
Constructor.