Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_opencv
提交
acbd36a9
S
skill_tree_opencv
项目概览
CSDN 技术社区
/
skill_tree_opencv
通知
44
Star
9
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
acbd36a9
编写于
12月 16, 2021
作者:
F
feilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修正车辆目标跟踪的路径bug
上级
cfdcccae
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
15 deletion
+19
-15
data/1.OpenCV初阶/6.视频分析/2.目标跟踪/obj_tracker_run.py
data/1.OpenCV初阶/6.视频分析/2.目标跟踪/obj_tracker_run.py
+19
-15
未找到文件。
data/1.OpenCV初阶/6.视频分析/2.目标跟踪/obj_tracker_run.py
浏览文件 @
acbd36a9
...
...
@@ -19,6 +19,8 @@ tracks = np.empty((0, 5))
sort
=
Sort
(
5
,
0
,
0.2
)
# do track and render on image
def
track_and_render
(
detections
,
img
):
global
total_frames
global
total_time
...
...
@@ -35,17 +37,18 @@ def track_and_render(detections, img):
else
:
# if skip frame in detection process
tracks
=
sort
.
update
()
# get the fps, calculate avg speed in 100 frames
cycle_time
=
time
.
time
()
-
start_time
total_time
+=
cycle_time
if
total_frames
%
100
==
0
:
print
(
"Total Tracking took: %.3f seconds for %d frames or %.1f FPS"
%
(
total_time
,
total_frames
,
total_frames
/
total_time
))
print
(
"Total Tracking took: %.3f seconds for %d frames or %.1f FPS"
%
(
total_time
,
total_frames
,
total_frames
/
total_time
))
total_time
=
0.0
total_frames
=
0
# render on frame image
for
track
in
tracks
:
for
track
in
tracks
:
# [left, top, right, bottom, id]
pt1
=
(
int
(
track
[
0
]),
int
(
track
[
1
]))
pt2
=
(
int
(
track
[
2
]),
int
(
track
[
3
]))
...
...
@@ -53,7 +56,7 @@ def track_and_render(detections, img):
cv2
.
putText
(
img
,
str
(
int
(
track
[
4
])),
(
pt1
[
0
],
pt1
[
1
]
-
5
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.7
,
(
0
,
255
,
255
),
1
)
(
0
,
255
,
255
),
1
)
# return frame image to caller
return
img
...
...
@@ -61,34 +64,35 @@ def track_and_render(detections, img):
# main
if
__name__
==
'__main__'
:
# detection data, generated by object-detector algo model, including frame image
path
=
'mot_benchmark
\\
MY_TEST
\\
www3'
path
=
'mot_benchmark
/MY_TEST/
www3'
# read test data from disk in a loop one frame by frame and send it to sort tracker
for
i
in
range
(
400000
):
# read frame image
bg
=
cv2
.
imread
(
path
+
'
\\
'
+
str
(
i
%
800
+
1
)
+
'.jpg'
)
bg
=
cv2
.
imread
(
path
+
'
/
'
+
str
(
i
%
800
+
1
)
+
'.jpg'
)
# rescale
bg
=
cv2
.
resize
(
bg
,
(
int
(
1280
/
scale
),
int
(
720
/
scale
)))
# read detection data in current frame
dets
=
[]
with
open
(
path
+
'
\\
'
+
str
(
i
%
800
+
1
)
+
'.txt'
)
as
txt
:
with
open
(
path
+
'
/
'
+
str
(
i
%
800
+
1
)
+
'.txt'
)
as
txt
:
lines
=
txt
.
readlines
()
for
line
in
lines
:
items
=
line
.
split
(
' '
)
left
=
float
(
items
[
1
])
top
=
float
(
items
[
2
])
right
=
float
(
items
[
3
])
bottom
=
float
(
items
[
4
])
dets
.
append
((
left
/
scale
,
top
/
scale
,
right
/
scale
,
bottom
/
scale
,
int
(
items
[
0
])))
bottom
=
float
(
items
[
4
])
dets
.
append
((
left
/
scale
,
top
/
scale
,
right
/
scale
,
bottom
/
scale
,
int
(
items
[
0
])))
# send to the tracker and draw the result on background image
if
len
(
dets
)
>
0
:
bg
=
track_and_render
(
dets
,
bg
)
cv2
.
imshow
(
'tracker'
,
bg
)
cv2
.
waitKey
(
40
)
cv2
.
destroyAllWindows
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录