Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5c3d64a4
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5c3d64a4
编写于
6月 29, 2022
作者:
Z
zhiboniu
提交者:
zhiboniu
7月 01, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
python smooth ok
上级
54b828a8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
49 addition
and
39 deletion
+49
-39
deploy/python/det_keypoint_unite_infer.py
deploy/python/det_keypoint_unite_infer.py
+49
-39
未找到文件。
deploy/python/det_keypoint_unite_infer.py
浏览文件 @
5c3d64a4
...
...
@@ -143,8 +143,8 @@ def topdown_unite_predict_video(detector,
writer
=
cv2
.
VideoWriter
(
out_path
,
fourcc
,
fps
,
(
width
,
height
))
index
=
0
store_res
=
[]
previous_keypoints
=
None
keypoint_smoothing
=
KeypointSmoothing
(
width
,
height
,
filter_type
=
FLAGS
.
filter_type
,
alpha
=
0.8
,
beta
=
1
)
keypoint_smoothing
=
KeypointSmoothing
(
width
,
height
,
filter_type
=
FLAGS
.
filter_type
,
beta
=
0.05
)
while
(
1
):
ret
,
frame
=
capture
.
read
()
...
...
@@ -167,8 +167,8 @@ def topdown_unite_predict_video(detector,
if
FLAGS
.
smooth
:
current_keypoints
=
np
.
array
(
keypoint_res
[
'keypoint'
][
0
][
0
])
smooth_keypoints
=
keypoint_smoothing
.
smooth_process
(
previous_keypoints
,
current_keypoints
)
previous_keypoints
=
smooth_keypoints
smooth_keypoints
=
keypoint_smoothing
.
smooth_process
(
current_keypoints
)
keypoint_res
[
'keypoint'
][
0
][
0
]
=
smooth_keypoints
.
tolist
()
...
...
@@ -205,13 +205,24 @@ def topdown_unite_predict_video(detector,
class
KeypointSmoothing
(
object
):
# The following code are modified from:
# https://github.com/610265158/Peppa_Pig_Face_Engine/blob/7bb1066ad3fbb12697924ba7f9287bf198c15232/lib/core/LK/lk.py
def
__init__
(
self
,
width
,
height
,
filter_type
,
alpha
=
0.5
,
fc_d
=
1
,
fc_min
=
1
,
beta
=
0
):
# https://github.com/jaantollander/OneEuroFilter
def
__init__
(
self
,
width
,
height
,
filter_type
,
alpha
=
0.5
,
fc_d
=
0.1
,
fc_min
=
0.1
,
beta
=
0.1
,
thres_mult
=
0.2
):
super
(
KeypointSmoothing
,
self
).
__init__
()
self
.
image_width
=
width
self
.
image_height
=
height
self
.
threshold
=
[
0.005
,
0.005
,
0.005
,
0.005
,
0.005
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
]
self
.
threshold
=
np
.
array
([
0.005
,
0.005
,
0.005
,
0.005
,
0.005
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
,
0.01
])
*
thres_mult
self
.
filter_type
=
filter_type
self
.
alpha
=
alpha
self
.
dx_prev_hat
=
None
...
...
@@ -227,51 +238,50 @@ class KeypointSmoothing(object):
else
:
raise
ValueError
(
'filter type must be one_euro or ema'
)
def
smooth_process
(
self
,
previous_keypoints
,
current_keypoints
):
if
previous_keypoints
is
None
:
previous_keypoints
=
current_keypoints
result
=
current_keypoints
def
smooth_process
(
self
,
current_keypoints
):
if
self
.
x_prev_hat
is
None
:
self
.
x_prev_hat
=
current_keypoints
[:,
:
2
]
self
.
dx_prev_hat
=
np
.
zeros
(
current_keypoints
[:,
:
2
].
shape
)
return
current_keypoints
else
:
result
=
[]
result
=
current_keypoints
num_keypoints
=
len
(
current_keypoints
)
for
i
in
range
(
num_keypoints
):
result
.
append
(
self
.
smooth
(
previous_keypoints
[
i
],
current_keypoints
[
i
],
self
.
threshold
[
i
]))
return
np
.
array
(
result
)
result
[
i
,
:
2
]
=
self
.
smooth
(
current_keypoints
[
i
,
:
2
],
self
.
threshold
[
i
],
i
)
return
result
def
smooth
(
self
,
previous_keypoint
,
current_keypoint
,
threshold
):
distance
=
np
.
sqrt
(
np
.
square
((
current_keypoint
[
0
]
-
previous_keypoint
[
0
])
/
self
.
image_width
)
+
np
.
square
((
current_keypoint
[
1
]
-
previous_keypoint
[
1
])
/
self
.
image_height
))
def
smooth
(
self
,
current_keypoint
,
threshold
,
index
):
distance
=
np
.
sqrt
(
np
.
square
((
current_keypoint
[
0
]
-
self
.
x_prev_hat
[
index
][
0
])
/
self
.
image_width
)
+
np
.
square
((
current_keypoint
[
1
]
-
self
.
x_prev_hat
[
index
][
1
])
/
self
.
image_height
))
if
distance
<
threshold
:
result
=
previous_keypoint
result
=
self
.
x_prev_hat
[
index
]
else
:
result
=
self
.
smooth_func
(
previous_keypoint
,
current_keypoint
)
result
=
self
.
smooth_func
(
current_keypoint
,
self
.
x_prev_hat
[
index
],
index
)
return
result
def
one_euro_filter
(
self
,
x_prev
,
x_cur
):
def
one_euro_filter
(
self
,
x_cur
,
x_pre
,
index
):
te
=
1
self
.
alpha
=
self
.
smoothing_factor
(
te
,
self
.
fc_d
)
if
self
.
x_prev_hat
is
None
:
self
.
x_prev_hat
=
x_prev
dx_cur
=
(
x_cur
-
self
.
x_prev_hat
)
/
te
if
self
.
dx_prev_hat
is
None
:
self
.
dx_prev_hat
=
0
dx_cur_hat
=
self
.
exponential_smoothing
(
self
.
dx_prev_hat
,
dx_cur
)
dx_cur
=
(
x_cur
-
x_pre
)
/
te
dx_cur_hat
=
self
.
exponential_smoothing
(
dx_cur
,
self
.
dx_prev_hat
[
index
])
fc
=
self
.
fc_min
+
self
.
beta
*
np
.
abs
(
dx_cur_hat
)
self
.
alpha
=
self
.
smoothing_factor
(
te
,
fc
)
x_cur_hat
=
self
.
exponential_smoothing
(
self
.
x_prev_hat
,
x_cur
)
self
.
dx_prev_hat
=
dx_cur_hat
self
.
x_prev_hat
=
x_cur_hat
x_cur_hat
=
self
.
exponential_smoothing
(
x_cur
,
x_pre
)
self
.
dx_prev_hat
[
index
]
=
dx_cur_hat
self
.
x_prev_hat
[
index
]
=
x_cur_hat
return
x_cur_hat
def
smoothing_factor
(
self
,
te
,
fc
):
r
=
2
*
math
.
pi
*
fc
*
te
return
r
/
(
r
+
1
)
def
exponential_smoothing
(
self
,
x_
prev
,
x_cur
):
return
self
.
alpha
*
x_cur
+
(
1
-
self
.
alpha
)
*
x_pre
v
def
exponential_smoothing
(
self
,
x_
cur
,
x_pre
,
index
=
0
):
return
self
.
alpha
*
x_cur
+
(
1
-
self
.
alpha
)
*
x_pre
def
main
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录