| 48 | |
| 49 | |
| 50 | def linear_assignment(cost_matrix, thresh): |
| 51 | if cost_matrix.size == 0: |
| 52 | return np.empty((0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple(range(cost_matrix.shape[1])) |
| 53 | matches, unmatched_a, unmatched_b = [], [], [] |
| 54 | cost, x, y = lap.lapjv(cost_matrix, extend_cost=True, cost_limit=thresh) |
| 55 | for ix, mx in enumerate(x): |
| 56 | if mx >= 0: |
| 57 | matches.append([ix, mx]) |
| 58 | unmatched_a = np.where(x < 0)[0] |
| 59 | unmatched_b = np.where(y < 0)[0] |
| 60 | matches = np.asarray(matches) |
| 61 | return matches, unmatched_a, unmatched_b |
| 62 | |
| 63 | |
| 64 | def ious(atlbrs, btlbrs): |