Selaa lähdekoodia

实现点云转换

LiuZe 1 vuosi sitten
vanhempi
commit
4ebbbd13eb

+ 61 - 60
CMakeLists.txt

@@ -1,70 +1,75 @@
 set(SON_PROJECT_NAME tof3d)
 
-set(CMAKE_CUDA_ARCHITECTURES 60 61 62 70 72 75 86)
-set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
-project(${SON_PROJECT_NAME} LANGUAGES CXX CUDA)
-
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
-set(CMAKE_CXX_STANDARD 17)
-#set(CMAKE_BUILD_TYPE Release)
-option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
-
-# CUDA
-find_package(CUDA REQUIRED)
-message(STATUS "CUDA Libs: \n${CUDA_LIBRARIES}\n")
-get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
-message(STATUS "CUDA Headers: \n${CUDA_INCLUDE_DIRS}\n")
-
-# OpenCV
-find_package(OpenCV REQUIRED)
-message(STATUS "OpenCV Libs: \n${OpenCV_LIBS}\n")
-message(STATUS "OpenCV Libraries: \n${OpenCV_LIBRARIES}\n")
-message(STATUS "OpenCV Headers: \n${OpenCV_INCLUDE_DIRS}\n")
-
-# TensorRT
-set(TensorRT_INCLUDE_DIRS /usr/include/aarch64-linux-gnu)
-set(TensorRT_LIBRARIES /usr/lib/aarch64-linux-gnu)
-message(STATUS "TensorRT Libs: \n${TensorRT_LIBRARIES}\n")
-message(STATUS "TensorRT Headers: \n${TensorRT_INCLUDE_DIRS}\n")
-
-list(APPEND INCLUDE_DIRS
-        ${CUDA_INCLUDE_DIRS}
-        ${OpenCV_INCLUDE_DIRS}
-        ${TensorRT_INCLUDE_DIRS}
-        include
-)
+message("========== Load son project ${SON_PROJECT_NAME} ==========" )
 
-list(APPEND ALL_LIBS
-        ${CUDA_LIBRARIES}
-        ${CUDA_LIB_DIR}
-        ${TensorRT_LIBRARIES}
-)
+unset(OPTION_ENABLE_TENSORRT_DETECT_CODE CACHE)
+option(OPTION_ENABLE_TENSORRT_DETECT_CODE "" OFF)
+message("<=${SON_PROJECT_NAME}=> OPTION_ENABLE_TENSORRT_DETECT_CODE: " ${OPTION_ENABLE_TENSORRT_DETECT_CODE})
+
+if (OPTION_ENABLE_TENSORRT_DETECT_CODE)
+    set(CMAKE_CUDA_ARCHITECTURES 60 61 62 70 72 75 86)
+    set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
+    project(${SON_PROJECT_NAME} LANGUAGES CXX CUDA)
+
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
+    set(CMAKE_CXX_STANDARD 17)
+
+    option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
+
+    # CUDA
+    find_package(CUDA REQUIRED)
+    message(STATUS "CUDA Libs: \n${CUDA_LIBRARIES}\n")
+    get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
+    message(STATUS "CUDA Headers: \n${CUDA_INCLUDE_DIRS}\n")
+
+    # OpenCV
+    message(STATUS "OpenCV Libs: \n${OpenCV_LIBS}\n")
+    message(STATUS "OpenCV Libraries: \n${OpenCV_LIBRARIES}\n")
+    message(STATUS "OpenCV Headers: \n${OpenCV_INCLUDE_DIRS}\n")
+
+    if(${OpenCV_VERSION} VERSION_GREATER_EQUAL 4.7.0)
+        message(STATUS "Build with -DBATCHED_NMS")
+        add_definitions(-DBATCHED_NMS)
+    endif()
+
+    # TensorRT
+    set(TensorRT_INCLUDE_DIRS /usr/include/aarch64-linux-gnu)
+    set(TensorRT_LIBRARIES /usr/lib/aarch64-linux-gnu)
+    message(STATUS "TensorRT Libs: \n${TensorRT_LIBRARIES}\n")
+    message(STATUS "TensorRT Headers: \n${TensorRT_INCLUDE_DIRS}\n")
+
+    list(APPEND INCLUDE_DIRS
+            ${CUDA_INCLUDE_DIRS}
+            ${TensorRT_INCLUDE_DIRS}
+    )
+
+    list(APPEND ALL_LIBS
+            nvinfer
+            nvinfer_plugin
+            ${CUDA_LIBRARIES}
+            ${CUDA_LIB_DIR}
+            ${TensorRT_LIBRARIES}
+    )
+
+    aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect/tensorrt detect)
+else ()
+    aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect/onnx detect)
+endif ()
 
-message("========== Load son project ${SON_PROJECT_NAME} ==========" )
 option(OPTION_COMMUNICATION_WITH_PLC "plc通信" OFF)
 message("<=${SON_PROJECT_NAME}=> OPTION_COMMUNICATION_WITH_PLC: " ${OPTION_COMMUNICATION_WITH_PLC})
 
-# if(NOT ENABLE_LIBRARY_PCL)
-#     message(FATAL_ERROR "ENABLE_LIBRARY_PCL OFF")
-# endif ()
-
 if (NOT ENABLE_LIBRARY_GOOGLE_LOG)
     message(FATAL_ERROR "ENABLE_LIBRARY_GOOGLE_LOG OFF")
 endif ()
 
-# if (NOT ENABLE_LIBRARY_JSON)
-#     message(FATAL_ERROR "ENABLE_LIBRARY_JSON OFF")
-# endif ()
-
-# if (NOT ENABLE_LIBRARY_THREAD)
-#     message(FATAL_ERROR "Not enable ENABLE_LIBRARY_THREAD")
-# endif ()
-
 # 获取系统架构
 message("SYSTEM: ${CMAKE_SYSTEM_PROCESSOR}")
 
 if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
         set(NebulaSDK_PATH "${CMAKE_CURRENT_LIST_DIR}/NebulaSDK/AArch64")
+elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+        set(NebulaSDK_PATH "${CMAKE_CURRENT_LIST_DIR}/NebulaSDK/x86_64")
 endif()
 message("NebulaSDK_PATH: ${NebulaSDK_PATH}")
 
@@ -79,12 +84,11 @@ include_directories(
 
 aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication communication)
 aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/vzense vzense)
-aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/detect detect)
 
 set(SON_PROJECT_SOURCE_LIST ${SON_PROJECT_SOURCE_LIST}
+        ${detect}
         ${communication}
         ${vzense}
-        ${detect}
         ${CMAKE_CURRENT_LIST_DIR}/tof3d_manager.h
         ${CMAKE_CURRENT_LIST_DIR}/tof3d_manager.cpp
         ${CMAKE_CURRENT_LIST_DIR}/tof3d_config.pb.h
@@ -100,19 +104,16 @@ set(SON_PROJECT_DEPEND_LIST ${SON_PROJECT_DEPEND_LIST}
         ${NebulaSDK_PATH}/lib/libNebula_api.so
         ${PROTOBUF_LIBRARIES}
         ${OpenCV_LIBRARIES}
-        nvinfer
-        nvinfer_plugin
+        ${PCL_LIBRARIES}
         ${ALL_LIBS}
 )
 
 add_executable(${SON_PROJECT_NAME} ${SON_PROJECT_SOURCE_LIST})
 target_link_libraries(${SON_PROJECT_NAME} ${SON_PROJECT_DEPEND_LIST})
 target_compile_definitions(${SON_PROJECT_NAME} PRIVATE PROJECT_NAME="${SON_PROJECT_NAME}")
-
-if(${OpenCV_VERSION} VERSION_GREATER_EQUAL 4.7.0)
-    message(STATUS "Build with -DBATCHED_NMS")
-    add_definitions(-DBATCHED_NMS)
-endif()
+if (OPTION_ENABLE_TENSORRT_DETECT_CODE)
+        target_compile_definitions(${SON_PROJECT_NAME} PRIVATE ENABLE_TENSORRT_DETECT)
+endif ()
 
 install(TARGETS ${SON_PROJECT_NAME}
         LIBRARY DESTINATION lib  # 动态库安装路径

+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS77CLite_0F.json


+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS77CPro_0E.json


+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS77Lite_11.json


+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS77Pro_10.json


+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS86_12.json


+ 0 - 0
NebulaSDK/AArch64/lib/Config/DS87_13.json


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1241 - 1598
communication/communication.pb.cc


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1574 - 946
communication/communication.pb.h


+ 0 - 142
detect/common.hpp

@@ -1,142 +0,0 @@
-//
-// Created by ubuntu on 3/16/23.
-//
-
-#ifndef JETSON_SEGMENT_COMMON_HPP
-#define JETSON_SEGMENT_COMMON_HPP
-#include "NvInfer.h"
-#include "opencv2/opencv.hpp"
-#include <sys/stat.h>
-#include <unistd.h>
-
-#define CHECK(call)                                                                                                    \
-    do {                                                                                                               \
-        const cudaError_t error_code = call;                                                                           \
-        if (error_code != cudaSuccess) {                                                                               \
-            printf("CUDA Error:\n");                                                                                   \
-            printf("    File:       %s\n", __FILE__);                                                                  \
-            printf("    Line:       %d\n", __LINE__);                                                                  \
-            printf("    Error code: %d\n", error_code);                                                                \
-            printf("    Error text: %s\n", cudaGetErrorString(error_code));                                            \
-            exit(1);                                                                                                   \
-        }                                                                                                              \
-    } while (0)
-
-class Logger: public nvinfer1::ILogger {
-public:
-    nvinfer1::ILogger::Severity reportableSeverity;
-
-    explicit Logger(nvinfer1::ILogger::Severity severity = nvinfer1::ILogger::Severity::kINFO):
-        reportableSeverity(severity)
-    {
-    }
-
-    void log(nvinfer1::ILogger::Severity severity, const char* msg) noexcept override
-    {
-        if (severity > reportableSeverity) {
-            return;
-        }
-        switch (severity) {
-            case nvinfer1::ILogger::Severity::kINTERNAL_ERROR:
-                std::cerr << "INTERNAL_ERROR: ";
-                break;
-            case nvinfer1::ILogger::Severity::kERROR:
-                std::cerr << "ERROR: ";
-                break;
-            case nvinfer1::ILogger::Severity::kWARNING:
-                std::cerr << "WARNING: ";
-                break;
-            case nvinfer1::ILogger::Severity::kINFO:
-                std::cerr << "INFO: ";
-                break;
-            default:
-                std::cerr << "VERBOSE: ";
-                break;
-        }
-        std::cerr << msg << std::endl;
-    }
-};
-
-inline int get_size_by_dims(const nvinfer1::Dims& dims)
-{
-    int size = 1;
-    for (int i = 0; i < dims.nbDims; i++) {
-        size *= dims.d[i];
-    }
-    return size;
-}
-
-inline int type_to_size(const nvinfer1::DataType& dataType)
-{
-    switch (dataType) {
-        case nvinfer1::DataType::kFLOAT:
-            return 4;
-        case nvinfer1::DataType::kHALF:
-            return 2;
-        case nvinfer1::DataType::kINT32:
-            return 4;
-        case nvinfer1::DataType::kINT8:
-            return 1;
-        case nvinfer1::DataType::kBOOL:
-            return 1;
-        default:
-            return 4;
-    }
-}
-
-inline static float clamp(float val, float min, float max)
-{
-    return val > min ? (val < max ? val : max) : min;
-}
-
-inline bool IsPathExist(const std::string& path)
-{
-    if (access(path.c_str(), 0) == F_OK) {
-        return true;
-    }
-    return false;
-}
-
-inline bool IsFile(const std::string& path)
-{
-    if (!IsPathExist(path)) {
-        printf("%s:%d %s not exist\n", __FILE__, __LINE__, path.c_str());
-        return false;
-    }
-    struct stat buffer;
-    return (stat(path.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));
-}
-
-inline bool IsFolder(const std::string& path)
-{
-    if (!IsPathExist(path)) {
-        return false;
-    }
-    struct stat buffer;
-    return (stat(path.c_str(), &buffer) == 0 && S_ISDIR(buffer.st_mode));
-}
-
-namespace seg {
-struct Binding {
-    size_t         size  = 1;
-    size_t         dsize = 1;
-    nvinfer1::Dims dims;
-    std::string    name;
-};
-
-struct Object {
-    cv::Rect_<float> rect;
-    int              label = 0;
-    float            prob  = 0.0;
-    cv::Mat          boxMask;
-};
-
-struct PreParam {
-    float ratio  = 1.0f;
-    float dw     = 0.0f;
-    float dh     = 0.0f;
-    float height = 0;
-    float width  = 0;
-};
-}  // namespace seg
-#endif  // JETSON_SEGMENT_COMMON_HPP

+ 0 - 658
detect/stream/def.pb.cc

@@ -1,658 +0,0 @@
-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-// source: def.proto
-
-#include "def.pb.h"
-
-#include <algorithm>
-
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/port.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/wire_format_lite_inl.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/generated_message_reflection.h>
-#include <google/protobuf/reflection_ops.h>
-#include <google/protobuf/wire_format.h>
-// This is a temporary google only hack
-#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
-#include "third_party/protobuf/version.h"
-#endif
-// @@protoc_insertion_point(includes)
-
-namespace JetStream {
-class RequestCmdDefaultTypeInternal {
- public:
-  ::google::protobuf::internal::ExplicitlyConstructed<RequestCmd>
-      _instance;
-} _RequestCmd_default_instance_;
-class ResponseDefaultTypeInternal {
- public:
-  ::google::protobuf::internal::ExplicitlyConstructed<Response>
-      _instance;
-} _Response_default_instance_;
-}  // namespace JetStream
-namespace protobuf_def_2eproto {
-static void InitDefaultsRequestCmd() {
-  GOOGLE_PROTOBUF_VERIFY_VERSION;
-
-  {
-    void* ptr = &::JetStream::_RequestCmd_default_instance_;
-    new (ptr) ::JetStream::RequestCmd();
-    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
-  }
-  ::JetStream::RequestCmd::InitAsDefaultInstance();
-}
-
-::google::protobuf::internal::SCCInfo<0> scc_info_RequestCmd =
-    {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsRequestCmd}, {}};
-
-static void InitDefaultsResponse() {
-  GOOGLE_PROTOBUF_VERIFY_VERSION;
-
-  {
-    void* ptr = &::JetStream::_Response_default_instance_;
-    new (ptr) ::JetStream::Response();
-    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
-  }
-  ::JetStream::Response::InitAsDefaultInstance();
-}
-
-::google::protobuf::internal::SCCInfo<0> scc_info_Response =
-    {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsResponse}, {}};
-
-void InitDefaults() {
-  ::google::protobuf::internal::InitSCC(&scc_info_RequestCmd.base);
-  ::google::protobuf::internal::InitSCC(&scc_info_Response.base);
-}
-
-::google::protobuf::Metadata file_level_metadata[2];
-
-const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
-  ~0u,  // no _has_bits_
-  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::JetStream::RequestCmd, _internal_metadata_),
-  ~0u,  // no _extensions_
-  ~0u,  // no _oneof_case_
-  ~0u,  // no _weak_field_map_
-  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::JetStream::RequestCmd, action_),
-  ~0u,  // no _has_bits_
-  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::JetStream::Response, _internal_metadata_),
-  ~0u,  // no _extensions_
-  ~0u,  // no _oneof_case_
-  ~0u,  // no _weak_field_map_
-  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::JetStream::Response, ret_),
-  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::JetStream::Response, info_),
-};
-static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
-  { 0, -1, sizeof(::JetStream::RequestCmd)},
-  { 6, -1, sizeof(::JetStream::Response)},
-};
-
-static ::google::protobuf::Message const * const file_default_instances[] = {
-  reinterpret_cast<const ::google::protobuf::Message*>(&::JetStream::_RequestCmd_default_instance_),
-  reinterpret_cast<const ::google::protobuf::Message*>(&::JetStream::_Response_default_instance_),
-};
-
-void protobuf_AssignDescriptors() {
-  AddDescriptors();
-  AssignDescriptors(
-      "def.proto", schemas, file_default_instances, TableStruct::offsets,
-      file_level_metadata, NULL, NULL);
-}
-
-void protobuf_AssignDescriptorsOnce() {
-  static ::google::protobuf::internal::once_flag once;
-  ::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
-}
-
-void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
-void protobuf_RegisterTypes(const ::std::string&) {
-  protobuf_AssignDescriptorsOnce();
-  ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 2);
-}
-
-void AddDescriptorsImpl() {
-  InitDefaults();
-  static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
-      "\n\tdef.proto\022\tJetStream\"\034\n\nRequestCmd\022\016\n\006"
-      "action\030\001 \001(\005\"%\n\010Response\022\013\n\003ret\030\001 \001(\005\022\014\n"
-      "\004info\030\002 \001(\t2L\n\nNavExcutor\022>\n\014DetectStrea"
-      "m\022\025.JetStream.RequestCmd\032\023.JetStream.Res"
-      "ponse\"\0000\001b\006proto3"
-  };
-  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
-      descriptor, 177);
-  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
-    "def.proto", &protobuf_RegisterTypes);
-}
-
-void AddDescriptors() {
-  static ::google::protobuf::internal::once_flag once;
-  ::google::protobuf::internal::call_once(once, AddDescriptorsImpl);
-}
-// Force AddDescriptors() to be called at dynamic initialization time.
-struct StaticDescriptorInitializer {
-  StaticDescriptorInitializer() {
-    AddDescriptors();
-  }
-} static_descriptor_initializer;
-}  // namespace protobuf_def_2eproto
-namespace JetStream {
-
-// ===================================================================
-
-void RequestCmd::InitAsDefaultInstance() {
-}
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const int RequestCmd::kActionFieldNumber;
-#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
-
-RequestCmd::RequestCmd()
-  : ::google::protobuf::Message(), _internal_metadata_(NULL) {
-  ::google::protobuf::internal::InitSCC(
-      &protobuf_def_2eproto::scc_info_RequestCmd.base);
-  SharedCtor();
-  // @@protoc_insertion_point(constructor:JetStream.RequestCmd)
-}
-RequestCmd::RequestCmd(const RequestCmd& from)
-  : ::google::protobuf::Message(),
-      _internal_metadata_(NULL) {
-  _internal_metadata_.MergeFrom(from._internal_metadata_);
-  action_ = from.action_;
-  // @@protoc_insertion_point(copy_constructor:JetStream.RequestCmd)
-}
-
-void RequestCmd::SharedCtor() {
-  action_ = 0;
-}
-
-RequestCmd::~RequestCmd() {
-  // @@protoc_insertion_point(destructor:JetStream.RequestCmd)
-  SharedDtor();
-}
-
-void RequestCmd::SharedDtor() {
-}
-
-void RequestCmd::SetCachedSize(int size) const {
-  _cached_size_.Set(size);
-}
-const ::google::protobuf::Descriptor* RequestCmd::descriptor() {
-  ::protobuf_def_2eproto::protobuf_AssignDescriptorsOnce();
-  return ::protobuf_def_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
-}
-
-const RequestCmd& RequestCmd::default_instance() {
-  ::google::protobuf::internal::InitSCC(&protobuf_def_2eproto::scc_info_RequestCmd.base);
-  return *internal_default_instance();
-}
-
-
-void RequestCmd::Clear() {
-// @@protoc_insertion_point(message_clear_start:JetStream.RequestCmd)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  // Prevent compiler warnings about cached_has_bits being unused
-  (void) cached_has_bits;
-
-  action_ = 0;
-  _internal_metadata_.Clear();
-}
-
-bool RequestCmd::MergePartialFromCodedStream(
-    ::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
-  ::google::protobuf::uint32 tag;
-  // @@protoc_insertion_point(parse_start:JetStream.RequestCmd)
-  for (;;) {
-    ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
-    tag = p.first;
-    if (!p.second) goto handle_unusual;
-    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
-      // int32 action = 1;
-      case 1: {
-        if (static_cast< ::google::protobuf::uint8>(tag) ==
-            static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
-
-          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
-                   ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
-                 input, &action_)));
-        } else {
-          goto handle_unusual;
-        }
-        break;
-      }
-
-      default: {
-      handle_unusual:
-        if (tag == 0) {
-          goto success;
-        }
-        DO_(::google::protobuf::internal::WireFormat::SkipField(
-              input, tag, _internal_metadata_.mutable_unknown_fields()));
-        break;
-      }
-    }
-  }
-success:
-  // @@protoc_insertion_point(parse_success:JetStream.RequestCmd)
-  return true;
-failure:
-  // @@protoc_insertion_point(parse_failure:JetStream.RequestCmd)
-  return false;
-#undef DO_
-}
-
-void RequestCmd::SerializeWithCachedSizes(
-    ::google::protobuf::io::CodedOutputStream* output) const {
-  // @@protoc_insertion_point(serialize_start:JetStream.RequestCmd)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  // int32 action = 1;
-  if (this->action() != 0) {
-    ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->action(), output);
-  }
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()), output);
-  }
-  // @@protoc_insertion_point(serialize_end:JetStream.RequestCmd)
-}
-
-::google::protobuf::uint8* RequestCmd::InternalSerializeWithCachedSizesToArray(
-    bool deterministic, ::google::protobuf::uint8* target) const {
-  (void)deterministic; // Unused
-  // @@protoc_insertion_point(serialize_to_array_start:JetStream.RequestCmd)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  // int32 action = 1;
-  if (this->action() != 0) {
-    target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->action(), target);
-  }
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()), target);
-  }
-  // @@protoc_insertion_point(serialize_to_array_end:JetStream.RequestCmd)
-  return target;
-}
-
-size_t RequestCmd::ByteSizeLong() const {
-// @@protoc_insertion_point(message_byte_size_start:JetStream.RequestCmd)
-  size_t total_size = 0;
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    total_size +=
-      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()));
-  }
-  // int32 action = 1;
-  if (this->action() != 0) {
-    total_size += 1 +
-      ::google::protobuf::internal::WireFormatLite::Int32Size(
-        this->action());
-  }
-
-  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
-  SetCachedSize(cached_size);
-  return total_size;
-}
-
-void RequestCmd::MergeFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_merge_from_start:JetStream.RequestCmd)
-  GOOGLE_DCHECK_NE(&from, this);
-  const RequestCmd* source =
-      ::google::protobuf::internal::DynamicCastToGenerated<const RequestCmd>(
-          &from);
-  if (source == NULL) {
-  // @@protoc_insertion_point(generalized_merge_from_cast_fail:JetStream.RequestCmd)
-    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
-  } else {
-  // @@protoc_insertion_point(generalized_merge_from_cast_success:JetStream.RequestCmd)
-    MergeFrom(*source);
-  }
-}
-
-void RequestCmd::MergeFrom(const RequestCmd& from) {
-// @@protoc_insertion_point(class_specific_merge_from_start:JetStream.RequestCmd)
-  GOOGLE_DCHECK_NE(&from, this);
-  _internal_metadata_.MergeFrom(from._internal_metadata_);
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  if (from.action() != 0) {
-    set_action(from.action());
-  }
-}
-
-void RequestCmd::CopyFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_copy_from_start:JetStream.RequestCmd)
-  if (&from == this) return;
-  Clear();
-  MergeFrom(from);
-}
-
-void RequestCmd::CopyFrom(const RequestCmd& from) {
-// @@protoc_insertion_point(class_specific_copy_from_start:JetStream.RequestCmd)
-  if (&from == this) return;
-  Clear();
-  MergeFrom(from);
-}
-
-bool RequestCmd::IsInitialized() const {
-  return true;
-}
-
-void RequestCmd::Swap(RequestCmd* other) {
-  if (other == this) return;
-  InternalSwap(other);
-}
-void RequestCmd::InternalSwap(RequestCmd* other) {
-  using std::swap;
-  swap(action_, other->action_);
-  _internal_metadata_.Swap(&other->_internal_metadata_);
-}
-
-::google::protobuf::Metadata RequestCmd::GetMetadata() const {
-  protobuf_def_2eproto::protobuf_AssignDescriptorsOnce();
-  return ::protobuf_def_2eproto::file_level_metadata[kIndexInFileMessages];
-}
-
-
-// ===================================================================
-
-void Response::InitAsDefaultInstance() {
-}
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const int Response::kRetFieldNumber;
-const int Response::kInfoFieldNumber;
-#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
-
-Response::Response()
-  : ::google::protobuf::Message(), _internal_metadata_(NULL) {
-  ::google::protobuf::internal::InitSCC(
-      &protobuf_def_2eproto::scc_info_Response.base);
-  SharedCtor();
-  // @@protoc_insertion_point(constructor:JetStream.Response)
-}
-Response::Response(const Response& from)
-  : ::google::protobuf::Message(),
-      _internal_metadata_(NULL) {
-  _internal_metadata_.MergeFrom(from._internal_metadata_);
-  info_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  if (from.info().size() > 0) {
-    info_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.info_);
-  }
-  ret_ = from.ret_;
-  // @@protoc_insertion_point(copy_constructor:JetStream.Response)
-}
-
-void Response::SharedCtor() {
-  info_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  ret_ = 0;
-}
-
-Response::~Response() {
-  // @@protoc_insertion_point(destructor:JetStream.Response)
-  SharedDtor();
-}
-
-void Response::SharedDtor() {
-  info_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-
-void Response::SetCachedSize(int size) const {
-  _cached_size_.Set(size);
-}
-const ::google::protobuf::Descriptor* Response::descriptor() {
-  ::protobuf_def_2eproto::protobuf_AssignDescriptorsOnce();
-  return ::protobuf_def_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
-}
-
-const Response& Response::default_instance() {
-  ::google::protobuf::internal::InitSCC(&protobuf_def_2eproto::scc_info_Response.base);
-  return *internal_default_instance();
-}
-
-
-void Response::Clear() {
-// @@protoc_insertion_point(message_clear_start:JetStream.Response)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  // Prevent compiler warnings about cached_has_bits being unused
-  (void) cached_has_bits;
-
-  info_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-  ret_ = 0;
-  _internal_metadata_.Clear();
-}
-
-bool Response::MergePartialFromCodedStream(
-    ::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
-  ::google::protobuf::uint32 tag;
-  // @@protoc_insertion_point(parse_start:JetStream.Response)
-  for (;;) {
-    ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
-    tag = p.first;
-    if (!p.second) goto handle_unusual;
-    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
-      // int32 ret = 1;
-      case 1: {
-        if (static_cast< ::google::protobuf::uint8>(tag) ==
-            static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
-
-          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
-                   ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
-                 input, &ret_)));
-        } else {
-          goto handle_unusual;
-        }
-        break;
-      }
-
-      // string info = 2;
-      case 2: {
-        if (static_cast< ::google::protobuf::uint8>(tag) ==
-            static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
-          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
-                input, this->mutable_info()));
-          DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
-            this->info().data(), static_cast<int>(this->info().length()),
-            ::google::protobuf::internal::WireFormatLite::PARSE,
-            "JetStream.Response.info"));
-        } else {
-          goto handle_unusual;
-        }
-        break;
-      }
-
-      default: {
-      handle_unusual:
-        if (tag == 0) {
-          goto success;
-        }
-        DO_(::google::protobuf::internal::WireFormat::SkipField(
-              input, tag, _internal_metadata_.mutable_unknown_fields()));
-        break;
-      }
-    }
-  }
-success:
-  // @@protoc_insertion_point(parse_success:JetStream.Response)
-  return true;
-failure:
-  // @@protoc_insertion_point(parse_failure:JetStream.Response)
-  return false;
-#undef DO_
-}
-
-void Response::SerializeWithCachedSizes(
-    ::google::protobuf::io::CodedOutputStream* output) const {
-  // @@protoc_insertion_point(serialize_start:JetStream.Response)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  // int32 ret = 1;
-  if (this->ret() != 0) {
-    ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->ret(), output);
-  }
-
-  // string info = 2;
-  if (this->info().size() > 0) {
-    ::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
-      this->info().data(), static_cast<int>(this->info().length()),
-      ::google::protobuf::internal::WireFormatLite::SERIALIZE,
-      "JetStream.Response.info");
-    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
-      2, this->info(), output);
-  }
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()), output);
-  }
-  // @@protoc_insertion_point(serialize_end:JetStream.Response)
-}
-
-::google::protobuf::uint8* Response::InternalSerializeWithCachedSizesToArray(
-    bool deterministic, ::google::protobuf::uint8* target) const {
-  (void)deterministic; // Unused
-  // @@protoc_insertion_point(serialize_to_array_start:JetStream.Response)
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  // int32 ret = 1;
-  if (this->ret() != 0) {
-    target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->ret(), target);
-  }
-
-  // string info = 2;
-  if (this->info().size() > 0) {
-    ::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
-      this->info().data(), static_cast<int>(this->info().length()),
-      ::google::protobuf::internal::WireFormatLite::SERIALIZE,
-      "JetStream.Response.info");
-    target =
-      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
-        2, this->info(), target);
-  }
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()), target);
-  }
-  // @@protoc_insertion_point(serialize_to_array_end:JetStream.Response)
-  return target;
-}
-
-size_t Response::ByteSizeLong() const {
-// @@protoc_insertion_point(message_byte_size_start:JetStream.Response)
-  size_t total_size = 0;
-
-  if ((_internal_metadata_.have_unknown_fields() &&  ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
-    total_size +=
-      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
-        (::google::protobuf::internal::GetProto3PreserveUnknownsDefault()   ? _internal_metadata_.unknown_fields()   : _internal_metadata_.default_instance()));
-  }
-  // string info = 2;
-  if (this->info().size() > 0) {
-    total_size += 1 +
-      ::google::protobuf::internal::WireFormatLite::StringSize(
-        this->info());
-  }
-
-  // int32 ret = 1;
-  if (this->ret() != 0) {
-    total_size += 1 +
-      ::google::protobuf::internal::WireFormatLite::Int32Size(
-        this->ret());
-  }
-
-  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
-  SetCachedSize(cached_size);
-  return total_size;
-}
-
-void Response::MergeFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_merge_from_start:JetStream.Response)
-  GOOGLE_DCHECK_NE(&from, this);
-  const Response* source =
-      ::google::protobuf::internal::DynamicCastToGenerated<const Response>(
-          &from);
-  if (source == NULL) {
-  // @@protoc_insertion_point(generalized_merge_from_cast_fail:JetStream.Response)
-    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
-  } else {
-  // @@protoc_insertion_point(generalized_merge_from_cast_success:JetStream.Response)
-    MergeFrom(*source);
-  }
-}
-
-void Response::MergeFrom(const Response& from) {
-// @@protoc_insertion_point(class_specific_merge_from_start:JetStream.Response)
-  GOOGLE_DCHECK_NE(&from, this);
-  _internal_metadata_.MergeFrom(from._internal_metadata_);
-  ::google::protobuf::uint32 cached_has_bits = 0;
-  (void) cached_has_bits;
-
-  if (from.info().size() > 0) {
-
-    info_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.info_);
-  }
-  if (from.ret() != 0) {
-    set_ret(from.ret());
-  }
-}
-
-void Response::CopyFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_copy_from_start:JetStream.Response)
-  if (&from == this) return;
-  Clear();
-  MergeFrom(from);
-}
-
-void Response::CopyFrom(const Response& from) {
-// @@protoc_insertion_point(class_specific_copy_from_start:JetStream.Response)
-  if (&from == this) return;
-  Clear();
-  MergeFrom(from);
-}
-
-bool Response::IsInitialized() const {
-  return true;
-}
-
-void Response::Swap(Response* other) {
-  if (other == this) return;
-  InternalSwap(other);
-}
-void Response::InternalSwap(Response* other) {
-  using std::swap;
-  info_.Swap(&other->info_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(),
-    GetArenaNoVirtual());
-  swap(ret_, other->ret_);
-  _internal_metadata_.Swap(&other->_internal_metadata_);
-}
-
-::google::protobuf::Metadata Response::GetMetadata() const {
-  protobuf_def_2eproto::protobuf_AssignDescriptorsOnce();
-  return ::protobuf_def_2eproto::file_level_metadata[kIndexInFileMessages];
-}
-
-
-// @@protoc_insertion_point(namespace_scope)
-}  // namespace JetStream
-namespace google {
-namespace protobuf {
-template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::JetStream::RequestCmd* Arena::CreateMaybeMessage< ::JetStream::RequestCmd >(Arena* arena) {
-  return Arena::CreateInternal< ::JetStream::RequestCmd >(arena);
-}
-template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::JetStream::Response* Arena::CreateMaybeMessage< ::JetStream::Response >(Arena* arena) {
-  return Arena::CreateInternal< ::JetStream::Response >(arena);
-}
-}  // namespace protobuf
-}  // namespace google
-
-// @@protoc_insertion_point(global_scope)

