ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
object.hpp
Go to the documentation of this file.
1#pragma once
2#include <opencv2/opencv.hpp>
3
4#include <optional>
5#include <ostream>
6#include <string>
7#include <tuple>
8#include <vector>
9
11
14enum class ObjectType {
15 UNKNOW = -1,
17 POSE = 1,
18 OBB = 2,
22 TRACK = 6,
24};
25
28struct Box {
29 float left = 0.0f;
30 float top = 0.0f;
31 float right = 0.0f;
32 float bottom = 0.0f;
33
34 Box() = default;
35
41 Box(float l, float t, float r, float b);
42
44 float width() const noexcept { return right - left; }
45
47 float height() const noexcept { return bottom - top; }
48
50 float center_x() const noexcept { return (left + right) / 2; }
51
53 float center_y() const noexcept { return (top + bottom) / 2; }
54
56 float area() const noexcept { return width() * height(); }
57
58 friend std::ostream &operator<<(std::ostream &os, const Box &box);
59};
60
62struct PosePoint {
63 float x = 0.0f;
64 float y = 0.0f;
65 float vis = 0.0f;
67
68 PosePoint() = default;
69
71 PosePoint(float x, float y, float vis);
72
74 friend std::ostream &operator<<(std::ostream &os, const PosePoint &point);
75};
76
78struct Pose {
79 std::vector<PosePoint> points;
80
81 Pose &operator=(const Pose &other);
82 friend std::ostream &operator<<(std::ostream &os, const Pose &pose);
83};
84
87struct Obb {
88 float cx = 0.0f;
89 float cy = 0.0f;
90 float w = 0.0f;
91 float h = 0.0f;
92 float angle = 0.0f;
93
94 Obb() = default;
95
97 Obb(float cx, float cy, float w, float h, float angle);
98
99 Obb &operator=(const Obb &other);
100
102 float area() const { return w * h; }
103
104 friend std::ostream &operator<<(std::ostream &os, const Obb &obb);
105};
106
110 int width = 0;
111 int height = 0;
112 unsigned char *data = nullptr;
113
117
118 virtual ~SegmentMap();
119
121 SegmentMap(const SegmentMap &) = delete;
122 SegmentMap &operator=(const SegmentMap &) = delete;
123
125 SegmentMap(SegmentMap &&other) noexcept
126 : width(std::exchange(other.width, 0)),
127 height(std::exchange(other.height, 0)),
128 data(std::exchange(other.data, nullptr)) {}
129
131 SegmentMap &operator=(SegmentMap &&other) noexcept;
132};
133
136 cv::Mat mask;
137
140
143 Segmentation align_to_left_top(int left, int top, int width,
144 int height) const;
145
147};
148
150struct Depth {
151 cv::Mat depth;
152 float fog_data = 0.0f;
153
155 float point_depth(int x, int y) const;
156
158 float average_depth() const;
159
161 float min_depth() const;
162
164 float max_depth() const;
165
168 float area_average_depth(const cv::Mat &seg) const;
169
171 float area_average_depth(const Box &box) const;
172};
173
175struct Track {
176 int track_id = -1;
177
179 std::optional<std::vector<Pose>> history_pose;
180
182 std::vector<std::tuple<float, float>> track_trace;
183
184 friend std::ostream &operator<<(std::ostream &os, const Track &track);
185};
186
192 float score = 0.0f;
193 int class_id = -1;
194 std::string class_name;
195
196 std::optional<Pose> pose;
197 std::optional<Obb> obb;
198 std::optional<Segmentation>
200 std::optional<Depth> depth;
201 std::optional<Track> track;
202
203 friend std::ostream &operator<<(std::ostream &os, const DetectionBox &box);
204};
205
209cv::Mat segmentMapToMat(const std::shared_ptr<SegmentMap> &map);
210
212using DetectionBoxArray = std::vector<DetectionBox>;
213
214} // namespace ReUseX::vision::common::object
ObjectType
Enumeration of supported detection object types.
Definition object.hpp:14
@ DEPTH_PRO
Depth map from DepthPro model.
Definition object.hpp:21
@ DEPTH_ANYTHING
Depth map from DepthAnything model.
Definition object.hpp:20
@ UNKNOW
Unknown or unclassified object type.
Definition object.hpp:15
@ POSITION
Simple position/region of interest.
Definition object.hpp:16
@ DETECTION
Standard bounding box detection.
Definition object.hpp:23
@ TRACK
Multi-object tracking result.
Definition object.hpp:22
@ POSE
Human pose estimation result.
Definition object.hpp:17
@ SEGMENTATION
Instance segmentation mask.
Definition object.hpp:19
cv::Mat segmentMapToMat(const std::shared_ptr< SegmentMap > &map)
Convert a SegmentMap to an OpenCV Mat (zero-copy header wrapper).
std::vector< DetectionBox > DetectionBoxArray
Convenience alias for a collection of DetectionBox results.
Definition object.hpp:212
Axis-aligned bounding box defined by (left, top, right, bottom) coordinates.
Definition object.hpp:28
float right
Right edge x-coordinate.
Definition object.hpp:31
float left
Left edge x-coordinate.
Definition object.hpp:29
float center_y() const noexcept
Returns the y-coordinate of the box center.
Definition object.hpp:53
float top
Top edge y-coordinate.
Definition object.hpp:30
float bottom
Bottom edge y-coordinate.
Definition object.hpp:32
float width() const noexcept
Returns the width of the box.
Definition object.hpp:44
friend std::ostream & operator<<(std::ostream &os, const Box &box)
float area() const noexcept
Returns the area of the box.
Definition object.hpp:56
float height() const noexcept
Returns the height of the box.
Definition object.hpp:47
Box(float l, float t, float r, float b)
Construct a Box with explicit corner coordinates.
float center_x() const noexcept
Returns the x-coordinate of the box center.
Definition object.hpp:50
Depth map result with per-pixel depth values.
Definition object.hpp:150
float area_average_depth(const Box &box) const
Returns the average depth within the given bounding box region.
float point_depth(int x, int y) const
Returns the depth at pixel (x, y).
float max_depth() const
Returns the maximum depth value.
cv::Mat depth
CV_32F depth image.
Definition object.hpp:151
float area_average_depth(const cv::Mat &seg) const
Returns the average depth within the region indicated by a segmentation mask.
float min_depth() const
Returns the minimum depth value.
float average_depth() const
Returns the average depth over the entire map.
float fog_data
Optional fog/haze estimate.
Definition object.hpp:152
Universal detection result container that holds a bounding box plus optional enriched data (pose,...
Definition object.hpp:189
std::optional< Obb > obb
Populated for OBB detections.
Definition object.hpp:197
ObjectType type
Type of this detection.
Definition object.hpp:190
std::optional< Track > track
Populated for TRACK detections.
Definition object.hpp:201
float score
Confidence score in [0, 1].
Definition object.hpp:192
std::string class_name
Human-readable class label.
Definition object.hpp:194
std::optional< Segmentation > segmentation
Populated for SEGMENTATION detections.
Definition object.hpp:199
std::optional< Depth > depth
Populated for DEPTH_* detections.
Definition object.hpp:200
friend std::ostream & operator<<(std::ostream &os, const DetectionBox &box)
std::optional< Pose > pose
Populated for POSE detections.
Definition object.hpp:196
Box box
Axis-aligned bounding box.
Definition object.hpp:191
float area() const
Returns the area of the oriented bounding box.
Definition object.hpp:102
float angle
Rotation angle in degrees.
Definition object.hpp:92
float cx
Center x-coordinate.
Definition object.hpp:88
Obb & operator=(const Obb &other)
float h
Height of the box.
Definition object.hpp:91
friend std::ostream & operator<<(std::ostream &os, const Obb &obb)
float w
Width of the box.
Definition object.hpp:90
float cy
Center y-coordinate.
Definition object.hpp:89
Obb(float cx, float cy, float w, float h, float angle)
Construct an Obb with center, size, and angle.
PosePoint(float x, float y, float vis)
Construct a PosePoint with position and visibility.
friend std::ostream & operator<<(std::ostream &os, const PosePoint &point)
float y
Y-coordinate of the keypoint.
Definition object.hpp:64
float x
X-coordinate of the keypoint.
Definition object.hpp:63
PosePoint & operator=(const PosePoint &other)
float vis
Visibility/confidence score (0 = invisible, 1 = visible).
Definition object.hpp:65
A set of keypoints representing a human or object pose.
Definition object.hpp:78
Pose & operator=(const Pose &other)
friend std::ostream & operator<<(std::ostream &os, const Pose &pose)
std::vector< PosePoint > points
Ordered list of pose keypoints.
Definition object.hpp:79
int width
Width of the mask in pixels (must be % 8 == 0).
Definition object.hpp:110
SegmentMap & operator=(const SegmentMap &)=delete
SegmentMap(SegmentMap &&other) noexcept
Move constructor — transfers ownership and resets source.
Definition object.hpp:125
SegmentMap(int width, int height)
Allocate a SegmentMap of the given dimensions using pinned CUDA host memory.
SegmentMap & operator=(SegmentMap &&other) noexcept
Move assignment — transfers ownership and resets source.
unsigned char * data
Raw mask data (width * height bytes).
Definition object.hpp:112
SegmentMap(const SegmentMap &)=delete
Copy is disabled — use move semantics instead.
int height
Height of the mask in pixels.
Definition object.hpp:111
Instance segmentation result backed by an OpenCV mask.
Definition object.hpp:135
Segmentation & operator=(const Segmentation &other)
void keep_largest_part()
Retain only the largest connected component in the mask.
cv::Mat mask
Binary or grayscale segmentation mask.
Definition object.hpp:136
Segmentation align_to_left_top(int left, int top, int width, int height) const
Return a new Segmentation placed at the given (left, top) offset within a canvas of the specified dim...
Multi-object tracking state for a single tracked instance.
Definition object.hpp:175
int track_id
Unique tracking identifier.
Definition object.hpp:176
friend std::ostream & operator<<(std::ostream &os, const Track &track)
std::optional< std::vector< Pose > > history_pose
Optional history of pose keypoints from previous frames.
Definition object.hpp:179
std::vector< std::tuple< float, float > > track_trace
Trajectory trace as (x, y) positions from previous frames.
Definition object.hpp:182