当前位置:网站首页>deepsort源码解读(六)
deepsort源码解读(六)
2022-07-27 05:24:00 【德林恩宝】
track.py
# vim: expandtab:ts=4:sw=4
class TrackState:
"""
Enumeration type for the single target track state. Newly created tracks are
classified as `tentative` until enough evidence has been collected. Then,
the track state is changed to `confirmed`. Tracks that are no longer alive
are classified as `deleted` to mark them for removal from the set of active
tracks.
"""
# tentative即所谓的unconfirmed
Tentative = 1
Confirmed = 2
Deleted = 3
class Track:
"""
A single target track with state space `(x, y, a, h)` and associated
velocities, where `(x, y)` is the center of the bounding box, `a` is the
aspect ratio and `h` is the height.
Parameters
----------
mean : ndarray
Mean vector of the initial state distribution.
covariance : ndarray
Covariance matrix of the initial state distribution.
track_id : int
A unique track identifier.
n_init : int
Number of consecutive detections before the track is confirmed. The
track state is set to `Deleted` if a miss occurs within the first
`n_init` frames.
max_age : int
The maximum number of consecutive misses before the track state is
set to `Deleted`.
feature : Optional[ndarray]
Feature vector of the detection this track originates from. If not None,
this feature is added to the `features` cache.
Attributes
----------
mean : ndarray
Mean vector of the initial state distribution.
covariance : ndarray
Covariance matrix of the initial state distribution.
track_id : int
A unique track identifier.
hits : int
Total number of measurement updates.
表示匹配上了多少次,匹配次数超过n_init就会设置为confirmed状态
age : int
Total number of frames since first occurance.
time_since_update : int
Total number of frames since last measurement update.
表示失配的次数;被匹配时会被置零
state : TrackState
The current track state.
features : List[ndarray]
A cache of features. On each measurement update, the associated feature
vector is added to this list.
每个track对应多个features,每次更新都将最新的feature添加到列表中.
意义在于解决目标被遮挡后再次出现的问题,需要根据以往帧对应的特征inx匹配
"""
def __init__(self, mean, covariance, track_id, n_init, max_age,
feature=None):
self.mean = mean
self.covariance = covariance
self.track_id = track_id
self.hits = 1
self.age = 1
self.time_since_update = 0
self.state = TrackState.Tentative
self.features = []
if feature is not None:
self.features.append(feature)
self._n_init = n_init
self._max_age = max_age
def to_tlwh(self):
"""Get current position in bounding box format `(top left x, top left y,
width, height)`.
Returns
-------
ndarray
The bounding box.
"""
ret = self.mean[:4].copy()
ret[2] *= ret[3]
ret[:2] -= ret[2:] / 2
return ret
def to_tlbr(self):
"""Get current position in bounding box format `(min x, miny, max x,
max y)`.
Returns
-------
ndarray
The bounding box.
"""
ret = self.to_tlwh()
ret[2:] = ret[:2] + ret[2:]
return ret
# 利用卡尔曼滤波预测前一帧中的tracks在当前帧的状态
def predict(self, kf):
"""Propagate the state distribution to the current time step using a
Kalman filter prediction step.
Parameters
----------
kf : kalman_filter.KalmanFilter
The Kalman filter.
"""
# mean和covariance的功能
# 根据卡尔曼去预测这些track在当前帧的位置mean与covariance.
# 然后根据预测的均值和方差进行track与detection的匹配
# 卡尔曼预测的均值和方差的作用,在gate_cost_matrix()参与实现
# mean的格式[中心点坐标,w/h,h]
self.mean, self.covariance = kf.predict(self.mean, self.covariance)
self.age += 1
self.time_since_update += 1
# 匹配成功,进行更新参数值
def update(self, kf, detection):
"""Perform Kalman filter measurement update step and update the feature
cache.
Parameters
----------
kf : kalman_filter.KalmanFilter
The Kalman filter.
detection : Detection
The associated detection.
"""
self.mean, self.covariance = kf.update(
self.mean, self.covariance, detection.to_xyah())
self.features.append(detection.feature)
self.hits += 1
# 匹配成功,将time_since_update置为零
self.time_since_update = 0
if self.state == TrackState.Tentative and self.hits >= self._n_init:
self.state = TrackState.Confirmed
# 标记缺失,改为删除状态
def mark_missed(self):
"""Mark this track as missed (no association at the current time step).
"""
if self.state == TrackState.Tentative:
self.state = TrackState.Deleted
elif self.time_since_update > self._max_age:
self.state = TrackState.Deleted
# 状态判断
def is_tentative(self):
"""Returns True if this track is tentative (unconfirmed).
"""
return self.state == TrackState.Tentative
def is_confirmed(self):
"""Returns True if this track is confirmed."""
return self.state == TrackState.Confirmed
def is_deleted(self):
"""Returns True if this track is dead and should be deleted."""
return self.state == TrackState.Deleted
边栏推荐
- What if the website server is attacked? Sunflower tips that preventing loopholes is the key
- Boostrap
- 程序、进程、线程、协程以及单线程、多线程基本概念
- 向日葵全面科普,为你的远程控制设备及时规避漏洞
- Code random notes_ Hash_ 242 effective letter heterotopic words
- PSI|CSI和ROC|AUC和KS -备忘录
- Soul 递交港股上市申请,加快社交聚集地多元化、场景化的布局
- 系统安全与应用
- FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生
- Use of getattr, hasattr, delattr and setattr in reflectors
猜你喜欢

Li Hongyi 2020 deep learning and human language processing dlhlp core resolution-p21

FTX.US推出股票和ETF交易服务,让交易更透明

EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?

多模态数据库 | 星环科技多模数据库ArgoDB“一库多用“,构建高性能湖仓集一体平台

pycharm在虚拟环境下跑jupyter notebook问题记录

DNS域名解析服务

【11】 Binary code: "holding two roller handcuffs, crying out for hot hot hot"?

Linux安装Redis操作

ES6的新特性(2)

Project training experience 1
随机推荐
Account management and authority
2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!
Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
3D打印品牌的康复骨科支具有何特别之处?
Summary of frequently asked questions in the interview [summarized after painstaking work all night]
Linux Installation and uninstallation of MySQL
Redis fast learning
PSI | CSI and ROC | AUC and KS - memorandum
Keras OCR instance test
where接自定义函数导致查询缓慢
Memo @restcontrolleradvice and exception interception class example
FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生
Pymysql query result conversion JSON
ES6 new features (getting started)
Detection and identification data set and yolov5 model of helmet reflective clothing
Concept and principle of DHCP
FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health
如何让最小 API 绑定查询字符串中的数组
使用密钥方式登录阿里云服务器
NFS简介和配置