10 #include <opencv2/highgui/highgui.hpp> 11 #include <opencv2/core/core.hpp> 12 #ifndef CV_VERSION_EPOCH 13 #define CV_VERSION_EPOCH CV_VERSION_MAJOR 15 #if CV_VERSION_EPOCH > 3 16 #include <opencv2/imgcodecs/legacy/constants_c.h> 24 "implementation_id",
"JpegDecoder",
25 "type_name",
"JpegDecoder",
26 "description",
"null component",
27 "version", HRPSYS_PACKAGE_VERSION,
29 "category",
"example",
30 "activity_type",
"DataFlowComponent",
33 "lang_type",
"compile",
43 m_encodedIn(
"encoded", m_encoded),
44 m_decodedOut(
"decoded", m_decoded),
58 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
110 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
116 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
130 Img::ImageData& idat =
m_encoded.data.image;
132 std::vector<uchar>
buf;
133 int len = idat.raw_data.length();
134 buf.resize(idat.raw_data.length());
135 memcpy(&buf[0], (
void *)&(idat.raw_data[0]), len);
137 int flags = (idat.format == Img::CF_GRAY_JPEG) ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR;
138 cv::Mat
image = cv::imdecode(cv::Mat(buf), flags);
140 if (idat.format == Img::CF_GRAY_JPEG){
141 m_decoded.data.image.format = Img::CF_GRAY;
142 m_decoded.data.image.raw_data.length(image.cols*image.rows);
144 m_decoded.data.image.format = Img::CF_RGB;
145 m_decoded.data.image.raw_data.length(image.cols*image.rows*3);
148 m_decoded.data.image.height = image.rows;
149 unsigned char *src = image.data;
150 unsigned char *dst =
m_decoded.data.image.raw_data.get_buffer();
151 if (idat.format == Img::CF_GRAY_JPEG){
152 memcpy(dst, src,
m_decoded.data.image.raw_data.length());
154 for (
int i=0;
i<image.rows;
i++){
155 for (
int j=0; j<image.cols; j++){
214 RTC::Create<JpegDecoder>,
215 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
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)