data.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef DATA_HPP__
  2. #define DATA_HPP__
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <iostream>
  7. #include <memory>
  8. #include "opencv2/opencv.hpp"
  9. #include "common/check.hpp"
  10. namespace data
  11. {
  12. struct Point
  13. {
  14. float x;
  15. float y;
  16. float score;
  17. Point() : x(0), y(0), score(0) {}
  18. Point(float x, float y, float score) : x(x), y(y), score(score) {}
  19. Point(const Point& p) : x(p.x), y(p.y), score(p.score) {}
  20. Point& operator=(const Point& p)
  21. {
  22. x = p.x;
  23. y = p.y;
  24. score = p.score;
  25. return *this;
  26. }
  27. };
  28. struct InstanceSegmentMap
  29. {
  30. int width = 0, height = 0; // width % 8 == 0
  31. unsigned char *data = nullptr; // is width * height memory
  32. InstanceSegmentMap(int width, int height)
  33. {
  34. this->width = width;
  35. this->height = height;
  36. checkRuntime(cudaMallocHost(&this->data, width * height));
  37. }
  38. virtual ~InstanceSegmentMap()
  39. {
  40. if (this->data)
  41. {
  42. checkRuntime(cudaFreeHost(this->data));
  43. this->data = nullptr;
  44. }
  45. this->width = 0;
  46. this->height = 0;
  47. }
  48. };
  49. struct Box
  50. {
  51. float left, top, right, bottom, score;
  52. // 在目标追踪中,将class_id赋值表示追踪的目标id
  53. int class_id;
  54. std::string label;
  55. std::vector<Point> keypoints;
  56. cv::Mat seg_mask;
  57. Box() : left(0), top(0), right(0), bottom(0), score(0), class_id(0), label("") {}
  58. Box(float left, float top, float right, float bottom, float score, int class_id)
  59. : left(left), top(top), right(right), bottom(bottom), score(score), class_id(class_id), label("") {}
  60. Box(float left, float top, float right, float bottom, float score, int class_id, const std::string& label)
  61. : left(left), top(top), right(right), bottom(bottom), score(score), class_id(class_id), label(label) {}
  62. Box(const Box& b) :
  63. left(b.left), top(b.top), right(b.right), bottom(b.bottom), score(b.score),
  64. class_id(b.class_id), label(b.label), keypoints(b.keypoints),
  65. seg_mask(b.seg_mask.clone()) {}
  66. Box(Box&& b) noexcept :
  67. left(b.left), top(b.top), right(b.right), bottom(b.bottom), score(b.score),
  68. class_id(b.class_id), label(std::move(b.label)), keypoints(std::move(b.keypoints)),
  69. seg_mask(std::move(b.seg_mask)) {}
  70. Box& operator=(const Box& b)
  71. {
  72. left = b.left;
  73. top = b.top;
  74. right = b.right;
  75. bottom = b.bottom;
  76. score = b.score;
  77. class_id = b.class_id;
  78. label = b.label;
  79. keypoints = b.keypoints;
  80. seg_mask = b.seg_mask.clone();
  81. return *this;
  82. }
  83. };
  84. using BoxArray = std::vector<Box>;
  85. } // namespace data
  86. #endif // DATA_HPP__