net_message_trans.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "proto/def.grpc.pb.h"
  3. #include <opencv2/opencv.hpp>
  4. #include "tool/log.hpp"
  5. class NetMessageTrans {
  6. public:
  7. static void lableMat2Proto(int lable, cv::Mat &mat, JetStream::LabelImage &image, bool encode = false) {
  8. image.set_label(lable);
  9. image.mutable_ir()->set_width(mat.cols);
  10. image.mutable_ir()->set_height(mat.rows);
  11. image.mutable_ir()->set_channel(mat.type());
  12. image.mutable_ir()->set_encode(encode);
  13. if (encode) {
  14. std::vector<uchar> merge_encode_data;
  15. // cv::cvtColor(mat, mat, cv::COLOR_GRAY2RGB);
  16. cv::imencode(".jpg", mat, merge_encode_data, {cv::IMWRITE_JPEG_QUALITY, 80});
  17. image.mutable_ir()->set_data(merge_encode_data.data(), merge_encode_data.size());
  18. } else {
  19. image.mutable_ir()->set_data(mat.data, mat.dataend - mat.datastart);
  20. }
  21. // LOG(INFO) << "mat.dataend - mat.datastart = " << mat.dataend - mat.datastart;
  22. }
  23. static void Proto2lableMat(JetStream::LabelImage &image, int &lable, cv::Mat &mat) {
  24. lable = image.label();
  25. if (image.ir().encode()) {
  26. std::vector<uchar> data;
  27. data.resize(image.ir().data().size());
  28. memcpy((void *)data.data(), (void *)image.ir().data().data(), data.size());
  29. mat = cv::imdecode(data, 0);
  30. } else {
  31. mat = cv::Mat(image.ir().height(), image.ir().width(), image.ir().channel(), (void*)image.ir().data().data());
  32. }
  33. }
  34. static void getSegBoxData() {
  35. }
  36. static void data2SegBox() {
  37. }
  38. };