xuepengqiang
2020-05-26 bb5cb224c9abe4216aaa49a8287b06d9f05dab60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
3
¢-¸]_ ã@s6ddlmZddlZddlmZdd„Zd    dd„ZdS)
é)Úabsolute_importNé)Úlinear_assignmentc Csn|dd…|dd…|dd…}}|dd…dd…f}|dd…dd…f|dd…dd…f}tjtj|d|dd…dfƒdd…tjftj|d|dd…dfƒdd…tjff}tjtj|d|dd…dfƒdd…tjftj|d|dd…dfƒdd…tjff}tjd||ƒ}|jdd}    |dd…jƒ}
|dd…dd…fjdd} |    |
| |    S)aüComputer intersection over union.
 
    Parameters
    ----------
    bbox : ndarray
        A bounding box in format `(top left x, top left y, width, height)`.
    candidates : ndarray
        A matrix of candidate bounding boxes (one per row) in the same format
        as `bbox`.
 
    Returns
    -------
    ndarray
        The intersection over union in [0, 1] between the `bbox` and each
        candidate. A higher score means a larger fraction of the `bbox` is
        occluded by the candidate.
 
    Nérrg)Úaxis)ÚnpÚc_ÚmaximumÚnewaxisÚminimumÚprod) ÚbboxÚ
candidatesZbbox_tlZbbox_brZ candidates_tlZ candidates_brÚtlÚbrZwhZarea_intersectionZ    area_bboxZarea_candidates©rúMD:\project\07_tracking_Re-id\04_s_yolo_tracking\lib\deep_sort\iou_matching.pyÚious&(,.,. rc    s¼|dkrtjt|ƒƒ}|dkr,tjtˆƒƒ}tjt|ƒt|ƒfƒ}xtt|ƒD]h\}}||jdkrvtj||dd…f<qL||jƒ}tj    ‡fdd„|Dƒƒ}dt
||ƒ||dd…f<qLW|S)aâAn intersection over union distance metric.
 
    Parameters
    ----------
    tracks : List[deep_sort.track.Track]
        A list of tracks.
    detections : List[deep_sort.detection.Detection]
        A list of detections.
    track_indices : Optional[List[int]]
        A list of indices to tracks that should be matched. Defaults to
        all `tracks`.
    detection_indices : Optional[List[int]]
        A list of indices to detections that should be matched. Defaults
        to all `detections`.
 
    Returns
    -------
    ndarray
        Returns a cost matrix of shape
        len(track_indices), len(detection_indices) where entry (i, j) is
        `1 - iou(tracks[track_indices[i]], detections[detection_indices[j]])`.
 
    Nrcsg|]}ˆ|j‘qSr)Útlwh)Ú.0Úi)Ú
detectionsrrú
<listcomp>Osziou_cost.<locals>.<listcomp>gð?) rÚarangeÚlenÚzerosÚ    enumerateÚtime_since_updaterÚ
INFTY_COSTZto_tlwhÚasarrayr)    ÚtracksrÚ track_indicesÚdetection_indicesÚ cost_matrixÚrowÚ    track_idxr rr)rrÚiou_cost*s r&)NN)Ú
__future__rÚnumpyrÚrrr&rrrrÚ<module>s
 #