+ 0 - 393
detect/stream/def.pb.h

@@ -1,393 +0,0 @@
-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-// source: def.proto
-
-#ifndef PROTOBUF_INCLUDED_def_2eproto
-#define PROTOBUF_INCLUDED_def_2eproto
-
-#include <string>
-
-#include <google/protobuf/stubs/common.h>
-
-#if GOOGLE_PROTOBUF_VERSION < 3006001
-#error This file was generated by a newer version of protoc which is
-#error incompatible with your Protocol Buffer headers.  Please update
-#error your headers.
-#endif
-#if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
-#error This file was generated by an older version of protoc which is
-#error incompatible with your Protocol Buffer headers.  Please
-#error regenerate this file with a newer version of protoc.
-#endif
-
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/arena.h>
-#include <google/protobuf/arenastring.h>
-#include <google/protobuf/generated_message_table_driven.h>
-#include <google/protobuf/generated_message_util.h>
-#include <google/protobuf/inlined_string_field.h>
-#include <google/protobuf/metadata.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
-#include <google/protobuf/extension_set.h>  // IWYU pragma: export
-#include <google/protobuf/unknown_field_set.h>
-// @@protoc_insertion_point(includes)
-#define PROTOBUF_INTERNAL_EXPORT_protobuf_def_2eproto 
-
-namespace protobuf_def_2eproto {
-// Internal implementation detail -- do not use these members.
-struct TableStruct {
-  static const ::google::protobuf::internal::ParseTableField entries[];
-  static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
-  static const ::google::protobuf::internal::ParseTable schema[2];
-  static const ::google::protobuf::internal::FieldMetadata field_metadata[];
-  static const ::google::protobuf::internal::SerializationTable serialization_table[];
-  static const ::google::protobuf::uint32 offsets[];
-};
-void AddDescriptors();
-}  // namespace protobuf_def_2eproto
-namespace JetStream {
-class RequestCmd;
-class RequestCmdDefaultTypeInternal;
-extern RequestCmdDefaultTypeInternal _RequestCmd_default_instance_;
-class Response;
-class ResponseDefaultTypeInternal;
-extern ResponseDefaultTypeInternal _Response_default_instance_;
-}  // namespace JetStream
-namespace google {
-namespace protobuf {
-template<> ::JetStream::RequestCmd* Arena::CreateMaybeMessage<::JetStream::RequestCmd>(Arena*);
-template<> ::JetStream::Response* Arena::CreateMaybeMessage<::JetStream::Response>(Arena*);
-}  // namespace protobuf
-}  // namespace google
-namespace JetStream {
-
-// ===================================================================
-
-class RequestCmd : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:JetStream.RequestCmd) */ {
- public:
-  RequestCmd();
-  virtual ~RequestCmd();
-
-  RequestCmd(const RequestCmd& from);
-
-  inline RequestCmd& operator=(const RequestCmd& from) {
-    CopyFrom(from);
-    return *this;
-  }
-  #if LANG_CXX11
-  RequestCmd(RequestCmd&& from) noexcept
-    : RequestCmd() {
-    *this = ::std::move(from);
-  }
-
-  inline RequestCmd& operator=(RequestCmd&& from) noexcept {
-    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
-      if (this != &from) InternalSwap(&from);
-    } else {
-      CopyFrom(from);
-    }
-    return *this;
-  }
-  #endif
-  static const ::google::protobuf::Descriptor* descriptor();
-  static const RequestCmd& default_instance();
-
-  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
-  static inline const RequestCmd* internal_default_instance() {
-    return reinterpret_cast<const RequestCmd*>(
-               &_RequestCmd_default_instance_);
-  }
-  static constexpr int kIndexInFileMessages =
-    0;
-
-  void Swap(RequestCmd* other);
-  friend void swap(RequestCmd& a, RequestCmd& b) {
-    a.Swap(&b);
-  }
-
-  // implements Message ----------------------------------------------
-
-  inline RequestCmd* New() const final {
-    return CreateMaybeMessage<RequestCmd>(NULL);
-  }
-
-  RequestCmd* New(::google::protobuf::Arena* arena) const final {
-    return CreateMaybeMessage<RequestCmd>(arena);
-  }
-  void CopyFrom(const ::google::protobuf::Message& from) final;
-  void MergeFrom(const ::google::protobuf::Message& from) final;
-  void CopyFrom(const RequestCmd& from);
-  void MergeFrom(const RequestCmd& from);
-  void Clear() final;
-  bool IsInitialized() const final;
-
-  size_t ByteSizeLong() const final;
-  bool MergePartialFromCodedStream(
-      ::google::protobuf::io::CodedInputStream* input) final;
-  void SerializeWithCachedSizes(
-      ::google::protobuf::io::CodedOutputStream* output) const final;
-  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
-      bool deterministic, ::google::protobuf::uint8* target) const final;
-  int GetCachedSize() const final { return _cached_size_.Get(); }
-
-  private:
-  void SharedCtor();
-  void SharedDtor();
-  void SetCachedSize(int size) const final;
-  void InternalSwap(RequestCmd* other);
-  private:
-  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
-    return NULL;
-  }
-  inline void* MaybeArenaPtr() const {
-    return NULL;
-  }
-  public:
-
-  ::google::protobuf::Metadata GetMetadata() const final;
-
-  // nested types ----------------------------------------------------
-
-  // accessors -------------------------------------------------------
-
-  // int32 action = 1;
-  void clear_action();
-  static const int kActionFieldNumber = 1;
-  ::google::protobuf::int32 action() const;
-  void set_action(::google::protobuf::int32 value);
-
-  // @@protoc_insertion_point(class_scope:JetStream.RequestCmd)
- private:
-
-  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
-  ::google::protobuf::int32 action_;
-  mutable ::google::protobuf::internal::CachedSize _cached_size_;
-  friend struct ::protobuf_def_2eproto::TableStruct;
-};
-// -------------------------------------------------------------------
-
-class Response : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:JetStream.Response) */ {
- public:
-  Response();
-  virtual ~Response();
-
-  Response(const Response& from);
-
-  inline Response& operator=(const Response& from) {
-    CopyFrom(from);
-    return *this;
-  }
-  #if LANG_CXX11
-  Response(Response&& from) noexcept
-    : Response() {
-    *this = ::std::move(from);
-  }
-
-  inline Response& operator=(Response&& from) noexcept {
-    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
-      if (this != &from) InternalSwap(&from);
-    } else {
-      CopyFrom(from);
-    }
-    return *this;
-  }
-  #endif
-  static const ::google::protobuf::Descriptor* descriptor();
-  static const Response& default_instance();
-
-  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
-  static inline const Response* internal_default_instance() {
-    return reinterpret_cast<const Response*>(
-               &_Response_default_instance_);
-  }
-  static constexpr int kIndexInFileMessages =
-    1;
-
-  void Swap(Response* other);
-  friend void swap(Response& a, Response& b) {
-    a.Swap(&b);
-  }
-
-  // implements Message ----------------------------------------------
-
-  inline Response* New() const final {
-    return CreateMaybeMessage<Response>(NULL);
-  }
-
-  Response* New(::google::protobuf::Arena* arena) const final {
-    return CreateMaybeMessage<Response>(arena);
-  }
-  void CopyFrom(const ::google::protobuf::Message& from) final;
-  void MergeFrom(const ::google::protobuf::Message& from) final;
-  void CopyFrom(const Response& from);
-  void MergeFrom(const Response& from);
-  void Clear() final;
-  bool IsInitialized() const final;
-
-  size_t ByteSizeLong() const final;
-  bool MergePartialFromCodedStream(
-      ::google::protobuf::io::CodedInputStream* input) final;
-  void SerializeWithCachedSizes(
-      ::google::protobuf::io::CodedOutputStream* output) const final;
-  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
-      bool deterministic, ::google::protobuf::uint8* target) const final;
-  int GetCachedSize() const final { return _cached_size_.Get(); }
-
-  private:
-  void SharedCtor();
-  void SharedDtor();
-  void SetCachedSize(int size) const final;
-  void InternalSwap(Response* other);
-  private:
-  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
-    return NULL;
-  }
-  inline void* MaybeArenaPtr() const {
-    return NULL;
-  }
-  public:
-
-  ::google::protobuf::Metadata GetMetadata() const final;
-
-  // nested types ----------------------------------------------------
-
-  // accessors -------------------------------------------------------
-
-  // string info = 2;
-  void clear_info();
-  static const int kInfoFieldNumber = 2;
-  const ::std::string& info() const;
-  void set_info(const ::std::string& value);
-  #if LANG_CXX11
-  void set_info(::std::string&& value);
-  #endif
-  void set_info(const char* value);
-  void set_info(const char* value, size_t size);
-  ::std::string* mutable_info();
-  ::std::string* release_info();
-  void set_allocated_info(::std::string* info);
-
-  // int32 ret = 1;
-  void clear_ret();
-  static const int kRetFieldNumber = 1;
-  ::google::protobuf::int32 ret() const;
-  void set_ret(::google::protobuf::int32 value);
-
-  // @@protoc_insertion_point(class_scope:JetStream.Response)
- private:
-
-  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
-  ::google::protobuf::internal::ArenaStringPtr info_;
-  ::google::protobuf::int32 ret_;
-  mutable ::google::protobuf::internal::CachedSize _cached_size_;
-  friend struct ::protobuf_def_2eproto::TableStruct;
-};
-// ===================================================================
-
-
-// ===================================================================
-
-#ifdef __GNUC__
-  #pragma GCC diagnostic push
-  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
-#endif  // __GNUC__
-// RequestCmd
-
-// int32 action = 1;
-inline void RequestCmd::clear_action() {
-  action_ = 0;
-}
-inline ::google::protobuf::int32 RequestCmd::action() const {
-  // @@protoc_insertion_point(field_get:JetStream.RequestCmd.action)
-  return action_;
-}
-inline void RequestCmd::set_action(::google::protobuf::int32 value) {
-  
-  action_ = value;
-  // @@protoc_insertion_point(field_set:JetStream.RequestCmd.action)
-}
-
-// -------------------------------------------------------------------
-
-// Response
-
-// int32 ret = 1;
-inline void Response::clear_ret() {
-  ret_ = 0;
-}
-inline ::google::protobuf::int32 Response::ret() const {
-  // @@protoc_insertion_point(field_get:JetStream.Response.ret)
-  return ret_;
-}
-inline void Response::set_ret(::google::protobuf::int32 value) {
-  
-  ret_ = value;
-  // @@protoc_insertion_point(field_set:JetStream.Response.ret)
-}
-
-// string info = 2;
-inline void Response::clear_info() {
-  info_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline const ::std::string& Response::info() const {
-  // @@protoc_insertion_point(field_get:JetStream.Response.info)
-  return info_.GetNoArena();
-}
-inline void Response::set_info(const ::std::string& value) {
-  
-  info_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
-  // @@protoc_insertion_point(field_set:JetStream.Response.info)
-}
-#if LANG_CXX11
-inline void Response::set_info(::std::string&& value) {
-  
-  info_.SetNoArena(
-    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
-  // @@protoc_insertion_point(field_set_rvalue:JetStream.Response.info)
-}
-#endif
-inline void Response::set_info(const char* value) {
-  GOOGLE_DCHECK(value != NULL);
-  
-  info_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
-  // @@protoc_insertion_point(field_set_char:JetStream.Response.info)
-}
-inline void Response::set_info(const char* value, size_t size) {
-  
-  info_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
-      ::std::string(reinterpret_cast<const char*>(value), size));
-  // @@protoc_insertion_point(field_set_pointer:JetStream.Response.info)
-}
-inline ::std::string* Response::mutable_info() {
-  
-  // @@protoc_insertion_point(field_mutable:JetStream.Response.info)
-  return info_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline ::std::string* Response::release_info() {
-  // @@protoc_insertion_point(field_release:JetStream.Response.info)
-  
-  return info_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline void Response::set_allocated_info(::std::string* info) {
-  if (info != NULL) {
-    
-  } else {
-    
-  }
-  info_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), info);
-  // @@protoc_insertion_point(field_set_allocated:JetStream.Response.info)
-}
-
-#ifdef __GNUC__
-  #pragma GCC diagnostic pop
-#endif  // __GNUC__
-// -------------------------------------------------------------------
-
-
-// @@protoc_insertion_point(namespace_scope)
-
-}  // namespace JetStream
-
-// @@protoc_insertion_point(global_scope)
-
-#endif  // PROTOBUF_INCLUDED_def_2eproto

