#pragma once #include "proto/def.grpc.pb.h" #include #include "tool/log.hpp" class NetMessageTrans { public: static void lableMat2Proto(int lable, cv::Mat &mat, JetStream::LabelImage &image, bool encode = false) { image.set_label(lable); image.mutable_ir()->set_width(mat.cols); image.mutable_ir()->set_height(mat.rows); image.mutable_ir()->set_channel(mat.type()); image.mutable_ir()->set_encode(encode); if (encode) { std::vector merge_encode_data; // cv::cvtColor(mat, mat, cv::COLOR_GRAY2RGB); cv::imencode(".jpg", mat, merge_encode_data, {cv::IMWRITE_JPEG_QUALITY, 80}); image.mutable_ir()->set_data(merge_encode_data.data(), merge_encode_data.size()); } else { image.mutable_ir()->set_data(mat.data, mat.dataend - mat.datastart); } // LOG(INFO) << "mat.dataend - mat.datastart = " << mat.dataend - mat.datastart; } static void Proto2lableMat(JetStream::LabelImage &image, int &lable, cv::Mat &mat) { lable = image.label(); if (image.ir().encode()) { std::vector data; data.resize(image.ir().data().size()); memcpy((void *)data.data(), (void *)image.ir().data().data(), data.size()); mat = cv::imdecode(data, 0); } else { mat = cv::Mat(image.ir().height(), image.ir().width(), image.ir().channel(), (void*)image.ir().data().data()); } } static void getSegBoxData() { } static void data2SegBox() { } };