63 const float MARGIN =
static_cast<float>(1e-5);
65 float center_x = (box[0] + box[2]) / 2;
66 float center_y = (box[1] + box[3]) / 2;
68 float angle_cos = cos(-box[4]), angle_sin = sin(-box[4]);
69 float rot_x = (p.
x_ - center_x) * angle_cos +
70 (p.
y_ - center_y) * angle_sin + center_x;
71 float rot_y = -(p.
x_ - center_x) * angle_sin +
72 (p.
y_ - center_y) * angle_cos + center_y;
73 return (rot_x > box[0] - MARGIN && rot_x < box[2] + MARGIN &&
74 rot_y > box[1] - MARGIN && rot_y < box[3] + MARGIN);
132 const float *box_b) {
135 float a_x1 = box_a[0], a_y1 = box_a[1], a_x2 = box_a[2], a_y2 = box_a[3],
137 float b_x1 = box_b[0], b_y1 = box_b[1], b_x2 = box_b[2], b_y2 = box_b[3],
140 Point center_a((a_x1 + a_x2) / 2, (a_y1 + a_y2) / 2);
141 Point center_b((b_x1 + b_x2) / 2, (b_y1 + b_y2) / 2);
143 Point box_a_corners[5];
144 box_a_corners[0].
set(a_x1, a_y1);
145 box_a_corners[1].
set(a_x2, a_y1);
146 box_a_corners[2].
set(a_x2, a_y2);
147 box_a_corners[3].
set(a_x1, a_y2);
149 Point box_b_corners[5];
150 box_b_corners[0].
set(b_x1, b_y1);
151 box_b_corners[1].
set(b_x2, b_y1);
152 box_b_corners[2].
set(b_x2, b_y2);
153 box_b_corners[3].
set(b_x1, b_y2);
156 float a_angle_cos = cos(a_angle), a_angle_sin = sin(a_angle);
157 float b_angle_cos = cos(b_angle), b_angle_sin = sin(b_angle);
159 for (
int k = 0; k < 4; k++) {
166 box_a_corners[4] = box_a_corners[0];
167 box_b_corners[4] = box_b_corners[0];
170 Point cross_points[16];
172 int cnt = 0, flag = 0;
174 poly_center.
set(0, 0);
175 for (
int i = 0; i < 4; i++) {
176 for (
int j = 0; j < 4; j++) {
177 flag =
Intersection(box_a_corners[i + 1], box_a_corners[i],
178 box_b_corners[j + 1], box_b_corners[j],
181 poly_center = poly_center + cross_points[cnt];
188 for (
int k = 0; k < 4; k++) {
190 poly_center = poly_center + box_b_corners[k];
191 cross_points[cnt] = box_b_corners[k];
195 poly_center = poly_center + box_a_corners[k];
196 cross_points[cnt] = box_a_corners[k];
203 poly_center.
x_ /= cnt;
204 poly_center.
y_ /= cnt;
208 for (
int j = 0; j < cnt - 1; j++) {
209 for (
int i = 0; i < cnt - j - 1; i++) {
210 if (
PointCmp(cross_points[i], cross_points[i + 1], poly_center)) {
211 temp = cross_points[i];
212 cross_points[i] = cross_points[i + 1];
213 cross_points[i + 1] = temp;
220 for (
int k = 0; k < cnt - 1; k++) {
221 area +=
Cross(cross_points[k] - cross_points[0],
222 cross_points[k + 1] - cross_points[0]);
225 return static_cast<float>(fabs(
area)) / 2.0f;
249 bool intersection_only =
false) {
251 box_a_new[0] = box_a[0] - box_a[2] / 2;
252 box_a_new[1] = box_a[1] - box_a[3] / 2;
253 box_a_new[2] = box_a[0] + box_a[2] / 2;
254 box_a_new[3] = box_a[1] + box_a[3] / 2;
255 box_a_new[4] = box_a[4];
258 box_b_new[0] = box_b[0] - box_b[2] / 2;
259 box_b_new[1] = box_b[1] - box_b[3] / 2;
260 box_b_new[2] = box_b[0] + box_b[2] / 2;
261 box_b_new[3] = box_b[1] + box_b[3] / 2;
262 box_b_new[4] = box_b[4];
268 const float *box_b) {
270 box_a_2d[0] = box_a[0];
271 box_a_2d[1] = box_a[2];
272 box_a_2d[2] = box_a[3];
273 box_a_2d[3] = box_a[5];
274 box_a_2d[4] = box_a[6];
277 box_b_2d[0] = box_b[0];
278 box_b_2d[1] = box_b[2];
279 box_b_2d[2] = box_b[3];
280 box_b_2d[3] = box_b[5];
281 box_b_2d[4] = box_b[6];
284 float y_a_min = box_a[1] - box_a[4];
285 float y_a_max = box_a[1];
286 float y_b_min = box_b[1] - box_b[4];
287 float y_b_max = box_b[1];
288 float iw = (y_a_max < y_b_max ? y_a_max : y_b_max) -
289 (y_a_min > y_b_min ? y_a_min : y_b_min);
292 float intersection_3d = intersection_2d * iw;
293 float volume_a = box_a[3] * box_a[4] * box_a[5];
294 float volume_b = box_b[3] * box_b[4] * box_b[5];
295 float union_3d = volume_a + volume_b - intersection_3d;
296 iou_3d = intersection_3d / union_3d;
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:246
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:229
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:267