10 #include <opencv2/highgui/highgui.hpp> 11 #include <opencv2/core/core.hpp> 18 "implementation_id",
"JpegDecoder",
19 "type_name",
"JpegDecoder",
20 "description",
"null component",
21 "version", HRPSYS_PACKAGE_VERSION,
23 "category",
"example",
24 "activity_type",
"DataFlowComponent",
27 "lang_type",
"compile",
37 m_encodedIn(
"encoded", m_encoded),
38 m_decodedOut(
"decoded", m_decoded),
52 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
104 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
110 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
124 Img::ImageData& idat =
m_encoded.data.image;
126 std::vector<uchar>
buf;
127 int len = idat.raw_data.length();
128 buf.resize(idat.raw_data.length());
129 memcpy(&buf[0], (
void *)&(idat.raw_data[0]), len);
131 int flags = (idat.format == Img::CF_GRAY_JPEG) ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR;
132 cv::Mat
image = cv::imdecode(cv::Mat(buf), flags);
134 if (idat.format == Img::CF_GRAY_JPEG){
135 m_decoded.data.image.format = Img::CF_GRAY;
136 m_decoded.data.image.raw_data.length(image.cols*image.rows);
138 m_decoded.data.image.format = Img::CF_RGB;
139 m_decoded.data.image.raw_data.length(image.cols*image.rows*3);
142 m_decoded.data.image.height = image.rows;
143 unsigned char *src = image.data;
144 unsigned char *dst =
m_decoded.data.image.raw_data.get_buffer();
145 if (idat.format == Img::CF_GRAY_JPEG){
146 memcpy(dst, src,
m_decoded.data.image.raw_data.length());
148 for (
int i=0;
i<image.rows;
i++){
149 for (
int j=0;
j<image.cols;
j++){
208 RTC::Create<JpegDecoder>,
209 RTC::Delete<JpegDecoder>);
static const char * jpegdecoder_spec[]
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
OutPort< Img::TimedCameraImage > m_decodedOut
bool addOutPort(const char *name, OutPortBase &outport)
InPort< Img::TimedCameraImage > m_encodedIn
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Img::TimedCameraImage m_decoded
virtual RTC::ReturnCode_t onInitialize()
ExecutionContextHandle_t UniqueId
def j(str, encoding="cp932")
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
virtual ~JpegDecoder()
Destructor.
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Img::TimedCameraImage m_encoded
virtual bool write(DataType &value)
bool addInPort(const char *name, InPortBase &inport)
JpegDecoder(RTC::Manager *manager)
Constructor.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void JpegDecoderInit(RTC::Manager *manager)