|
12 | 12 | from __future__ import print_function |
13 | 13 |
|
14 | 14 | import numpy as np |
| 15 | +from shapely.geometry import Point |
| 16 | +from shapely.geometry.polygon import Polygon |
15 | 17 |
|
16 | 18 | from motmetrics.distances import iou_matrix, norm2squared_matrix |
17 | 19 | from motmetrics.mot import MOTAccumulator |
@@ -71,16 +73,14 @@ def compute_euc(a, b): |
71 | 73 | oids = np.empty(0) |
72 | 74 | hids = np.empty(0) |
73 | 75 | dists = np.empty((0, 0)) |
74 | | - |
75 | | - fgt = fid_to_fgt.get(fid, None) |
76 | | - fdt = fid_to_fdt.get(fid, None) |
77 | | - if fgt is not None and fdt is not None: |
78 | | - oids = fgt.index.get_level_values(1) |
79 | | - hids = fdt.index.get_level_values(1) |
80 | | - if len(oids) > 0 and len(hids) > 0: |
81 | | - # dists = compute_dist(fgt[distfields].values, fdt[distfields].values) |
82 | | - dists = compute_dist(fgt.values, fdt.values) |
83 | | - |
| 76 | + if fid in fid_to_fgt: |
| 77 | + fgt = fid_to_fgt[fid] |
| 78 | + oids = fgt.index.get_level_values('Id') |
| 79 | + if fid in fid_to_fdt: |
| 80 | + fdt = fid_to_fdt[fid] |
| 81 | + hids = fdt.index.get_level_values('Id') |
| 82 | + if len(oids) > 0 and len(hids) > 0: |
| 83 | + dists = compute_dist(fgt.values, fdt.values) |
84 | 84 | acc.update(oids, hids, dists, frameid=fid) |
85 | 85 |
|
86 | 86 | return acc |
@@ -163,3 +163,42 @@ def compute_euc(a, b): |
163 | 163 | acc.update(oids, hids, dists, frameid=fid, vf=vflag) |
164 | 164 |
|
165 | 165 | return acc, analysis |
| 166 | + |
| 167 | + |
| 168 | +# Andreu |
| 169 | +def is_in_region(bbox, reg): |
| 170 | + # Check if the 4 points of the bbox are inside region |
| 171 | + points = [] |
| 172 | + # Center |
| 173 | + cx = bbox[0] + (bbox[2] / 2) |
| 174 | + cy = bbox[1] + (bbox[3] / 2) |
| 175 | + points.append(Point(cx, cy)) |
| 176 | + # # Top-left |
| 177 | + # x1 = bbox[0] |
| 178 | + # y1 = bbox[1] |
| 179 | + # points.append(Point(x1, y1)) |
| 180 | + # # Top-right |
| 181 | + # x1 = bbox[0] + bbox[2] |
| 182 | + # y1 = bbox[1] |
| 183 | + # points.append(Point(x1, y1)) |
| 184 | + # # Bot-right |
| 185 | + # x1 = bbox[0] + bbox[2] |
| 186 | + # y1 = bbox[1] + bbox[3] |
| 187 | + # points.append(Point(x1, y1)) |
| 188 | + # # Bot-left |
| 189 | + # x1 = bbox[0] |
| 190 | + # y1 = bbox[1] + bbox[3] |
| 191 | + # points.append(Point(x1, y1)) |
| 192 | + |
| 193 | + # Region |
| 194 | + p_xy0 = (reg[0], reg[1]) |
| 195 | + p_xy1 = (reg[0] + reg[2], reg[1]) |
| 196 | + p_xy2 = (reg[0] + reg[2], reg[1] + reg[3]) |
| 197 | + p_xy3 = (reg[0], reg[1] + reg[3]) |
| 198 | + region = [p_xy0, p_xy1, p_xy2, p_xy3] |
| 199 | + polygon = Polygon(region) |
| 200 | + |
| 201 | + flags_inside = [polygon.contains(p) for p in points] |
| 202 | + flag_inside = all(flags_inside) |
| 203 | + |
| 204 | + return flag_inside |
0 commit comments