1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #pragma once
- #include "proto/def.grpc.pb.h"
- #include <opencv2/opencv.hpp>
- #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<uchar> 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<uchar> 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() {
- }
- };
|