ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
object.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6#include <opencv2/opencv.hpp>
7
8#include <optional>
9#include <ostream>
10#include <string>
11#include <tuple>
12#include <vector>
13
15
18enum class ObjectType {
19 unknown = -1,
21 pose = 1,
22 obb = 2,
26 track = 6,
28};
29
32struct Box {
33 float left = 0.0f;
34 float top = 0.0f;
35 float right = 0.0f;
36 float bottom = 0.0f;
37
38 Box() = default;
39
45 Box(float l, float t, float r, float b);
46
48 float width() const noexcept { return right - left; }
49
51 float height() const noexcept { return bottom - top; }
52
54 float center_x() const noexcept { return (left + right) / 2; }
55
57 float center_y() const noexcept { return (top + bottom) / 2; }
58
60 float area() const noexcept { return width() * height(); }
61
62 friend std::ostream &operator<<(std::ostream &os, const Box &box);
63};
64
66struct PosePoint {
67 float x = 0.0f;
68 float y = 0.0f;
69 float vis = 0.0f;
71
72 PosePoint() = default;
73
75 PosePoint(float x, float y, float vis);
76
78 friend std::ostream &operator<<(std::ostream &os, const PosePoint &point);
79};
80
82struct Pose {
83 std::vector<PosePoint> points;
84
85 Pose &operator=(const Pose &other);
86 friend std::ostream &operator<<(std::ostream &os, const Pose &pose);
87};
88
91struct Obb {
92 float cx = 0.0f;
93 float cy = 0.0f;
94 float w = 0.0f;
95 float h = 0.0f;
96 float angle = 0.0f;
97
98 Obb() = default;
99
101 Obb(float cx, float cy, float w, float h, float angle);
102
103 Obb &operator=(const Obb &other);
104
106 float area() const { return w * h; }
107
108 friend std::ostream &operator<<(std::ostream &os, const Obb &obb);
109};
110
114 int width = 0;
115 int height = 0;
116 unsigned char *data = nullptr;
117
121
122 virtual ~SegmentMap();
123
125 SegmentMap(const SegmentMap &) = delete;
126 SegmentMap &operator=(const SegmentMap &) = delete;
127
129 SegmentMap(SegmentMap &&other) noexcept
130 : width(std::exchange(other.width, 0)),
131 height(std::exchange(other.height, 0)),
132 data(std::exchange(other.data, nullptr)) {}
133
135 SegmentMap &operator=(SegmentMap &&other) noexcept;
136};
137
140 cv::Mat mask;
141
144
147 Segmentation align_to_left_top(int left, int top, int width,
148 int height) const;
149
151};
152
154struct Depth {
155 cv::Mat depth;
156 float fog_data = 0.0f;
157
159 float point_depth(int x, int y) const;
160
162 float average_depth() const;
163
165 float min_depth() const;
166
168 float max_depth() const;
169
172 float area_average_depth(const cv::Mat &seg) const;
173
175 float area_average_depth(const Box &box) const;
176};
177
179struct Track {
180 int track_id = -1;
181
183 std::optional<std::vector<Pose>> history_pose;
184
186 std::vector<std::tuple<float, float>> track_trace;
187
188 friend std::ostream &operator<<(std::ostream &os, const Track &track);
189};
190
196 float score = 0.0f;
197 int class_id = -1;
198 std::string class_name;
199
200 std::optional<Pose> pose;
201 std::optional<Obb> obb;
202 std::optional<Segmentation>
204 std::optional<Depth> depth;
205 std::optional<Track> track;
206
207 friend std::ostream &operator<<(std::ostream &os, const DetectionBox &box);
208};
209
213cv::Mat segment_map_to_mat(const std::shared_ptr<SegmentMap> &map);
214
216using DetectionBoxArray = std::vector<DetectionBox>;
217
218} // namespace reusex::vision::common::object
std::vector< DetectionBox > DetectionBoxArray
Convenience alias for a collection of DetectionBox results.
Definition object.hpp:216
cv::Mat segment_map_to_mat(const std::shared_ptr< SegmentMap > &map)
Convert a SegmentMap to an OpenCV Mat (zero-copy header wrapper).
ObjectType
Enumeration of supported detection object types.
Definition object.hpp:18
@ pose
Human pose estimation result.
Definition object.hpp:21
@ track
Multi-object tracking result.
Definition object.hpp:26
@ position
Simple position/region of interest.
Definition object.hpp:20
@ segmentation
Instance segmentation mask.
Definition object.hpp:23
@ depth_pro
Depth map from DepthPro model.
Definition object.hpp:25
@ detection
Standard bounding box detection.
Definition object.hpp:27
@ unknown
Unknown or unclassified object type.
Definition object.hpp:19
@ depth_anything
Depth map from DepthAnything model.
Definition object.hpp:24
Axis-aligned bounding box defined by (left, top, right, bottom) coordinates.
Definition object.hpp:32
float area() const noexcept
Returns the area of the box.
Definition object.hpp:60
float center_x() const noexcept
Returns the x-coordinate of the box center.
Definition object.hpp:54
float center_y() const noexcept
Returns the y-coordinate of the box center.
Definition object.hpp:57
Box(float l, float t, float r, float b)
Construct a Box with explicit corner coordinates.
float bottom
Bottom edge y-coordinate.
Definition object.hpp:36
friend std::ostream & operator<<(std::ostream &os, const Box &box)
float left
Left edge x-coordinate.
Definition object.hpp:33
float width() const noexcept
Returns the width of the box.
Definition object.hpp:48
float right
Right edge x-coordinate.
Definition object.hpp:35
float height() const noexcept
Returns the height of the box.
Definition object.hpp:51
float top
Top edge y-coordinate.
Definition object.hpp:34
Depth map result with per-pixel depth values.
Definition object.hpp:154
float area_average_depth(const cv::Mat &seg) const
Returns the average depth within the region indicated by a segmentation mask.
float average_depth() const
Returns the average depth over the entire map.
float fog_data
Optional fog/haze estimate.
Definition object.hpp:156
float area_average_depth(const Box &box) const
Returns the average depth within the given bounding box region.
float min_depth() const
Returns the minimum depth value.
cv::Mat depth
CV_32F depth image.
Definition object.hpp:155
float max_depth() const
Returns the maximum depth value.
float point_depth(int x, int y) const
Returns the depth at pixel (x, y).
Universal detection result container that holds a bounding box plus optional enriched data (pose,...
Definition object.hpp:193
std::optional< Segmentation > segmentation
Populated for SEGMENTATION detections.
Definition object.hpp:203
ObjectType type
Type of this detection.
Definition object.hpp:194
std::optional< Pose > pose
Populated for POSE detections.
Definition object.hpp:200
std::optional< Track > track
Populated for TRACK detections.
Definition object.hpp:205
Box box
Axis-aligned bounding box.
Definition object.hpp:195
std::optional< Obb > obb
Populated for OBB detections.
Definition object.hpp:201
friend std::ostream & operator<<(std::ostream &os, const DetectionBox &box)
float score
Confidence score in [0, 1].
Definition object.hpp:196
std::string class_name
Human-readable class label.
Definition object.hpp:198
std::optional< Depth > depth
Populated for DEPTH_* detections.
Definition object.hpp:204
Obb & operator=(const Obb &other)
float h
Height of the box.
Definition object.hpp:95
Obb(float cx, float cy, float w, float h, float angle)
Construct an Obb with center, size, and angle.
friend std::ostream & operator<<(std::ostream &os, const Obb &obb)
float angle
Rotation angle in degrees.
Definition object.hpp:96
float w
Width of the box.
Definition object.hpp:94
float cy
Center y-coordinate.
Definition object.hpp:93
float cx
Center x-coordinate.
Definition object.hpp:92
float area() const
Returns the area of the oriented bounding box.
Definition object.hpp:106
friend std::ostream & operator<<(std::ostream &os, const PosePoint &point)
float x
X-coordinate of the keypoint.
Definition object.hpp:67
float y
Y-coordinate of the keypoint.
Definition object.hpp:68
float vis
Visibility/confidence score (0 = invisible, 1 = visible).
Definition object.hpp:69
PosePoint & operator=(const PosePoint &other)
PosePoint(float x, float y, float vis)
Construct a PosePoint with position and visibility.
A set of keypoints representing a human or object pose.
Definition object.hpp:82
friend std::ostream & operator<<(std::ostream &os, const Pose &pose)
Pose & operator=(const Pose &other)
std::vector< PosePoint > points
Ordered list of pose keypoints.
Definition object.hpp:83
SegmentMap(SegmentMap &&other) noexcept
Move constructor — transfers ownership and resets source.
Definition object.hpp:129
SegmentMap(int width, int height)
Allocate a SegmentMap of the given dimensions using pinned CUDA host memory.
SegmentMap & operator=(const SegmentMap &)=delete
int height
Height of the mask in pixels.
Definition object.hpp:115
unsigned char * data
Raw mask data (width * height bytes).
Definition object.hpp:116
SegmentMap & operator=(SegmentMap &&other) noexcept
Move assignment — transfers ownership and resets source.
int width
Width of the mask in pixels (must be % 8 == 0).
Definition object.hpp:114
SegmentMap(const SegmentMap &)=delete
Copy is disabled — use move semantics instead.
Instance segmentation result backed by an OpenCV mask.
Definition object.hpp:139
Segmentation & operator=(const Segmentation &other)
cv::Mat mask
Binary or grayscale segmentation mask.
Definition object.hpp:140
void keep_largest_part()
Retain only the largest connected component in the mask.
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:179
std::vector< std::tuple< float, float > > track_trace
Trajectory trace as (x, y) positions from previous frames.
Definition object.hpp:186
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:183
int track_id
Unique tracking identifier.
Definition object.hpp:180