39 constexpr
float EPS =
static_cast<float>(1e-8);
65 return (p1.
x_ - p0.
x_) * (p2.
y_ - p0.
y_) -
73 int ret = fmin(p1.
x_, p2.
x_) <= fmax(q1.
x_, q2.
x_) &&
74 fmin(q1.
x_, q2.
x_) <= fmax(p1.
x_, p2.
x_) &&
75 fmin(p1.
y_, p2.
y_) <= fmax(q1.
y_, q2.
y_) &&
76 fmin(q1.
y_, q2.
y_) <= fmax(p1.
y_, p2.
y_);
82 const float MARGIN =
static_cast<float>(1e-5);
84 float center_x = (box[0] + box[2]) / 2;
85 float center_y = (box[1] + box[3]) / 2;
87 float angle_cos = cos(-box[4]), angle_sin = sin(-box[4]);
88 float rot_x = (p.
x_ - center_x) * angle_cos +
89 (p.
y_ - center_y) * angle_sin + center_x;
90 float rot_y = -(p.
x_ - center_x) * angle_sin +
91 (p.
y_ - center_y) * angle_cos + center_y;
92 return (rot_x > box[0] - MARGIN && rot_x < box[2] + MARGIN &&
93 rot_y > box[1] - MARGIN && rot_y < box[3] + MARGIN);
105 float s1 =
Cross(q0, p1, p0);
106 float s2 =
Cross(p1, q1, p0);
107 float s3 =
Cross(p0, q1, q0);
108 float s4 =
Cross(q1, p1, q0);
110 if (!(s1 * s2 > 0 && s3 * s4 > 0))
return 0;
113 float s5 =
Cross(q1, p1, p0);
114 if (fabs(s5 - s1) > EPS) {
115 ans.
x_ = (s5 * q0.
x_ - s1 * q1.
x_) / (s5 - s1);
116 ans.
y_ = (s5 * q0.
y_ - s1 * q1.
y_) / (s5 - s1);
119 float a0 = p0.
y_ - p1.
y_, b0 = p1.
x_ - p0.
x_,
121 float a1 = q0.
y_ - q1.
y_, b1 = q1.
x_ - q0.
x_,
123 float D = a0 * b1 - a1 * b0;
125 ans.
x_ = (b0 * c1 - b1 * c0) / D;
126 ans.
y_ = (a1 * c0 - a0 * c1) / D;
133 const float angle_cos,
134 const float angle_sin,
136 float new_x = (p.
x_ - center.
x_) * angle_cos +
137 (p.
y_ - center.
y_) * angle_sin + center.
x_;
138 float new_y = -(p.
x_ - center.
x_) * angle_sin +
139 (p.
y_ - center.
y_) * angle_cos + center.
y_;
145 const Point ¢er) {
146 return atan2(a.
y_ - center.
y_, a.
x_ - center.
x_) >
147 atan2(b.
y_ - center.
y_, b.
x_ - center.
x_);
151 const float *box_b) {
154 float a_x1 = box_a[0], a_y1 = box_a[1], a_x2 = box_a[2], a_y2 = box_a[3],
156 float b_x1 = box_b[0], b_y1 = box_b[1], b_x2 = box_b[2], b_y2 = box_b[3],
159 Point center_a((a_x1 + a_x2) / 2, (a_y1 + a_y2) / 2);
160 Point center_b((b_x1 + b_x2) / 2, (b_y1 + b_y2) / 2);
162 Point box_a_corners[5];
163 box_a_corners[0].
set(a_x1, a_y1);
164 box_a_corners[1].
set(a_x2, a_y1);
165 box_a_corners[2].
set(a_x2, a_y2);
166 box_a_corners[3].
set(a_x1, a_y2);
168 Point box_b_corners[5];
169 box_b_corners[0].
set(b_x1, b_y1);
170 box_b_corners[1].
set(b_x2, b_y1);
171 box_b_corners[2].
set(b_x2, b_y2);
172 box_b_corners[3].
set(b_x1, b_y2);
175 float a_angle_cos = cos(a_angle), a_angle_sin = sin(a_angle);
176 float b_angle_cos = cos(b_angle), b_angle_sin = sin(b_angle);
178 for (
int k = 0; k < 4; k++) {
185 box_a_corners[4] = box_a_corners[0];
186 box_b_corners[4] = box_b_corners[0];
189 Point cross_points[16];
191 int cnt = 0, flag = 0;
193 poly_center.
set(0, 0);
194 for (
int i = 0; i < 4; i++) {
195 for (
int j = 0; j < 4; j++) {
196 flag =
Intersection(box_a_corners[i + 1], box_a_corners[i],
197 box_b_corners[j + 1], box_b_corners[j],
200 poly_center = poly_center + cross_points[cnt];
207 for (
int k = 0; k < 4; k++) {
209 poly_center = poly_center + box_b_corners[k];
210 cross_points[cnt] = box_b_corners[k];
214 poly_center = poly_center + box_a_corners[k];
215 cross_points[cnt] = box_a_corners[k];
222 poly_center.
x_ /= cnt;
223 poly_center.
y_ /= cnt;
227 for (
int j = 0; j < cnt - 1; j++) {
228 for (
int i = 0; i < cnt - j - 1; i++) {
229 if (
PointCmp(cross_points[i], cross_points[i + 1], poly_center)) {
230 temp = cross_points[i];
231 cross_points[i] = cross_points[i + 1];
232 cross_points[i + 1] = temp;
239 for (
int k = 0; k < cnt - 1; k++) {
240 area +=
Cross(cross_points[k] - cross_points[0],
241 cross_points[k + 1] - cross_points[0]);
244 return static_cast<float>(fabs(area)) / 2.0f;
251 bool intersection_only =
false) {
254 float sa = (box_a[2] - box_a[0]) * (box_a[3] - box_a[1]);
255 float sb = (box_b[2] - box_b[0]) * (box_b[3] - box_b[1]);
257 if (intersection_only) {
260 return s_overlap / fmaxf(sa + sb - s_overlap, EPS);
268 bool intersection_only =
false) {
270 box_a_new[0] = box_a[0] - box_a[2] / 2;
271 box_a_new[1] = box_a[1] - box_a[3] / 2;
272 box_a_new[2] = box_a[0] + box_a[2] / 2;
273 box_a_new[3] = box_a[1] + box_a[3] / 2;
274 box_a_new[4] = box_a[4];
277 box_b_new[0] = box_b[0] - box_b[2] / 2;
278 box_b_new[1] = box_b[1] - box_b[3] / 2;
279 box_b_new[2] = box_b[0] + box_b[2] / 2;
280 box_b_new[3] = box_b[1] + box_b[3] / 2;
281 box_b_new[4] = box_b[4];
287 const float *box_b) {
289 box_a_2d[0] = box_a[0];
290 box_a_2d[1] = box_a[2];
291 box_a_2d[2] = box_a[3];
292 box_a_2d[3] = box_a[5];
293 box_a_2d[4] = box_a[6];
296 box_b_2d[0] = box_b[0];
297 box_b_2d[1] = box_b[2];
298 box_b_2d[2] = box_b[3];
299 box_b_2d[3] = box_b[5];
300 box_b_2d[4] = box_b[6];
303 float y_a_min = box_a[1] - box_a[4];
304 float y_a_max = box_a[1];
305 float y_b_min = box_b[1] - box_b[4];
306 float y_b_max = box_b[1];
307 float iw = (y_a_max < y_b_max ? y_a_max : y_b_max) -
308 (y_a_min > y_b_min ? y_a_min : y_b_min);
311 float intersection_3d = intersection_2d * iw;
312 float volume_a = box_a[3] * box_a[4] * box_a[5];
313 float volume_b = box_b[3] * box_b[4] * box_b[5];
314 float union_3d = volume_a + volume_b - intersection_3d;
315 iou_3d = intersection_3d / union_3d;
OPEN3D_HOST_DEVICE float IoUBev2DWithMinAndMax(const float *box_a, const float *box_b, bool intersection_only=false)
(x_min, z_min, x_max, z_max, y_rotate)
Definition: IoUImpl.h:248
OPEN3D_HOST_DEVICE float IoUBev2DWithCenterAndSize(const float *box_a, const float *box_b, bool intersection_only=false)
(x_center, z_center, x_size, z_size, y_rotate)
Definition: IoUImpl.h:265
OPEN3D_HOST_DEVICE int Intersection(const Point &p1, const Point &p0, const Point &q1, const Point &q0, Point &ans)
Definition: IoUImpl.h:96
OPEN3D_HOST_DEVICE Point operator+(const Point &b) const
Definition: IoUImpl.h:48
OPEN3D_HOST_DEVICE float BoxOverlap(const float *box_a, const float *box_b)
Definition: IoUImpl.h:150
constexpr float EPS
Definition: IoUImpl.h:39
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample uint64_t
Definition: K4aPlugin.cpp:352
float y_
Definition: IoUImpl.h:55
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:63
OPEN3D_HOST_DEVICE void RotateAroundCenter(const Point ¢er, const float angle_cos, const float angle_sin, Point &p)
Definition: IoUImpl.h:132
OPEN3D_HOST_DEVICE void set(float x, float y)
Definition: IoUImpl.h:44
OPEN3D_HOST_DEVICE int CheckRectCross(const Point &p1, const Point &p2, const Point &q1, const Point &q2)
Definition: IoUImpl.h:69
constexpr int NMS_BLOCK_SIZE
Definition: IoUImpl.h:38
OPEN3D_HOST_DEVICE Point()
Definition: IoUImpl.h:42
OPEN3D_HOST_DEVICE float IoU3DWithCenterAndSize(const float *box_a, const float *box_b)
(x_center, y_max, z_center, x_size, y_size, z_size, y_rotate)
Definition: IoUImpl.h:286
Definition: PinholeCameraIntrinsic.cpp:35
#define OPEN3D_ASSERT(...)
Definition: Macro.h:67
OPEN3D_HOST_DEVICE int PointCmp(const Point &a, const Point &b, const Point ¢er)
Definition: IoUImpl.h:143
OPEN3D_HOST_DEVICE float Cross(const Point &a, const Point &b)
Definition: IoUImpl.h:58
OPEN3D_HOST_DEVICE Point operator-(const Point &b) const
Definition: IoUImpl.h:51
float x_
Definition: IoUImpl.h:54
OPEN3D_HOST_DEVICE int CheckInBox2D(const float *box, const Point &p)
Definition: IoUImpl.h:80
OPEN3D_HOST_DEVICE Point(float x, float y)
Definition: IoUImpl.h:43