yolov8-seg.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // Created by ubuntu on 3/16/23.
  3. //
  4. #ifndef JETSON_SEGMENT_YOLOV8_SEG_HPP
  5. #define JETSON_SEGMENT_YOLOV8_SEG_HPP
  6. #include "NvInferPlugin.h"
  7. #include "common.hpp"
  8. #include <fstream>
  9. using namespace seg;
  10. class YOLOv8_seg {
  11. public:
  12. explicit YOLOv8_seg(const std::string& engine_file_path);
  13. ~YOLOv8_seg();
  14. void make_pipe(bool warmup = true);
  15. void copy_from_Mat(const cv::Mat& image);
  16. void copy_from_Mat(const cv::Mat& image, cv::Size& size);
  17. void letterbox(const cv::Mat& image, cv::Mat& out, cv::Size& size);
  18. void infer();
  19. void postprocess(std::vector<Object>& objs,
  20. float score_thres = 0.25f,
  21. float iou_thres = 0.65f,
  22. int topk = 100,
  23. int seg_channels = 32,
  24. int seg_h = 160,
  25. int seg_w = 160);
  26. static void draw_objects(const cv::Mat& image,
  27. cv::Mat& res,
  28. const std::vector<Object>& objs,
  29. const std::vector<std::string>& CLASS_NAMES,
  30. const std::vector<std::vector<unsigned int>>& COLORS,
  31. const std::vector<std::vector<unsigned int>>& MASK_COLORS);
  32. int num_bindings;
  33. int num_inputs = 0;
  34. int num_outputs = 0;
  35. std::vector<Binding> input_bindings;
  36. std::vector<Binding> output_bindings;
  37. std::vector<void*> host_ptrs;
  38. std::vector<void*> device_ptrs;
  39. PreParam pparam;
  40. private:
  41. nvinfer1::ICudaEngine* engine = nullptr;
  42. nvinfer1::IRuntime* runtime = nullptr;
  43. nvinfer1::IExecutionContext* context = nullptr;
  44. cudaStream_t stream = nullptr;
  45. Logger gLogger{nvinfer1::ILogger::Severity::kERROR};
  46. };
  47. #endif // JETSON_SEGMENT_YOLOV8_SEG_HPP