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#include <optional>
4#include <ostream>
5#include <string>
6#include <tuple>
7#include <vector>
8
10
13enum class ObjectType {
14 UNKNOW = -1,
16 POSE = 1,
17 OBB = 2,
21 TRACK = 6,
23};
24
27struct Box {
28 float left = 0.0f;
29 float top = 0.0f;
30 float right = 0.0f;
31 float bottom = 0.0f;
32
33 Box() = default;
34
40 Box(float l, float t, float r, float b);
41
43 float width() const noexcept { return right - left; }
44
46 float height() const noexcept { return bottom - top; }
47
49 float center_x() const noexcept { return (left + right) / 2; }
50
52 float center_y() const noexcept { return (top + bottom) / 2; }
53
55 float area() const noexcept { return width() * height(); }
56
57 friend std::ostream &operator<<(std::ostream &os, const Box &box);
58};
59
61struct PosePoint {
62 float x = 0.0f;
63 float y = 0.0f;
64 float vis = 0.0f;
66
67 PosePoint() = default;
68
70 PosePoint(float x, float y, float vis);
71
73 friend std::ostream &operator<<(std::ostream &os, const PosePoint &point);
74};
75
77struct Pose {
78 std::vector<PosePoint> points;
79
80 Pose &operator=(const Pose &other);
81 friend std::ostream &operator<<(std::ostream &os, const Pose &pose);
82};
83
86struct Obb {
87 float cx = 0.0f;
88 float cy = 0.0f;
89 float w = 0.0f;
90 float h = 0.0f;
91 float angle = 0.0f;
92
93 Obb() = default;
94
96 Obb(float cx, float cy, float w, float h, float angle);
97
98 Obb &operator=(const Obb &other);
99
101 float area() const { return w * h; }
102
103 friend std::ostream &operator<<(std::ostream &os, const Obb &obb);
104};
105
109 int width = 0;
110 int height = 0;
111 unsigned char *data = nullptr;
112
116
117 virtual ~SegmentMap();
118
120 SegmentMap(const SegmentMap &) = delete;
121 SegmentMap &operator=(const SegmentMap &) = delete;
122
124 SegmentMap(SegmentMap &&other) noexcept
125 : width(std::exchange(other.width, 0)),
126 height(std::exchange(other.height, 0)),
127 data(std::exchange(other.data, nullptr)) {}
128
130 SegmentMap &operator=(SegmentMap &&other) noexcept;
131};
132
135 cv::Mat mask;
136
139
142 Segmentation align_to_left_top(int left, int top, int width,
143 int height) const;
144
146};
147
149struct Depth {
150 cv::Mat depth;
151 float fog_data = 0.0f;
152
154 float point_depth(int x, int y) const;
155
157 float average_depth() const;
158
160 float min_depth() const;
161
163 float max_depth() const;
164
167 float area_average_depth(const cv::Mat &seg) const;
168
170 float area_average_depth(const Box &box) const;
171};
172
174struct Track {
175 int track_id = -1;
176
178 std::optional<std::vector<Pose>> history_pose;
179
181 std::vector<std::tuple<float, float>> track_trace;
182
183 friend std::ostream &operator<<(std::ostream &os, const Track &track);
184};
185
191 float score = 0.0f;
192 int class_id = -1;
193 std::string class_name;
194
195 std::optional<Pose> pose;
196 std::optional<Obb> obb;
197 std::optional<Segmentation> segmentation;
198 std::optional<Depth> depth;
199 std::optional<Track> track;
200
201 friend std::ostream &operator<<(std::ostream &os, const DetectionBox &box);
202};
203
207cv::Mat segmentMapToMat(const std::shared_ptr<SegmentMap> &map);
208
210using DetectionBoxArray = std::vector<DetectionBox>;
211
212} // namespace ReUseX::vision::common::object
ObjectType
Enumeration of supported detection object types.
Definition object.hpp:13
@ DEPTH_PRO
Depth map from DepthPro model.
Definition object.hpp:20
@ DEPTH_ANYTHING
Depth map from DepthAnything model.
Definition object.hpp:19
@ UNKNOW
Unknown or unclassified object type.
Definition object.hpp:14
@ POSITION
Simple position/region of interest.
Definition object.hpp:15
@ DETECTION
Standard bounding box detection.
Definition object.hpp:22
@ TRACK
Multi-object tracking result.
Definition object.hpp:21
@ POSE
Human pose estimation result.
Definition object.hpp:16
@ SEGMENTATION
Instance segmentation mask.
Definition object.hpp:18
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:210
Axis-aligned bounding box defined by (left, top, right, bottom) coordinates.
Definition object.hpp:27
float right
Right edge x-coordinate.
Definition object.hpp:30
float left
Left edge x-coordinate.
Definition object.hpp:28
float center_y() const noexcept
Returns the y-coordinate of the box center.
Definition object.hpp:52
float top
Top edge y-coordinate.
Definition object.hpp:29
float bottom
Bottom edge y-coordinate.
Definition object.hpp:31
float width() const noexcept
Returns the width of the box.
Definition object.hpp:43
friend std::ostream & operator<<(std::ostream &os, const Box &box)
float area() const noexcept
Returns the area of the box.
Definition object.hpp:55
float height() const noexcept
Returns the height of the box.
Definition object.hpp:46
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:49
Depth map result with per-pixel depth values.
Definition object.hpp:149
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:150
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:151
Universal detection result container that holds a bounding box plus optional enriched data (pose,...
Definition object.hpp:188
std::optional< Obb > obb
Populated for OBB detections.
Definition object.hpp:196
ObjectType type
Type of this detection.
Definition object.hpp:189
std::optional< Track > track
Populated for TRACK detections.
Definition object.hpp:199
float score
Confidence score in [0, 1].
Definition object.hpp:191
std::string class_name
Human-readable class label.
Definition object.hpp:193
std::optional< Segmentation > segmentation
Populated for SEGMENTATION detections.
Definition object.hpp:197
std::optional< Depth > depth
Populated for DEPTH_* detections.
Definition object.hpp:198
friend std::ostream & operator<<(std::ostream &os, const DetectionBox &box)
std::optional< Pose > pose
Populated for POSE detections.
Definition object.hpp:195
Box box
Axis-aligned bounding box.
Definition object.hpp:190
float area() const
Returns the area of the oriented bounding box.
Definition object.hpp:101
float angle
Rotation angle in degrees.
Definition object.hpp:91
float cx
Center x-coordinate.
Definition object.hpp:87
Obb & operator=(const Obb &other)
float h
Height of the box.
Definition object.hpp:90
friend std::ostream & operator<<(std::ostream &os, const Obb &obb)
float w
Width of the box.
Definition object.hpp:89
float cy
Center y-coordinate.
Definition object.hpp:88
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:63
float x
X-coordinate of the keypoint.
Definition object.hpp:62
PosePoint & operator=(const PosePoint &other)
float vis
Visibility/confidence score (0 = invisible, 1 = visible).
Definition object.hpp:64
A set of keypoints representing a human or object pose.
Definition object.hpp:77
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:78
int width
Width of the mask in pixels (must be % 8 == 0).
Definition object.hpp:109
SegmentMap & operator=(const SegmentMap &)=delete
SegmentMap(SegmentMap &&other) noexcept
Move constructor — transfers ownership and resets source.
Definition object.hpp:124
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:111
SegmentMap(const SegmentMap &)=delete
Copy is disabled — use move semantics instead.
int height
Height of the mask in pixels.
Definition object.hpp:110
Instance segmentation result backed by an OpenCV mask.
Definition object.hpp:134
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:135
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:174
int track_id
Unique tracking identifier.
Definition object.hpp:175
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:178
std::vector< std::tuple< float, float > > track_trace
Trajectory trace as (x, y) positions from previous frames.
Definition object.hpp:181