当前位置:网站首页>deepsort源码解读(二)
deepsort源码解读(二)
2022-07-27 05:24:00 【德林恩宝】
iou_matching.py
# vim: expandtab:ts=4:sw=4
from __future__ import absolute_import
import numpy as np
from . import linear_assignment
def iou(bbox, candidates):
"""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.
"""
bbox_tl, bbox_br = bbox[:2], bbox[:2] + bbox[2:]
candidates_tl = candidates[:, :2]
candidates_br = candidates[:, :2] + candidates[:, 2:]
tl = np.c_[np.maximum(bbox_tl[0], candidates_tl[:, 0])[:, np.newaxis],
np.maximum(bbox_tl[1], candidates_tl[:, 1])[:, np.newaxis]]
br = np.c_[np.minimum(bbox_br[0], candidates_br[:, 0])[:, np.newaxis],
np.minimum(bbox_br[1], candidates_br[:, 1])[:, np.newaxis]]
wh = np.maximum(0., br - tl)
area_intersection = wh.prod(axis=1)
area_bbox = bbox[2:].prod()
area_candidates = candidates[:, 2:].prod(axis=1)
return area_intersection / (area_bbox + area_candidates - area_intersection)
def iou_cost(tracks, detections, track_indices=None,
detection_indices=None):
"""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]])`.
"""
if track_indices is None:
track_indices = np.arange(len(tracks))
if detection_indices is None:
detection_indices = np.arange(len(detections))
cost_matrix = np.zeros((len(track_indices), len(detection_indices)))
for row, track_idx in enumerate(track_indices):
# 将time_since_update=1的track赋值为无穷大代价
if tracks[track_idx].time_since_update > 1:
cost_matrix[row, :] = linear_assignment.INFTY_COST
continue
bbox = tracks[track_idx].to_tlwh()
candidates = np.asarray([detections[i].tlwh for i in detection_indices])
# 计算track与所有unmatched_detections的iou代价
cost_matrix[row, :] = 1. - iou(bbox, candidates)
return cost_matrix
边栏推荐
- Concept and principle of DHCP
- IoTDB 的C# 客户端发布 0.13.0.7
- Socket programming II: using Select
- C语言怎么学?这篇文章给你完整答案
- Go语言学习
- What is special about the rehabilitation orthopedic branch of 3D printing brand?
- When a subclass calls the constructor of its parent class
- Shell sentence judgment exercise
- Is it feasible to fix the vulnerability with one click? Sunflower to tell you that one click fix vulnerability is feasible? Sunflower to tell you that one click fix vulnerability is feasible? Sunflowe
- Boostrap
猜你喜欢

Shell -- operation of variables

PSI | CSI and ROC | AUC and KS - memorandum

NFS introduction and configuration

Packaging of logging logs

According to SQL, you must know and learn SQL (MySQL)

Sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then judge sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then ju

Linux Installation and uninstallation of MySQL

ES6新特性(入门)

众多世界500强企业集聚第二届数博会,数字产业大幕即将开启!

Esxi virtual machine starts, and the module "monitorloop" fails to power on
随机推荐
IoTDB 的C# 客户端发布 0.13.0.7
NFS introduction and configuration
Use of getattr, hasattr, delattr and setattr in reflectors
Common font and color settings of markdown documents
磁盘管理与文件系统
Talk about why you need to declare the member function of a class as private
What is the reason why dragging the timeline is invalid when playing device videos on the easycvr platform?
Brief introduction of chip, memory and its key indicators I
1. Install redis in CentOS 7
Rsync remote synchronization
FTX US launched FTX stocks, striding forward to the mainstream financial industry
Redis快速学习
如何删除或替换EasyPlayer流媒体播放器的loading样式?
EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?
Soul continues to make efforts to list its social channels in Hong Kong. Why is "soul style social" popular?
Pruning - quantification - turn to onnx Chinese series tutorials
Redis operation of Linux Installation
Numpy array and image conversion
Esxi virtual machine starts, and the module "monitorloop" fails to power on
Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places