+ 0 - 17
detect/stream/def.proto

@@ -1,17 +0,0 @@
-syntax = "proto3";
-package JetStream;
-
-message RequestCmd
-{
-  int32 action=1;  //
-}
-
-message Response{
-  int32 ret=1;
-  string info=2;
-}
-
-
-service NavExcutor{
-  rpc DetectStream(RequestCmd) returns(stream Response){}
-}

+ 0 - 1
detect/stream/proto.sh

@@ -1 +0,0 @@
-protoc --cpp_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` -I=./ def.proto

+ 0 - 69
detect/wheel-detector.cpp

@@ -1,69 +0,0 @@
-#include "wheel-detector.h"
-
-TensorrtWheelDetector::TensorrtWheelDetector(const std::string &enginfile){
-    yolov8_=new YOLOv8_seg(enginfile);
-    yolov8_->make_pipe(false);
-    imgsz_=cv::Size{640, 480};
-    seg_h_        = 120;
-    seg_w_        = 160;
-    seg_channels_ = 32;
-}
-
-TensorrtWheelDetector::~TensorrtWheelDetector(){
-    if(yolov8_!=nullptr){
-        delete yolov8_;
-        yolov8_=nullptr;
-    }
-
-}
-
-bool TensorrtWheelDetector::detect(cv::Mat& img,std::vector<Object>& objs){
-    if(yolov8_==nullptr){
-        return false;
-    }
-    if(img.size()!=imgsz_){
-        printf("imgsz required [%d,%d],but input is [%d,%d]\n",imgsz_.height,imgsz_.width,img.rows,img.cols);
-        return false;
-    }
-    yolov8_->copy_from_Mat(img, imgsz_);
-    yolov8_->infer();
-    float score_thres=0.9;
-    float iou_thres=0.65;
-    int topk=10;
-    yolov8_->postprocess(objs, score_thres, iou_thres, topk, seg_channels_, seg_h_, seg_w_);
-    return true;
-
-}
-
-bool TensorrtWheelDetector::detect(cv::Mat& img,std::vector<Object>& objs,cv::Mat& res){
-    if(detect(img,objs))
-    {
-        const std::vector<std::string> classes={"none","wheel"};
-        const std::vector<std::vector<unsigned int>> colors = {{0, 114, 189},   {0, 255, 0}};
-        const std::vector<std::vector<unsigned int>> mask_colors = {{255, 56, 56},  {255, 0, 0}};
-        yolov8_->draw_objects(img, res, objs, classes, colors, mask_colors);
-        return true;
-    }else{
-        return false;
-    }
-}
-
-std::vector<cv::Point> TensorrtWheelDetector::getPointsFromObj(Object obj){
-    std::vector<cv::Point> ret;
-    int x=int(obj.rect.x+0.5);
-    int y=int(obj.rect.y+0.5);
-    int width=int(obj.rect.width);
-    int height=int(obj.rect.height);
-    
-    printf("mask type:%d\n",obj.boxMask.type());
-    for(int i=0;i<height;++i){
-        for(int j=0;j<width;++j){
-            //printf("%d    ",obj.boxMask.at<uchar>(i,j));
-            if(obj.boxMask.at<uchar>(i,j)!=0){
-                ret.push_back(cv::Point(x+j,y+i));
-            }
-        }
-    }
-    //printf("\n");
-    return ret;
-}

+ 0 - 25
detect/wheel-detector.h

@@ -1,25 +0,0 @@
-#ifndef WHELL_DETECTOR__HH___
-#define WWHELL_DETECTOR__HH___
-#include "yolov8-seg.h"
-
-class TensorrtWheelDetector{
-public:
-    TensorrtWheelDetector(const std::string &enginfile);
-    ~TensorrtWheelDetector();
-
-
-    bool detect(cv::Mat& img,std::vector<Object>& objs);
-    bool detect(cv::Mat& img,std::vector<Object>& objs,cv::Mat& res);
-
-    static std::vector<cv::Point> getPointsFromObj(Object obj);
-
-private:
-    YOLOv8_seg*  yolov8_;
-    cv::Size     imgsz_;
-    int      seg_h_        = 120;
-    int      seg_w_        = 160;
-    int      seg_channels_ = 32;
-
-};
-
-#endif

+ 0 - 319
detect/yolov8-seg.cpp

@@ -1,319 +0,0 @@
-//
-// Created by ubuntu on 3/16/23.
-//
-
-#include "yolov8-seg.h"
-
-
-using namespace seg;
-
-YOLOv8_seg::YOLOv8_seg(const std::string& engine_file_path)
-{
-    std::ifstream file(engine_file_path, std::ios::binary);
-    assert(file.good());
-    file.seekg(0, std::ios::end);
-    auto size = file.tellg();
-    file.seekg(0, std::ios::beg);
-    char* trtModelStream = new char[size];
-    assert(trtModelStream);
-    file.read(trtModelStream, size);
-    file.close();
-    initLibNvInferPlugins(&this->gLogger, "");
-    this->runtime = nvinfer1::createInferRuntime(this->gLogger);
-    assert(this->runtime != nullptr);
-
-    this->engine = this->runtime->deserializeCudaEngine(trtModelStream, size);
-    assert(this->engine != nullptr);
-    delete[] trtModelStream;
-    this->context = this->engine->createExecutionContext();
-
-    assert(this->context != nullptr);
-    cudaStreamCreate(&this->stream);
-    this->num_bindings = this->engine->getNbBindings();
-
-    for (int i = 0; i < this->num_bindings; ++i) {
-        Binding            binding;
-        nvinfer1::Dims     dims;
-        nvinfer1::DataType dtype = this->engine->getBindingDataType(i);
-        std::string        name  = this->engine->getBindingName(i);
-        binding.name             = name;
-        binding.dsize            = type_to_size(dtype);
-
-        bool IsInput = engine->bindingIsInput(i);
-        if (IsInput) {
-            this->num_inputs += 1;
-            dims         = this->engine->getProfileDimensions(i, 0, nvinfer1::OptProfileSelector::kMAX);
-            binding.size = get_size_by_dims(dims);
-            binding.dims = dims;
-            this->input_bindings.push_back(binding);
-            // set max opt shape
-            this->context->setBindingDimensions(i, dims);
-        }
-        else {
-            dims         = this->context->getBindingDimensions(i);
-            binding.size = get_size_by_dims(dims);
-            binding.dims = dims;
-            this->output_bindings.push_back(binding);
-            this->num_outputs += 1;
-        }
-        // printf("name: %s, size: %ld, dims: %d %d %d %d %d\n", 
-        //         name.c_str(), binding.dsize, dims.nbDims, dims.d[0], dims.d[1], dims.d[2], dims.d[3]);
-    }
-}
-
-YOLOv8_seg::~YOLOv8_seg()
-{
-    this->context->destroy();
-    this->engine->destroy();
-    this->runtime->destroy();
-    cudaStreamDestroy(this->stream);
-    for (auto& ptr : this->device_ptrs) {
-        CHECK(cudaFree(ptr));
-    }
-
-    for (auto& ptr : this->host_ptrs) {
-        CHECK(cudaFreeHost(ptr));
-    }
-}
-
-void YOLOv8_seg::make_pipe(bool warmup)
-{
-
-    for (auto& bindings : this->input_bindings) {
-        void* d_ptr;
-        CHECK(cudaMalloc(&d_ptr, bindings.size * bindings.dsize));
-        this->device_ptrs.push_back(d_ptr);
-    }
-
-    for (auto& bindings : this->output_bindings) {
-        void * d_ptr, *h_ptr;
-        size_t size = bindings.size * bindings.dsize;
-        CHECK(cudaMalloc(&d_ptr, size));
-        CHECK(cudaHostAlloc(&h_ptr, size, 0));
-        this->device_ptrs.push_back(d_ptr);
-        this->host_ptrs.push_back(h_ptr);
-    }
-
-    if (warmup) {
-        for (int i = 0; i < 10; i++) {
-            for (auto& bindings : this->input_bindings) {
-                size_t size  = bindings.size * bindings.dsize;
-                void*  h_ptr = malloc(size);
-                memset(h_ptr, 0, size);
-                CHECK(cudaMemcpyAsync(this->device_ptrs[0], h_ptr, size, cudaMemcpyHostToDevice, this->stream));
-                free(h_ptr);
-            }
-            this->infer();
-        }
-        printf("model warmup 10 times\n");
-    }
-}
-
-void YOLOv8_seg::letterbox(const cv::Mat& image, cv::Mat& out, cv::Size& size)
-{
-    const float inp_h  = size.height;
-    const float inp_w  = size.width;
-    float       height = image.rows;
-    float       width  = image.cols;
-
-    float r    = std::min(inp_h / height, inp_w / width);
-    int   padw = std::round(width * r);
-    int   padh = std::round(height * r);
-
-    cv::Mat tmp;
-    if ((int)width != padw || (int)height != padh) {
-        cv::resize(image, tmp, cv::Size(padw, padh));
-    }
-    else {
-        tmp = image.clone();
-    }
-
-    float dw = inp_w - padw;
-    float dh = inp_h - padh;
-
-    dw /= 2.0f;
-    dh /= 2.0f;
-    int top    = int(std::round(dh - 0.1f));
-    int bottom = int(std::round(dh + 0.1f));
-    int left   = int(std::round(dw - 0.1f));
-    int right  = int(std::round(dw + 0.1f));
-
-    cv::copyMakeBorder(tmp, tmp, top, bottom, left, right, cv::BORDER_CONSTANT, {114, 114, 114});
-
-    cv::dnn::blobFromImage(tmp, out, 1 / 255.f, cv::Size(), cv::Scalar(0, 0, 0), true, false, CV_32F);
-    this->pparam.ratio  = 1 / r;
-    this->pparam.dw     = dw;
-    this->pparam.dh     = dh;
-    this->pparam.height = height;
-    this->pparam.width  = width;
-}
-
-void YOLOv8_seg::copy_from_Mat(const cv::Mat& image)
-{
-    cv::Mat  nchw;
-    auto&    in_binding = this->input_bindings[0];
-    auto     width      = in_binding.dims.d[3];
-    auto     height     = in_binding.dims.d[2];
-    cv::Size size{width, height};
-    this->letterbox(image, nchw, size);
-
-    this->context->setBindingDimensions(0, nvinfer1::Dims{4, {1, 3, height, width}});
-
-    CHECK(cudaMemcpyAsync(
-        this->device_ptrs[0], nchw.ptr<float>(), nchw.total() * nchw.elemSize(), cudaMemcpyHostToDevice, this->stream));
-}
-
-void YOLOv8_seg::copy_from_Mat(const cv::Mat& image, cv::Size& size)
-{
-    cv::Mat nchw;
-    this->letterbox(image, nchw, size);
-    this->context->setBindingDimensions(0, nvinfer1::Dims{4, {1, 3, size.height, size.width}});
-    CHECK(cudaMemcpyAsync(
-        this->device_ptrs[0], nchw.ptr<float>(), nchw.total() * nchw.elemSize(), cudaMemcpyHostToDevice, this->stream));
-}
-
-void YOLOv8_seg::infer()
-{
-
-    this->context->enqueueV2(this->device_ptrs.data(), this->stream, nullptr);
-    for (int i = 0; i < this->num_outputs; i++) {
-        size_t osize = this->output_bindings[i].size * this->output_bindings[i].dsize;
-        CHECK(cudaMemcpyAsync(
-            this->host_ptrs[i], this->device_ptrs[i + this->num_inputs], osize, cudaMemcpyDeviceToHost, this->stream));
-    }
-    cudaStreamSynchronize(this->stream);
-}
-
-void YOLOv8_seg::postprocess(
-    std::vector<Object>& objs, float score_thres, float iou_thres, int topk, int seg_channels, int seg_h, int seg_w)
-{
-    objs.clear();
-    auto input_h      = this->input_bindings[0].dims.d[2];
-    auto input_w      = this->input_bindings[0].dims.d[3];
-    auto num_anchors  = this->output_bindings[0].dims.d[1];
-    auto num_channels = this->output_bindings[0].dims.d[2];
-
-    auto& dw     = this->pparam.dw;
-    auto& dh     = this->pparam.dh;
-    auto& width  = this->pparam.width;
-    auto& height = this->pparam.height;
-    auto& ratio  = this->pparam.ratio;
-
-    auto*   output = static_cast<float*>(this->host_ptrs[0]);
-    cv::Mat protos = cv::Mat(seg_channels, seg_h * seg_w, CV_32F, static_cast<float*>(this->host_ptrs[1]));
-
-    std::vector<int>      labels;
-    std::vector<float>    scores;
-    std::vector<cv::Rect> bboxes;
-    std::vector<cv::Mat>  mask_confs;
-    std::vector<int>      indices;
-
-    for (int i = 0; i < num_anchors; i++) {
-        float* ptr   = output + i * num_channels;
-        float  score = *(ptr + 4);
-		
-         /*if (score > score_thres) {
-             printf("num_channels: %d, score: %f\n", num_channels, score);
-         }*/
-	
-        if (score > score_thres) {
-            float x0 = *ptr++ - dw;
-            float y0 = *ptr++ - dh;
-            float x1 = *ptr++ - dw;
-            float y1 = *ptr++ - dh;
-
-            x0 = clamp(x0 * ratio, 0.f, width);
-            y0 = clamp(y0 * ratio, 0.f, height);
-            x1 = clamp(x1 * ratio, 0.f, width);
-            y1 = clamp(y1 * ratio, 0.f, height);
-
-            int     label     = *(++ptr);
-            cv::Mat mask_conf = cv::Mat(1, seg_channels, CV_32F, ++ptr);
-            mask_confs.push_back(mask_conf);
-            labels.push_back(label);
-            scores.push_back(score);
-            bboxes.push_back(cv::Rect_<float>(x0, y0, x1 - x0, y1 - y0));
-        }
-    }
-
-#if defined(BATCHED_NMS)
-    cv::dnn::NMSBoxesBatched(bboxes, scores, labels, score_thres, iou_thres, indices);
-#else
-    cv::dnn::NMSBoxes(bboxes, scores, score_thres, iou_thres, indices);
-#endif
-
-    cv::Mat masks;
-    int     cnt = 0;
-    for (auto& i : indices) {
-        if (cnt >= topk) {
-            break;
-        }
-        cv::Rect tmp = bboxes[i];
-        Object   obj;
-        obj.label = labels[i];
-        obj.rect  = tmp;
-        obj.prob  = scores[i];
-        masks.push_back(mask_confs[i]);
-        objs.push_back(obj);
-        cnt += 1;
-    }
-    if (masks.empty()) {
-        // masks is empty
-    }
-    else {
-        cv::Mat matmulRes = (masks * protos).t();
-        cv::Mat maskMat   = matmulRes.reshape(indices.size(), {seg_h, seg_w});
-
-        std::vector<cv::Mat> maskChannels;
-        cv::split(maskMat, maskChannels);
-        int scale_dw = dw / input_w * seg_w;
-        int scale_dh = dh / input_h * seg_h;
-
-        cv::Rect roi(scale_dw, scale_dh, seg_w - 2 * scale_dw, seg_h - 2 * scale_dh);
-
-        for (int i = 0; i < indices.size(); i++) {
-            cv::Mat dest, mask;
-            cv::exp(-maskChannels[i], dest);
-            dest = 1.0 / (1.0 + dest);
-            dest = dest(roi);
-            cv::resize(dest, mask, cv::Size((int)width, (int)height), cv::INTER_LINEAR);
-            objs[i].boxMask = mask(objs[i].rect) > 0.5f;
-        }
-    }
-}
-
-void YOLOv8_seg::draw_objects(const cv::Mat&                                image,
-                              cv::Mat&                                      res,
-                              const std::vector<Object>&                    objs,
-                              const std::vector<std::string>&               CLASS_NAMES,
-                              const std::vector<std::vector<unsigned int>>& COLORS,
-                              const std::vector<std::vector<unsigned int>>& MASK_COLORS)
-{
-    res          = image.clone();
-    cv::Mat mask = image.clone();
-    for (auto& obj : objs) {
-        int        idx   = obj.label;
-        cv::Scalar color = cv::Scalar(COLORS[idx][0], COLORS[idx][1], COLORS[idx][2]);
-        cv::Scalar mask_color =
-            cv::Scalar(MASK_COLORS[idx % 20][0], MASK_COLORS[idx % 20][1], MASK_COLORS[idx % 20][2]);
-        cv::rectangle(res, obj.rect, color, 2);
-
-        char text[256];
-        sprintf(text, "%s %.1f%%", CLASS_NAMES[idx].c_str(), obj.prob * 100);
-        mask(obj.rect).setTo(mask_color, obj.boxMask);
-
-        int      baseLine   = 0;
-        cv::Size label_size = cv::getTextSize(text, cv::FONT_HERSHEY_SIMPLEX, 0.4, 1, &baseLine);
-
-        int x = (int)obj.rect.x;
-        int y = (int)obj.rect.y + 1;
-
-        if (y > res.rows)
-            y = res.rows;
-
-        cv::rectangle(res, cv::Rect(x, y, label_size.width, label_size.height + baseLine), {0, 0, 255}, -1);
-
-        cv::putText(res, text, cv::Point(x, y + label_size.height), cv::FONT_HERSHEY_SIMPLEX, 0.4, {255, 255, 255}, 1);
-    }
-    cv::addWeighted(res, 0.5, mask, 0.8, 1, res);
-}

+ 0 - 53
detect/yolov8-seg.h

@@ -1,53 +0,0 @@
-//
-// Created by ubuntu on 3/16/23.
-//
-#ifndef JETSON_SEGMENT_YOLOV8_SEG_HPP
-#define JETSON_SEGMENT_YOLOV8_SEG_HPP
-#include "NvInferPlugin.h"
-#include "common.hpp"
-#include <fstream>
-
-using namespace seg;
-
-class YOLOv8_seg {
-public:
-    explicit YOLOv8_seg(const std::string& engine_file_path);
-    ~YOLOv8_seg();
-
-    void                 make_pipe(bool warmup = true);
-    void                 copy_from_Mat(const cv::Mat& image);
-    void                 copy_from_Mat(const cv::Mat& image, cv::Size& size);
-    void                 letterbox(const cv::Mat& image, cv::Mat& out, cv::Size& size);
-    void                 infer();
-    void                 postprocess(std::vector<Object>& objs,
-                                     float                score_thres  = 0.25f,
-                                     float                iou_thres    = 0.65f,
-                                     int                  topk         = 100,
-                                     int                  seg_channels = 32,
-                                     int                  seg_h        = 160,
-                                     int                  seg_w        = 160);
-    static void          draw_objects(const cv::Mat&                                image,
-                                      cv::Mat&                                      res,
-                                      const std::vector<Object>&                    objs,
-                                      const std::vector<std::string>&               CLASS_NAMES,
-                                      const std::vector<std::vector<unsigned int>>& COLORS,
-                                      const std::vector<std::vector<unsigned int>>& MASK_COLORS);
-    int                  num_bindings;
-    int                  num_inputs  = 0;
-    int                  num_outputs = 0;
-    std::vector<Binding> input_bindings;
-    std::vector<Binding> output_bindings;
-    std::vector<void*>   host_ptrs;
-    std::vector<void*>   device_ptrs;
-
-    PreParam pparam;
-
-private:
-    nvinfer1::ICudaEngine*       engine  = nullptr;
-    nvinfer1::IRuntime*          runtime = nullptr;
-    nvinfer1::IExecutionContext* context = nullptr;
-    cudaStream_t                 stream  = nullptr;
-    Logger                       gLogger{nvinfer1::ILogger::Severity::kERROR};
-};
-
-#endif  // JETSON_SEGMENT_YOLOV8_SEG_HPP

+ 0 - 183
model/inference.cpp

@@ -1,183 +0,0 @@
-#include "inference.h"
-
-Inference::Inference(const std::string &onnxModelPath, const cv::Size &modelInputShape, const std::string &classesTxtFile, const bool &runWithCuda)
-{
-    modelPath = onnxModelPath;
-    modelShape = modelInputShape;
-    classesPath = classesTxtFile;
-    cudaEnabled = runWithCuda;
-
-    loadOnnxNetwork();
-    // loadClassesFromFile(); The classes are hard-coded for this example
-}
-
-std::vector<Detection> Inference::runInference(const cv::Mat &input)
-{
-    cv::Mat modelInput = input;
-    if (letterBoxForSquare && modelShape.width == modelShape.height)
-        modelInput = formatToSquare(modelInput);
-
-    cv::Mat blob;
-    cv::dnn::blobFromImage(modelInput, blob, 1.0/255.0, modelShape, cv::Scalar(), true, false);
-    net.setInput(blob);
-
-    std::vector<cv::Mat> outputs;
-    net.forward(outputs, net.getUnconnectedOutLayersNames());
-
-    int rows = outputs[0].size[1];
-    int dimensions = outputs[0].size[2];
-
-    bool yolov8 = false;
-    // yolov5 has an output of shape (batchSize, 25200, 85) (Num classes + box[x,y,w,h] + confidence[c])
-    // yolov8 has an output of shape (batchSize, 84,  8400) (Num classes + box[x,y,w,h])
-    if (dimensions > rows) // Check if the shape[2] is more than shape[1] (yolov8)
-    {
-        yolov8 = true;
-        rows = outputs[0].size[2];
-        dimensions = outputs[0].size[1];
-
-        outputs[0] = outputs[0].reshape(1, dimensions);
-        cv::transpose(outputs[0], outputs[0]);
-    }
-    float *data = (float *)outputs[0].data;
-
-    float x_factor = modelInput.cols / modelShape.width;
-    float y_factor = modelInput.rows / modelShape.height;
-
-    std::vector<int> class_ids;
-    std::vector<float> confidences;
-    std::vector<cv::Rect> boxes;
-
-    for (int i = 0; i < rows; ++i)
-    {
-        if (yolov8)
-        {
-            float *classes_scores = data+4;
-
-            cv::Mat scores(1, classes.size(), CV_32FC1, classes_scores);
-            cv::Point class_id;
-            double maxClassScore;
-
-            minMaxLoc(scores, 0, &maxClassScore, 0, &class_id);
-
-            if (maxClassScore > modelScoreThreshold)
-            {
-                confidences.push_back(maxClassScore);
-                class_ids.push_back(class_id.x);
-
-                float x = data[0];
-                float y = data[1];
-                float w = data[2];
-                float h = data[3];
-
-                int left = int((x - 0.5 * w) * x_factor);
-                int top = int((y - 0.5 * h) * y_factor);
-
-                int width = int(w * x_factor);
-                int height = int(h * y_factor);
-
-                boxes.push_back(cv::Rect(left, top, width, height));
-            }
-        }
-        else // yolov5
-        {
-            float confidence = data[4];
-
-            if (confidence >= modelConfidenceThreshold)
-            {
-                float *classes_scores = data+5;
-
-                cv::Mat scores(1, classes.size(), CV_32FC1, classes_scores);
-                cv::Point class_id;
-                double max_class_score;
-
-                minMaxLoc(scores, 0, &max_class_score, 0, &class_id);
-
-                if (max_class_score > modelScoreThreshold)
-                {
-                    confidences.push_back(confidence);
-                    class_ids.push_back(class_id.x);
-
-                    float x = data[0];
-                    float y = data[1];
-                    float w = data[2];
-                    float h = data[3];
-
-                    int left = int((x - 0.5 * w) * x_factor);
-                    int top = int((y - 0.5 * h) * y_factor);
-
-                    int width = int(w * x_factor);
-                    int height = int(h * y_factor);
-
-                    boxes.push_back(cv::Rect(left, top, width, height));
-                }
-            }
-        }
-
-        data += dimensions;
-    }
-
-    std::vector<int> nms_result;
-    cv::dnn::NMSBoxes(boxes, confidences, modelScoreThreshold, modelNMSThreshold, nms_result);
-
-    std::vector<Detection> detections{};
-    for (unsigned long i = 0; i < nms_result.size(); ++i)
-    {
-        int idx = nms_result[i];
-
-        Detection result;
-        result.class_id = class_ids[idx];
-        result.confidence = confidences[idx];
-
-        std::random_device rd;
-        std::mt19937 gen(rd());
-        std::uniform_int_distribution<int> dis(100, 255);
-        result.color = cv::Scalar(dis(gen),
-                                  dis(gen),
-                                  dis(gen));
-
-        result.className = classes[result.class_id];
-        result.box = boxes[idx];
-
-        detections.push_back(result);
-    }
-
-    return detections;
-}
-
-void Inference::loadClassesFromFile()
-{
-    std::ifstream inputFile(classesPath);
-    if (inputFile.is_open())
-    {
-        std::string classLine;
-        while (std::getline(inputFile, classLine))
-            classes.push_back(classLine);
-        inputFile.close();
-    }
-}
-
-void Inference::loadOnnxNetwork()
-{
-    net = cv::dnn::readNetFromONNX(modelPath);
-    if (cudaEnabled)
-    {
-        net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
-        net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
-    }
-    else
-    {
-        net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
-        net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
-    }
-}
-
-cv::Mat Inference::formatToSquare(const cv::Mat &source)
-{
-    int col = source.cols;
-    int row = source.rows;
-    int _max = MAX(col, row);
-    cv::Mat result = cv::Mat::zeros(_max, _max, CV_8UC3);
-    source.copyTo(result(cv::Rect(0, 0, col, row)));
-    return result;
-}

+ 0 - 50
model/inference.h

@@ -1,50 +0,0 @@
-#pragma once
-
-// Cpp native
-#include <fstream>
-#include <vector>
-#include <string>
-#include <random>
-
-// OpenCV / DNN / Inference
-#include <opencv2/imgproc.hpp>
-#include <opencv2/opencv.hpp>
-#include <opencv2/dnn.hpp>
-
-struct Detection
-{
-    int class_id{0};
-    std::string className{};
-    float confidence{0.0};
-    cv::Scalar color{};
-    cv::Rect box{};
-};
-
-class Inference
-{
-public:
-    Inference(const std::string &onnxModelPath, const cv::Size &modelInputShape = {640, 640}, const std::string &classesTxtFile = "", const bool &runWithCuda = false);
-    std::vector<Detection> runInference(const cv::Mat &input);
-
-private:
-    void loadClassesFromFile();
-    void loadOnnxNetwork();
-    cv::Mat formatToSquare(const cv::Mat &source);
-
-    std::string modelPath{};
-    std::string classesPath{};
-    bool cudaEnabled{};
-
-    std::vector<std::string> classes{"car", "wheel"};
-
-    cv::Size2f modelShape{};
-
-    float modelConfidenceThreshold {0.25};
-    float modelScoreThreshold      {0.45};
-    float modelNMSThreshold        {0.50};
-
-    bool letterBoxForSquare = true;
-
-    cv::dnn::Net net;
-};
-

+ 1 - 1
tof3d_manager.cpp

@@ -8,7 +8,7 @@ Error_manager tof3dManager::init() {
     if (loadProtobufFile(ETC_PATH PROJECT_NAME "/tof3d_manager.json", m_tof_etc) == SUCCESS) {
         LOG(INFO) << m_tof_etc.DebugString();
     } else {
-        return {FAILED, NEGLIGIBLE_ERROR, "tof3dManager read param form %s error.", ETC_PATH"Tof3d/tof3d_manager.json"};
+        return {FAILED, NEGLIGIBLE_ERROR, "tof3dManager read param form %s error.", ETC_PATH PROJECT_NAME "/tof3d_manager.json"};
     }
 
     auto list = m_tof_etc.vzense_tof3d_devices();

+ 291 - 158
vzense/device_tof3d.cpp

@@ -7,30 +7,40 @@ Error_manager DeviceTof3D::Init(const VzEtcMap &tp_tof3d, bool search) {
         return {TOF3D_VZENSE_DEVICE_INIT_FAILED, MAJOR_ERROR, "VzInitialize failed status: %d", m_vz_status};
     }
 
+    detector = new TensorrtWheelDetector(ETC_PATH PROJECT_NAME "/model.onnx", ETC_PATH PROJECT_NAME "/class.txt");
+
     loadEtc(tp_tof3d);
 
     if (search) {
         SearchDevice(5);
     }
 
+    cv::namedWindow("ret", cv::WINDOW_AUTOSIZE);
+
     ConnectAllEtcDevices();
 
     VZ_SetHotPlugStatusCallback(DeviceTof3D::HotPlugStateCallback, &mp_device_info);
 
     //启动 线程。
     for (auto &info: mp_device_info) {
-        setTof3dParams(info.second.etc.ip());
-        getTof3dParams(info.second.etc.ip());
+        if (!info.second->etc.enable_device()) {
+            continue;
+        }
+        setTof3dParams(info.second->etc.ip());
+        getTof3dParams(info.second->etc.ip());
         mp_thread_info.insert(std::pair<std::string, ThreadInfo>(
                 info.first, ThreadInfo(new std::thread(&DeviceTof3D::receiveFrameThread, this, info.first),
                                        new Thread_condition()
-                                       )
-                ));
+                )
+        ));
     }
 
     for (auto &t: mp_thread_info) {
         t.second.condit->notify_all(true);
     }
+    detect_thread.t = new std::thread(&DeviceTof3D::detectThread, this);
+    detect_thread.condit = new Thread_condition();
+    detect_thread.condit->notify_all(true);
 
     return {TOF3D_VZENSE_DEVICE_INIT_SUCCESS, NORMAL, "VzInitialize success."};
 }
@@ -63,20 +73,17 @@ Error_manager DeviceTof3D::SearchDevice(const double &time) {
         for (int i = 0; i < deviceCount; i++) {
             auto iter = mp_device_info.find(pDeviceListInfo[i].ip);
             if (iter == mp_device_info.end()) {
-                mp_device_info.insert(std::pair<std::string, tof3dVzenseInfo>(pDeviceListInfo[i].ip, tof3dVzenseInfo()));
+                mp_device_info.insert(
+                        std::pair<std::string, tof3dVzenseInfo *>(pDeviceListInfo[i].ip, new tof3dVzenseInfo()));
                 iter = mp_device_info.find(pDeviceListInfo[i].ip);
             }
-            iter->second.info = pDeviceListInfo[i];
+            iter->second->info = pDeviceListInfo[i];
             LOG(INFO) << "Found device: " << pDeviceListInfo[i].ip;
         }
     }
     return {};
 }
 
-void DeviceTof3D::run() {
-
-}
-
 Error_manager DeviceTof3D::ConnectDevice(const std::string &ip, bool open_stream) {
     auto iter = mp_device_info.find(ip);
     if (iter == mp_device_info.end()) {
@@ -84,24 +91,24 @@ Error_manager DeviceTof3D::ConnectDevice(const std::string &ip, bool open_stream
         return {}; //TODO
     }
 
-    m_vz_status = VZ_OpenDeviceByIP(iter->second.info.ip, &iter->second.handle);
+    m_vz_status = VZ_OpenDeviceByIP(iter->second->info.ip, &iter->second->handle);
     if (m_vz_status != VzReturnStatus::VzRetOK) {
-        iter->second.is_connect = false;
+        iter->second->is_connect = false;
         LOG(WARNING) << "OpenDevice " << ip << " failed status:" << m_vz_status;
         return {}; //TODO
     } else {
-        iter->second.is_connect = true;
+        iter->second->is_connect = true;
         LOG(INFO) << "OpenDevice " << ip << " success status:" << m_vz_status;
     }
 
     if (open_stream) {
-        m_vz_status = VZ_StartStream(iter->second.handle);
+        m_vz_status = VZ_StartStream(iter->second->handle);
         if (m_vz_status != VzReturnStatus::VzRetOK) {
-            iter->second.is_start_stream = false;
+            iter->second->is_start_stream = false;
             LOG(WARNING) << "VZ_StartStream " << ip << " failed status:" << m_vz_status;
             return {};
         } else {
-            iter->second.is_start_stream = true;
+            iter->second->is_start_stream = true;
             LOG(INFO) << "VZ_StartStream " << ip << " success status:" << m_vz_status;
         }
     }
@@ -111,7 +118,7 @@ Error_manager DeviceTof3D::ConnectDevice(const std::string &ip, bool open_stream
 
 Error_manager DeviceTof3D::ConnectAllEtcDevices(bool open_stream) {
     for (auto &device: mp_device_info) {
-        if (device.second.etc.enable_device()) {
+        if (device.second->etc.enable_device()) {
             ConnectDevice(device.first, open_stream);
         }
     }
@@ -131,21 +138,21 @@ Error_manager DeviceTof3D::DisConnectDevice(const std::string &ip) {
         return {}; //TODO
     }
 
-    m_vz_status = VZ_StopStream(iter->second.handle);
+    m_vz_status = VZ_StopStream(iter->second->handle);
     if (m_vz_status != VzReturnStatus::VzRetOK) {
-        iter->second.is_start_stream = true;
+        iter->second->is_start_stream = true;
         LOG(WARNING) << "VZ_StopStream failed status:" << m_vz_status;
     } else {
-        iter->second.is_start_stream = false;
+        iter->second->is_start_stream = false;
         LOG(INFO) << "VZ_StopStream success status:" << m_vz_status;
     }
 
-    m_vz_status = VZ_CloseDevice(&iter->second.handle);
+    m_vz_status = VZ_CloseDevice(&iter->second->handle);
     if (m_vz_status != VzReturnStatus::VzRetOK) {
-        iter->second.is_connect = true;
+        iter->second->is_connect = true;
         LOG(WARNING) << "VZ_CloseDevice failed status:" << m_vz_status;
     } else {
-        iter->second.is_connect = false;
+        iter->second->is_connect = false;
         LOG(INFO) << "VZ_CloseDevice success status:" << m_vz_status;
     }
 
@@ -154,7 +161,7 @@ Error_manager DeviceTof3D::DisConnectDevice(const std::string &ip) {
 
 Error_manager DeviceTof3D::DisConnectAllEtcDevices() {
     for (auto &device: mp_device_info) {
-        if (device.second.etc.enable_device()) {
+        if (device.second->etc.enable_device()) {
             DisConnectDevice(device.first);
         }
     }
@@ -174,22 +181,22 @@ Error_manager DeviceTof3D::getDepthFrame(const std::string &ip, VzFrame &depthFr
         return {FAILED, NORMAL, "Device %s not in list, can\'t get depth frame.", ip.c_str()}; //TODO
     }
 
-    if (iter->second.handle == nullptr || !iter->second.is_connect) {
-        if(ConnectDevice(ip, true) != SUCCESS) {
+    if (iter->second->handle == nullptr || !iter->second->is_connect) {
+        if (ConnectDevice(ip, true) != SUCCESS) {
             return {FAILED, NORMAL, "Open device %s failed, stop get depth frame.", ip.c_str()};
         }
     }
 
     VzFrameReady frameReady = {0};
-    m_vz_status = VZ_GetFrameReady(iter->second.handle, 100, &frameReady);
+    m_vz_status = VZ_GetFrameReady(iter->second->handle, iter->second->etc.bip().exposure_time(), &frameReady);
 
     if (m_vz_status != VzRetOK) {
         LOG(WARNING) << ip << "  VZ_GetFrameReady failed status:" << m_vz_status;
-        return {}; //TODO
+        return {FAILED, MINOR_ERROR, "%s VZ_GetFrameReady failed status %d!", ip.c_str(), m_vz_status}; //TODO
     }
 
     if (1 == frameReady.depth) {
-        m_vz_status = VZ_GetFrame(iter->second.handle, VzDepthFrame, &depthFrame);
+        m_vz_status = VZ_GetFrame(iter->second->handle, VzDepthFrame, &depthFrame);
 
         if (m_vz_status == VzRetOK && depthFrame.pFrameData != nullptr) {
 //            LOG(INFO) << ip << " VZ_GetFrame VzDepthFrame success:" << m_vz_status;
@@ -207,14 +214,14 @@ Error_manager DeviceTof3D::getIrFrame(const std::string &ip, VzFrame &irFrame) {
         return {FAILED, NORMAL, "Device %s not in list, can\'t get ir frame.", ip.c_str()}; //TODO
     }
 
-    if (iter->second.handle == nullptr || !iter->second.is_connect) {
-        if(ConnectDevice(ip, true) != SUCCESS) {
+    if (iter->second->handle == nullptr || !iter->second->is_connect) {
+        if (ConnectDevice(ip, true) != SUCCESS) {
             return {FAILED, NORMAL, "Open device %s failed, stop get ir frame.", ip.c_str()};
         }
     }
 
     VzFrameReady frameReady = {0};
-    m_vz_status = VZ_GetFrameReady(iter->second.handle, 100, &frameReady);
+    m_vz_status = VZ_GetFrameReady(iter->second->handle, 100, &frameReady);
 
     if (m_vz_status != VzRetOK) {
         LOG(WARNING) << ip << "  VZ_GetFrameReady failed status:" << m_vz_status;
@@ -222,7 +229,7 @@ Error_manager DeviceTof3D::getIrFrame(const std::string &ip, VzFrame &irFrame) {
     }
 
     if (1 == frameReady.ir) {
-        m_vz_status = VZ_GetFrame(iter->second.handle, VzIRFrame, &irFrame);
+        m_vz_status = VZ_GetFrame(iter->second->handle, VzIRFrame, &irFrame);
 
         if (m_vz_status == VzRetOK && irFrame.pFrameData != nullptr) {
             LOG(INFO) << ip << "VZ_GetFrame VzIrFrame success:" << m_vz_status;
@@ -240,25 +247,26 @@ Error_manager DeviceTof3D::getDepthAndIrPicture(const std::string &ip, VzFrame &
         return {FAILED, NORMAL, "Device %s not in list, can\'t get depth and ir frame.", ip.c_str()}; //TODO
     }
 
-    if (iter->second.handle == nullptr || !iter->second.is_connect) {
-        if(ConnectDevice(ip, true) != SUCCESS) {
+    if (iter->second->handle == nullptr || !iter->second->is_connect) {
+        if (ConnectDevice(ip, true) != SUCCESS) {
             return {FAILED, NORMAL, "Open device %s failed, stop get depth and ir frame.", ip.c_str()};
         }
     }
 
     Error_manager ret;
     VzFrameReady frameReady = {0};
-    m_vz_status = VZ_GetFrameReady(iter->second.handle, 100, &frameReady);
+    m_vz_status = VZ_GetFrameReady(iter->second->handle, 100, &frameReady);
 
     if (m_vz_status != VzRetOK) {
         LOG(WARNING) << ip << "  VZ_GetFrameReady failed status:" << m_vz_status;
-        ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrameReady failed status: %d.", ip.c_str(), m_vz_status});    //TODO
+        ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrameReady failed status: %d.", ip.c_str(),
+                                  m_vz_status});    //TODO
         return ret;
     }
 
     //Get depth frame, depth frame only output in following data mode
     if (1 == frameReady.depth) {
-        m_vz_status = VZ_GetFrame(iter->second.handle, VzDepthFrame, &depthFrame);
+        m_vz_status = VZ_GetFrame(iter->second->handle, VzDepthFrame, &depthFrame);
 
         if (m_vz_status == VzRetOK && depthFrame.pFrameData != nullptr) {
             LOG(INFO) << ip << " frameIndex :" << depthFrame.frameIndex;
@@ -269,19 +277,23 @@ Error_manager DeviceTof3D::getDepthAndIrPicture(const std::string &ip, VzFrame &
             LOG(INFO) << ip << "VZ_GetFrame VzIrFrame status:" << m_vz_status;
         }
     } else {
-        ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrameReady depth not ready: %d.", ip.c_str(), frameReady.depth});
+        ret.compare_and_merge_up(
+                {FAILED, MINOR_ERROR, "Device %s VZ_GetFrameReady depth not ready: %d.", ip.c_str(), frameReady.depth});
     }
 
     if (1 == frameReady.ir) {
-        m_vz_status = VZ_GetFrame(iter->second.handle, VzIRFrame, &irFrame);
+        m_vz_status = VZ_GetFrame(iter->second->handle, VzIRFrame, &irFrame);
         if (m_vz_status == VzRetOK && irFrame.pFrameData != nullptr) {
             LOG(INFO) << ip << " frameIndex :" << irFrame.frameIndex;
         } else {
-            ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrame VzIrFrame failed status: %d.", ip.c_str(), m_vz_status});    //TODO
+            ret.compare_and_merge_up(
+                    {FAILED, MINOR_ERROR, "Device %s VZ_GetFrame VzIrFrame failed status: %d.", ip.c_str(),
+                     m_vz_status});    //TODO
             LOG(INFO) << ip << "VZ_GetFrame VzIrFrame status:" << m_vz_status;
         }
     } else {
-        ret.compare_and_merge_up({FAILED, NORMAL, "Device %s VZ_GetFrameReady ir not ready: %d.", ip.c_str(), frameReady.depth});
+        ret.compare_and_merge_up(
+                {FAILED, NORMAL, "Device %s VZ_GetFrameReady ir not ready: %d.", ip.c_str(), frameReady.depth});
     }
 
     return ret;
@@ -293,14 +305,14 @@ Error_manager DeviceTof3D::getDepthPointCloud(const std::string &ip, pcl::PointC
         return {FAILED, NORMAL, "Device %s not in list, can\'t get point cloud.", ip.c_str()}; //TODO
     }
 
-    if (iter->second.handle == nullptr || !iter->second.is_connect) {
-        if(ConnectDevice(ip, true) != SUCCESS) {
+    if (iter->second->handle == nullptr || !iter->second->is_connect) {
+        if (ConnectDevice(ip, true) != SUCCESS) {
             return {FAILED, NORMAL, "Open device %s failed, stop get point cloud.", ip.c_str()};
         }
     }
 
     VzFrameReady frameReady = {0};
-    m_vz_status = VZ_GetFrameReady(iter->second.handle, 100, &frameReady);
+    m_vz_status = VZ_GetFrameReady(iter->second->handle, 100, &frameReady);
 
     if (m_vz_status != VzRetOK) {
         LOG(WARNING) << ip << "  VZ_GetFrameReady failed status:" << m_vz_status;
@@ -310,7 +322,7 @@ Error_manager DeviceTof3D::getDepthPointCloud(const std::string &ip, pcl::PointC
     //Get depth frame, depth frame only output in following data mode
     if (1 == frameReady.depth) {
         VzFrame depthFrame = {0};
-        m_vz_status = VZ_GetFrame(iter->second.handle, VzDepthFrame, &depthFrame);
+        m_vz_status = VZ_GetFrame(iter->second->handle, VzDepthFrame, &depthFrame);
 
         if (m_vz_status == VzRetOK && depthFrame.pFrameData != nullptr) {
             LOG(INFO) << ip << " frameIndex :" << depthFrame.frameIndex;
@@ -319,8 +331,8 @@ Error_manager DeviceTof3D::getDepthPointCloud(const std::string &ip, pcl::PointC
             const int len = srcFrame.width * srcFrame.height;
             VzVector3f *worldV = new VzVector3f[len];
 
-            m_vz_status = VZ_ConvertDepthFrameToPointCloudVector(iter->second.handle, &srcFrame,
-                                                   worldV);
+            m_vz_status = VZ_ConvertDepthFrameToPointCloudVector(iter->second->handle, &srcFrame,
+                                                                 worldV);
 
             if (m_vz_status == VzRetOK) {
                 cloud->clear();
@@ -342,7 +354,8 @@ Error_manager DeviceTof3D::getDepthPointCloud(const std::string &ip, pcl::PointC
     return {};
 }
 
-Error_manager DeviceTof3D::DepthFrame2PointCloud(const std::string &ip, VzFrame &depthFrame, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud) {
+Error_manager DeviceTof3D::DepthFrame2PointCloud(const std::string &ip, VzFrame &depthFrame,
+                                                 pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud) {
 //    if (depthFrame.frameType != VzDepthFrame) {
 //        return {};
 //    }
@@ -428,30 +441,63 @@ Error_manager DeviceTof3D::IrFrame2Mat(VzFrame &frame, cv::Mat &mat) {
 }
 
 #include <sys/stat.h>
+
 void DeviceTof3D::receiveFrameThread(const std::string &ip) {
     LOG(INFO) << ip << " in thread " << std::this_thread::get_id();
     auto iter = mp_device_info.find(ip);
     auto t_iter = mp_thread_info.find(ip);
-    TensorrtWheelDetector detector(ETC_PATH PROJECT_NAME "/best.engine");
 
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_car_cloud(new pcl::PointCloud<pcl::PointXYZ>);
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_wheel_cloud(new pcl::PointCloud<pcl::PointXYZ>);
+    std::vector<TensorrtWheelDetector::Object> segment_results;
     while (t_iter->second.condit->is_alive()) {
         t_iter->second.condit->wait();
-        if (t_iter->second.condit->is_alive() ) {
-           Error_manager ret;
-           VzFrame depthFrame;
-           if (iter->second.handle) {
+        if (t_iter->second.condit->is_alive()) {
+            Error_manager ret;
+            if (iter->second->handle) {
+                t_car_cloud->clear();
+                t_wheel_cloud->clear();
                 VzFrame depthFrame = {0};
                 cv::Mat depthMat(480, 640, CV_16UC1);
-                if(getDepthFrame(ip, depthFrame) == SUCCESS && DepthFrame2Mat(depthFrame, depthMat) == SUCCESS) {
+                if (getDepthFrame(ip, depthFrame) == SUCCESS) {
+                    segment_results.clear();
+                    if (Frame2Mat(depthFrame, depthMat) == SUCCESS) {
+                        detector->detect(depthMat, segment_results);
+                        cv::imshow("ret", depthMat);
+                        cv::waitKey(100);
+                    }
+
+                    std::vector<cv::Point> mat_seg_ret;
+                    for (auto &result: segment_results) {
+                        if (result.prob > 0.5) {
+                            mat_seg_ret = detector->getPointsFromObj(result);
+                            for (auto &pt: mat_seg_ret) {
+                                depthMat.at<uchar>(pt) = 255 - depthMat.at<uchar>(pt);
+                            }
+                            cv::imshow("ret", depthMat);
+                            cv::waitKey(1);
+                        }
+                    }
 
+                    if (!mat_seg_ret.empty()) {
+                        segFrame2CarAndWheel(depthFrame, mat_seg_ret, t_car_cloud, t_wheel_cloud);
+                        //                        viewer.removeAllPointClouds(view_port[0]);
+                        //                        viewer.removeAllPointClouds(view_port[1]);
+                        //                        viewer.addPointCloud(t_car_cloud, "car_cloud_", view_port[0]);
+                        //                        viewer.addPointCloud(t_wheel_cloud, "wheel_cloud_", view_port[1]);
+                        //                        viewer.spinOnce();
+                    }
                 } else {
                     ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrame failed.", ip.c_str()});
                 }
-           } else {
-               ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s handle is null.", ip.c_str()});
-           }
-           LOG(INFO) << ret.get_error_description();
-           std::this_thread::sleep_for(std::chrono::milliseconds (1));
+            } else {
+                ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s handle is null.", ip.c_str()});
+            }
+
+            if (!ret.get_error_description().empty()) {
+                LOG(INFO) << ret.get_error_description();
+            }
+            std::this_thread::sleep_for(std::chrono::milliseconds(1));
         }
     }
 
@@ -459,8 +505,50 @@ void DeviceTof3D::receiveFrameThread(const std::string &ip) {
     LOG(INFO) << ip << " thread end " << std::this_thread::get_id();
 }
 
-void DeviceTof3D::HotPlugStateCallback(const VzDeviceInfo *pInfo, int status, void *contex)
-{
+#include <pcl/visualization/pcl_visualizer.h>
+
+void DeviceTof3D::detectThread() {
+    LOG(INFO) << "detect thread running in " << std::this_thread::get_id();
+
+    int view_port[2];
+    pcl::visualization::PCLVisualizer viewer("viewer_0");
+    viewer.createViewPort(0.0, 0.0, 0.5, 1, view_port[0]);
+    viewer.createViewPort(0.5, 0.0, 1, 1, view_port[1]);
+    viewer.addText("car_cloud", 10, 10, 20, 0, 1, 0, "car_cloud", view_port[0]);
+    viewer.addText("wheel_cloud", 10, 10, 20, 0, 1, 0, "wheel_cloud", view_port[1]);
+    viewer.addCoordinateSystem(1, "car_axis", view_port[0]);
+    viewer.addCoordinateSystem(1, "wheel_axis", view_port[1]);
+
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_car_cloud(new pcl::PointCloud<pcl::PointXYZ>);
+    pcl::PointCloud<pcl::PointXYZ>::Ptr t_wheel_cloud(new pcl::PointCloud<pcl::PointXYZ>);
+    auto t_start_time = std::chrono::steady_clock::now();
+    std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
+
+    while (detect_thread.condit->is_alive()) {
+//        detect_thread.condit->wait();
+        t_car_cloud->clear();
+        t_wheel_cloud->clear();
+        cost = std::chrono::steady_clock::now() - t_start_time;
+        std::this_thread::sleep_for(std::chrono::milliseconds((int) MAX(100 - cost.count() * 1000, 1)));
+        t_start_time = std::chrono::steady_clock::now();
+//        LOG(INFO) << "last wheel cost time is " << cost.count() * 1000 << " ms";
+
+        if (detect_thread.condit->is_alive()) {
+
+
+//            cost = std::chrono::steady_clock::now() - t_start_time;
+//            LOG(INFO) << "cost time is " << cost.count() * 1000 << " ms";
+            if (!t_car_cloud->empty() && !t_wheel_cloud->empty()) {
+                CarPoseOptimize(t_car_cloud);
+                WheelCloudOptimize(t_wheel_cloud);
+            }
+
+        }
+    }
+    LOG(INFO) << "detect thread " << std::this_thread::get_id() << " closed.";
+}
+
+void DeviceTof3D::HotPlugStateCallback(const VzDeviceInfo *pInfo, int status, void *contex) {
     LOG(WARNING) << "uri " << status << "  " << pInfo->uri << "    " << (status == 0 ? "add" : "remove");
     LOG(WARNING) << "alia " << status << "  " << pInfo->alias << "    " << (status == 0 ? "add" : "remove");
 
@@ -468,22 +556,19 @@ void DeviceTof3D::HotPlugStateCallback(const VzDeviceInfo *pInfo, int status, vo
         return;
     }
 
-    tof3dVzenseInfoMap *mp = (tof3dVzenseInfoMap *)contex;
+    tof3dVzenseInfoMap *mp = (tof3dVzenseInfoMap *) contex;
     auto iter = mp->find(pInfo->ip);
     LOG(INFO) << iter->first;
-    if (status == 0)
-    {
-        LOG(WARNING) << "VZ_OpenDevice " << VZ_OpenDeviceByUri(pInfo->uri, &iter->second.handle);
-        LOG(WARNING) << "VZ_StartStream " << VZ_StartStream(iter->second.handle);
-        iter->second.is_connect = true;
-        iter->second.is_start_stream = true;
-    }
-    else
-    {
-        LOG(WARNING) << "VZ_StopStream " << VZ_StopStream(iter->second.handle);
-        LOG(WARNING) << "VZ_CloseDevice " << VZ_CloseDevice(&iter->second.handle);
-        iter->second.is_connect = false;
-        iter->second.is_start_stream = false;
+    if (status == 0) {
+        LOG(WARNING) << "VZ_OpenDevice " << VZ_OpenDeviceByUri(pInfo->uri, &iter->second->handle);
+        LOG(WARNING) << "VZ_StartStream " << VZ_StartStream(iter->second->handle);
+        iter->second->is_connect = true;
+        iter->second->is_start_stream = true;
+    } else {
+        LOG(WARNING) << "VZ_StopStream " << VZ_StopStream(iter->second->handle);
+        LOG(WARNING) << "VZ_CloseDevice " << VZ_CloseDevice(&iter->second->handle);
+        iter->second->is_connect = false;
+        iter->second->is_start_stream = false;
     }
 }
 
@@ -495,13 +580,14 @@ bool DeviceTof3D::drawBox(cv::Mat &mat, cv::Rect &box, cv::Scalar &color, std::s
     cv::Size textSize = cv::getTextSize(classString, cv::FONT_HERSHEY_DUPLEX, 1, 2, 0);
     cv::Rect textBox(box.x, box.y - 40, textSize.width + 10, textSize.height + 20);
     cv::rectangle(mat, textBox, color, cv::FILLED);
-    cv::putText(mat, classString, cv::Point(box.x + 5, box.y - 10), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 0, 0), 2, 0);
+    cv::putText(mat, classString, cv::Point(box.x + 5, box.y - 10), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 0, 0), 2,
+                0);
     return true;
 }
 
 Error_manager DeviceTof3D::updateTof3dEtc() {
-    for (auto &info : mp_device_info) {
-        if (info.second.etc.enable_device()) {
+    for (auto &info: mp_device_info) {
+        if (info.second->etc.enable_device()) {
 
         }
     }
@@ -510,9 +596,9 @@ Error_manager DeviceTof3D::updateTof3dEtc() {
 
 Error_manager DeviceTof3D::loadEtc(const DeviceTof3D::VzEtcMap &etc) {
     for (auto &iter: etc) {
-        tof3dVzenseInfo info;
-        info.etc = iter.second;
-        mp_device_info.insert(std::pair<std::string, tof3dVzenseInfo>(iter.first, info));
+        tof3dVzenseInfo *info = new tof3dVzenseInfo();
+        info->etc = iter.second;
+        mp_device_info.insert(std::pair<std::string, tof3dVzenseInfo *>(iter.first, info));
         LOG(INFO) << "Get device " << iter.first << " etc: " << iter.second.DebugString();
     }
     return Error_manager();
@@ -520,7 +606,7 @@ Error_manager DeviceTof3D::loadEtc(const DeviceTof3D::VzEtcMap &etc) {
 
 void DeviceTof3D::stopWorking() {
     for (auto &info: mp_device_info) {
-        auto iter = mp_thread_info.find(info.second.etc.ip());
+        auto iter = mp_thread_info.find(info.second->etc.ip());
         if (iter != mp_thread_info.end()) {
             iter->second.condit->kill_all();
             iter->second.t->join();
@@ -547,77 +633,68 @@ Error_manager DeviceTof3D::setTof3dParams(const std::string &ip) {
         return {}; //TODO
     }
 
-    m_vz_status = VZ_SetWorkMode(iter->second.handle, (VzWorkMode)iter->second.etc.bip().work_mode());
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_SetWorkMode(iter->second->handle, (VzWorkMode) iter->second->etc.bip().work_mode());
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetWorkMode failed status:" << m_vz_status;
         return {};  //TODO
     }
 
-    m_vz_status = VZ_SetIRGMMGain(iter->second.handle, iter->second.etc.bip().irgmmgain());
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_SetIRGMMGain(iter->second->handle, iter->second->etc.bip().irgmmgain());
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetIRGMMGain failed status:" << m_vz_status;
         return {};  //TODO
     }
 
-    m_vz_status = VZ_SetFrameRate(iter->second.handle, iter->second.etc.bip().frame_rate());
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_SetFrameRate(iter->second->handle, iter->second->etc.bip().frame_rate());
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetFrameRate failed status:" << m_vz_status;
         return {};  //TODO
     }
 
     VzExposureTimeParams exposure_param;
-    exposure_param.mode = (VzExposureControlMode)iter->second.etc.bip().enable_manual_exposure_time();
-    exposure_param.exposureTime = iter->second.etc.bip().exposure_time();
-    m_vz_status = VZ_SetExposureTime(iter->second.handle, VzToFSensor, exposure_param);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    exposure_param.mode = (VzExposureControlMode) iter->second->etc.bip().enable_manual_exposure_time();
+    exposure_param.exposureTime = iter->second->etc.bip().exposure_time();
+    m_vz_status = VZ_SetExposureTime(iter->second->handle, VzToFSensor, exposure_param);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetExposureTime failed status:" << m_vz_status;
         return {};  //TODO
     }
 
-    m_vz_status = VZ_SetFillHoleFilterEnabled(iter->second.handle, iter->second.etc.bip().enable_filter_fill_hole());
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_SetFillHoleFilterEnabled(iter->second->handle, iter->second->etc.bip().enable_filter_fill_hole());
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetFillHoleFilterEnabled failed status:" << m_vz_status;
         return {};  //TODO
     }
 
-    m_vz_status = VZ_SetSpatialFilterEnabled(iter->second.handle, iter->second.etc.bip().enable_filter_spatial());
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_SetSpatialFilterEnabled(iter->second->handle, iter->second->etc.bip().enable_filter_spatial());
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetSpatialFilterEnabled failed status:" << m_vz_status;
         return {};  //TODO
     }
 
     VzFlyingPixelFilterParams fly;
-    fly.enable = iter->second.etc.bip().enable_flying_pixel_filter();
-    fly.threshold = iter->second.etc.bip().flying_pixel_filter_value();
-    m_vz_status = VZ_SetFlyingPixelFilterParams(iter->second.handle, fly);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    fly.enable = iter->second->etc.bip().enable_flying_pixel_filter();
+    fly.threshold = iter->second->etc.bip().flying_pixel_filter_value();
+    m_vz_status = VZ_SetFlyingPixelFilterParams(iter->second->handle, fly);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetFlyingPixelFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
 
     VzConfidenceFilterParams confidence;
-    confidence.enable = iter->second.etc.bip().enable_confidence_filter();
-    confidence.threshold = iter->second.etc.bip().confidence_filter_value();
-    m_vz_status = VZ_SetConfidenceFilterParams(iter->second.handle, confidence);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    confidence.enable = iter->second->etc.bip().enable_confidence_filter();
+    confidence.threshold = iter->second->etc.bip().confidence_filter_value();
+    m_vz_status = VZ_SetConfidenceFilterParams(iter->second->handle, confidence);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetConfidenceFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
 
     VzTimeFilterParams time_filter;
-    time_filter.enable = iter->second.etc.bip().enable_time_filter();
-    time_filter.threshold = iter->second.etc.bip().time_filter_value();
-    m_vz_status = VZ_SetTimeFilterParams(iter->second.handle, time_filter);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    time_filter.enable = iter->second->etc.bip().enable_time_filter();
+    time_filter.threshold = iter->second->etc.bip().time_filter_value();
+    m_vz_status = VZ_SetTimeFilterParams(iter->second->handle, time_filter);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_SetTimeFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
@@ -634,88 +711,144 @@ Error_manager DeviceTof3D::getTof3dParams(const std::string &ip) {
 
     // 获取参数
     VzWorkMode mode;
-    m_vz_status = VZ_GetWorkMode(iter->second.handle, &mode);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetWorkMode(iter->second->handle, &mode);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetWorkMode failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_work_mode(mode);
+    iter->second->etc.mutable_bip()->set_work_mode(mode);
 
     uint8_t irgmmgain;
-    m_vz_status = VZ_GetIRGMMGain(iter->second.handle, &irgmmgain);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetIRGMMGain(iter->second->handle, &irgmmgain);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetIRGMMGain failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_irgmmgain(irgmmgain);
+    iter->second->etc.mutable_bip()->set_irgmmgain(irgmmgain);
 
     int frame_rate;
-    m_vz_status = VZ_GetFrameRate(iter->second.handle, &frame_rate);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetFrameRate(iter->second->handle, &frame_rate);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetFrameRate failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_frame_rate(frame_rate);
+    iter->second->etc.mutable_bip()->set_frame_rate(frame_rate);
 
     VzExposureTimeParams exposure_param = {VzExposureControlMode_Manual, 0};
-    m_vz_status = VZ_GetProperty(iter->second.handle, "Py_ToFExposureTimeMax", &exposure_param, sizeof(exposure_param));
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetProperty(iter->second->handle, "Py_ToFExposureTimeMax", &exposure_param,
+                                 sizeof(exposure_param));
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetExposureTime failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_manual_exposure_time(exposure_param.mode);
-    iter->second.etc.mutable_bip()->set_exposure_time(exposure_param.exposureTime);
+    iter->second->etc.mutable_bip()->set_enable_manual_exposure_time(exposure_param.mode);
+    iter->second->etc.mutable_bip()->set_exposure_time(exposure_param.exposureTime);
 
     bool boolret;
-    m_vz_status = VZ_GetFillHoleFilterEnabled(iter->second.handle, &boolret);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetFillHoleFilterEnabled(iter->second->handle, &boolret);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetFillHoleFilterEnabled failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_filter_fill_hole(boolret);
+    iter->second->etc.mutable_bip()->set_enable_filter_fill_hole(boolret);
 
-    m_vz_status = VZ_GetSpatialFilterEnabled(iter->second.handle, &boolret);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetSpatialFilterEnabled(iter->second->handle, &boolret);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetSpatialFilterEnabled failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_filter_spatial(boolret);
+    iter->second->etc.mutable_bip()->set_enable_filter_spatial(boolret);
 
     VzFlyingPixelFilterParams fly;
-    m_vz_status = VZ_GetFlyingPixelFilterParams(iter->second.handle, &fly);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetFlyingPixelFilterParams(iter->second->handle, &fly);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetFlyingPixelFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_flying_pixel_filter(fly.enable);
-    iter->second.etc.mutable_bip()->set_flying_pixel_filter_value(fly.threshold);
+    iter->second->etc.mutable_bip()->set_enable_flying_pixel_filter(fly.enable);
+    iter->second->etc.mutable_bip()->set_flying_pixel_filter_value(fly.threshold);
 
     VzConfidenceFilterParams confidence;
-    m_vz_status = VZ_GetConfidenceFilterParams(iter->second.handle, &confidence);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetConfidenceFilterParams(iter->second->handle, &confidence);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetConfidenceFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_confidence_filter(confidence.enable);
-    iter->second.etc.mutable_bip()->set_confidence_filter_value(confidence.threshold);
+    iter->second->etc.mutable_bip()->set_enable_confidence_filter(confidence.enable);
+    iter->second->etc.mutable_bip()->set_confidence_filter_value(confidence.threshold);
 
     VzTimeFilterParams time_filter;
-    m_vz_status = VZ_GetTimeFilterParams(iter->second.handle, &time_filter);
-    if (m_vz_status != VzReturnStatus::VzRetOK)
-    {
+    m_vz_status = VZ_GetTimeFilterParams(iter->second->handle, &time_filter);
+    if (m_vz_status != VzReturnStatus::VzRetOK) {
         LOG(WARNING) << ip << " VZ_GetTimeFilterParams failed status:" << m_vz_status;
         return {};  //TODO
     }
-    iter->second.etc.mutable_bip()->set_enable_time_filter(time_filter.enable);
-    iter->second.etc.mutable_bip()->set_time_filter_value(time_filter.threshold);
+    iter->second->etc.mutable_bip()->set_enable_time_filter(time_filter.enable);
+    iter->second->etc.mutable_bip()->set_time_filter_value(time_filter.threshold);
+
+    return Error_manager();
+}
+
+Error_manager DeviceTof3D::segFrame2CarAndWheel(VzFrame &depth_frame, std::vector<cv::Point> &wheel_cv_cloud,
+                                                pcl::PointCloud<pcl::PointXYZ>::Ptr &car_cloud,
+                                                pcl::PointCloud<pcl::PointXYZ>::Ptr &wheel_cloud) {
+
+    auto iter = mp_device_info.find("192.168.2.102");
+    if (iter->second->handle != nullptr) {
+        VzSensorIntrinsicParameters cameraParam = {};
+        VZ_GetSensorIntrinsicParameters(iter->second->handle, VzToFSensor, &cameraParam);
+
+        const uint16_t *pDepthFrameData = (uint16_t *) depth_frame.pFrameData;
+        for (auto &pt: wheel_cv_cloud) {
+            VzDepthVector3 depthPoint = {pt.x, pt.y, pDepthFrameData[pt.y * depth_frame.width + pt.x]};
+            VzVector3f worldV = {};
+            VZ_ConvertDepthToPointCloud(iter->second->handle, &depthPoint, &worldV, 1, &cameraParam);
+            wheel_cloud->emplace_back(worldV.x, worldV.y, worldV.z);
+        }
+        LOG(INFO) << wheel_cloud->size();
+
+        VzFrame &srcFrame = depth_frame;
+        const int len = srcFrame.width * srcFrame.height;
+        VzVector3f *worldV = new VzVector3f[len];
+
+        m_vz_status = VZ_ConvertDepthFrameToPointCloudVector(iter->second->handle, &srcFrame,
+                                                             worldV);
+
+        if (m_vz_status == VzRetOK) {
+            car_cloud->clear();
+            for (int i = 0; i < len; i++) {
+                if (worldV[i].x == 0 && worldV[i].y == 0 && worldV[i].z == 0) {
+                    continue;
+                }
+                car_cloud->points.emplace_back(worldV[i].x, worldV[i].y, worldV[i].z);
+            }
+            delete[] worldV;
+            worldV = nullptr;
+            LOG(INFO) << "Save point cloud successful to cloud: " << car_cloud->size();
+        }
+
+//        for (int i = (depth_frame.height - WINDOW_SIZE)/2, offset = i * depth_frame.width; i < (depth_frame.height + WINDOW_SIZE)/2; i++)
+//        {
+//            for (int j = (depth_frame.width - WINDOW_SIZE)/2; j < (depth_frame.width + WINDOW_SIZE)/2; j++)
+//            {
+//                VzDepthVector3 depthPoint = {j, i, pDepthFrameData[offset + j]};
+//                VzVector3f worldV = {};
+//                VZ_ConvertDepthToPointCloud(iter->second->handle, &depthPoint, &worldV, 1, &cameraParam);
+//                if (0 < worldV.z && worldV.z < 0xFFFF)
+//                {
+//                    LOG(INFO) << worldV.x << "\t" << worldV.y << "\t" << worldV.z << std::endl;
+//                }
+//            }
+//            offset += depth_frame.width;
+//        }
+    }
+    return Error_manager();
+}
+
+Error_manager DeviceTof3D::WheelCloudOptimize(pcl::PointCloud<pcl::PointXYZ>::Ptr &wheel_cloud) {
+    return Error_manager();
+}
 
+Error_manager DeviceTof3D::CarPoseOptimize(pcl::PointCloud<pcl::PointXYZ>::Ptr &car_cloud) {
     return Error_manager();
 }

+ 15 - 16
vzense/device_tof3d.h

@@ -12,21 +12,26 @@
 #include "thread/thread_condition.h"
 
 #include "tof3d_config.pb.h"
-#include "detect/wheel-detector.h"
+
+#ifdef ENABLE_TENSORRT_DETECT
+#include "detect/tensorrt/wheel-detector.h"
+#else
+#include "detect/onnx/wheel-detector.h"
+#endif
 
 
 class DeviceTof3D {
 public:
     struct tof3dVzenseInfo {
-        VzDeviceInfo info;
-        tof3dVzenseEtc etc;
         VzDeviceHandle handle = nullptr;
         bool is_connect = false;
         bool is_start_stream = false;
+        VzDeviceInfo info;
+        tof3dVzenseEtc etc;
     };
 
     using VzEtcMap = std::map<std::string, tof3dVzenseEtc>;
-    using tof3dVzenseInfoMap = std::map<std::string, tof3dVzenseInfo>;
+    using tof3dVzenseInfoMap = std::map<std::string, tof3dVzenseInfo*>;
 public:
     static DeviceTof3D* iter() {
         static DeviceTof3D* instance = nullptr;
@@ -86,7 +91,7 @@ protected:
 
     void receiveFrameThread(const std::string &ip);
 
-    void detectThread(const std::string &ip);
+    void detectThread();
 
     static void HotPlugStateCallback(const VzDeviceInfo *pInfo, int status, void *contex);
 
@@ -96,8 +101,8 @@ protected:
 
     void stopWorking();
 
-    // 传入深度图,得到车轮在mat中的坐标
-    Error_manager segmentTensorRT(cv::Mat &depth_mat, std::vector<cv::Point> &wheel_cv_cloud);
+    // // 传入深度图,得到车轮在mat中的坐标
+    // Error_manager segmentTensorRT(cv::Mat &depth_mat, std::vector<cv::Point> &wheel_cv_cloud);
 
     // 根据传入坐标,分离depth frame的数据点
     Error_manager segFrame2CarAndWheel(VzFrame &depth_frame, std::vector<cv::Point> &wheel_cv_cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr &car_cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr &wheel_cloud);
@@ -112,6 +117,7 @@ private:
         std::thread * t;
         Thread_condition * condit;
 
+        ThreadInfo() {t = nullptr; condit = nullptr;}
         ThreadInfo(std::thread *m_t, Thread_condition * m_condit): t(m_t), condit(m_condit) {}
     };
     VzReturnStatus m_vz_status = VzRetOthers;
@@ -119,15 +125,8 @@ private:
     tof3dVzenseInfoMap mp_device_info;
     std::map<std::string, ThreadInfo> mp_thread_info;
 
-    VzFrame lf_frame;
-    std::mutex lf_frame_mutex;                                              // 测量结果互斥锁
-    VzFrame rf_frame;
-    std::mutex rf_frame_mutex;                                              // 测量结果互斥锁
-    VzFrame lr_frame;
-    std::mutex lr_frame_mutex;                                              // 测量结果互斥锁
-    VzFrame rr_frame;
-    std::mutex rr_frame_mutex;                                              // 测量结果互斥锁
-
+    ThreadInfo detect_thread;
+    TensorrtWheelDetector *detector;
 };