当前位置:网站首页>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
边栏推荐
- Ancient art - make good use of long tail keywords
- PSI|CSI和ROC|AUC和KS -备忘录
- Add virtual network card and configure OP route in win10
- 关于卡尔曼滤波的协方差如何影响deepsort的跟踪效果的考虑
- Go language learning
- Future, futuretask and completable future are often asked in interviews
- 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
- Rsync remote synchronization
- Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform
- 向日葵教大家如何防范拒绝服务攻击漏洞?
猜你喜欢

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

Alibaba cloud SMS authentication third-party interface (fast use)

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

FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生

ESXI虚拟机启动,模块“MonitorLoop”打开电源失败

Project training experience 2

ES6新特性(入门)

Disk management and file system

FTX US launched FTX stocks, striding forward to the mainstream financial industry

According to SQL, you must know and learn SQL (MySQL)
随机推荐
Px4 source code compilation to establish its own program module
正则表达式
Memo @restcontrolleradvice and exception interception class example
px4源码编译之 建立自己的程序模块
Redis' idea under windows is not connected
【12】 Understand the circuit: from telegraph to gate circuit, how can we "send messages from thousands of miles"?
FTX US launched FTX stocks, striding forward to the mainstream financial industry
如何避免漏洞?向日葵远程为你讲解不同场景下的安全使用方法
网站服务器被攻击怎么办?向日葵提示防范漏洞是关键
Keras OCR instance test
GoLand writes Go program
Shell programming specification and redirection and pipeline operation
FTP service introduction and configuration
Summary of frequently asked questions in the interview [summarized after painstaking work all night]
What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
Shell Function
Shell script backup MySQL database
RAID详解与配置
Install redis under Windows
Redis fast learning