当前位置:网站首页>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
边栏推荐
- Keras OCR instance test
- Redis快速学习
- Rsync remote synchronization
- Decorator functions and the use of class decorators
- Some problems about too fast s verification code
- How to avoid loopholes? Sunflower remote explains the safe use methods in different scenarios
- NAT(网络地址转换)
- The problem of torch loading custom models
- PSI | CSI and ROC | AUC and KS - memorandum
- 1. Install redis in CentOS 7
猜你喜欢

ES6的新特性(2)

Iptables firewall

Shell -- conditional statements (if statements, case statements)

网站服务器被攻击怎么办?向日葵提示防范漏洞是关键

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

正则表达式

Soul持续发力社交渠道赴港上市,“Soul式社交”凭什么火出圈?

Redis fast learning

FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health

磁盘管理与文件系统
随机推荐
Sunflower popularizes Science in an all-round way to avoid loopholes for your remote control equipment in time
RAID详解与配置
Common font and color settings of markdown documents
Future, futuretask and completable future are often asked in interviews
Express接收请求参数
FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生
3D打印品牌的康复骨科支具有何特别之处?
Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
gin-vue-admin 使用docker容器中的数据库
Shell script backup MySQL database
Three methods to judge whether it is palindrome structure
KVM command set management virtual machine
2022年全球最具技术实力的的智能合约安全审计公司推荐
2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!
向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解
Linux安装Redis操作
FTX.US推出股票和ETF交易服务,让交易更透明
NFS introduction and configuration
IoTDB 的C# 客户端发布 0.13.0.7
Keras OCR instance test