Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
b47db6b5
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b47db6b5
编写于
5月 28, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update optical flow
上级
5c1d321a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
20 addition
and
18 deletion
+20
-18
contrib/HumanSeg/bg_replace.py
contrib/HumanSeg/bg_replace.py
+4
-4
contrib/HumanSeg/video_infer.py
contrib/HumanSeg/video_infer.py
+16
-14
未找到文件。
contrib/HumanSeg/bg_replace.py
浏览文件 @
b47db6b5
...
@@ -196,8 +196,8 @@ def infer(args):
...
@@ -196,8 +196,8 @@ def infer(args):
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
scoremap
=
255
*
score_map
[:,
:,
1
]
score
_
map
=
255
*
score_map
[:,
:,
1
]
optflow_map
=
postprocess
(
cur_gray
,
scoremap
,
prev_gray
,
prev_cfd
,
\
optflow_map
=
postprocess
(
cur_gray
,
score
_
map
,
prev_gray
,
prev_cfd
,
\
disflow
,
is_init
)
disflow
,
is_init
)
prev_gray
=
cur_gray
.
copy
()
prev_gray
=
cur_gray
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
...
@@ -252,8 +252,8 @@ def infer(args):
...
@@ -252,8 +252,8 @@ def infer(args):
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
scoremap
=
255
*
score_map
[:,
:,
1
]
score
_
map
=
255
*
score_map
[:,
:,
1
]
optflow_map
=
postprocess
(
cur_gray
,
scoremap
,
prev_gray
,
prev_cfd
,
\
optflow_map
=
postprocess
(
cur_gray
,
score
_
map
,
prev_gray
,
prev_cfd
,
\
disflow
,
is_init
)
disflow
,
is_init
)
prev_gray
=
cur_gray
.
copy
()
prev_gray
=
cur_gray
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
...
...
contrib/HumanSeg/video_infer.py
浏览文件 @
b47db6b5
...
@@ -22,6 +22,7 @@ import numpy as np
...
@@ -22,6 +22,7 @@ import numpy as np
from
utils.humanseg_postprocess
import
postprocess
,
threshold_mask
from
utils.humanseg_postprocess
import
postprocess
,
threshold_mask
import
models
import
models
import
transforms
import
transforms
import
time
def
parse_args
():
def
parse_args
():
...
@@ -109,7 +110,7 @@ def video_infer(args):
...
@@ -109,7 +110,7 @@ def video_infer(args):
fps
=
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
fps
=
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
if
args
.
video_path
:
if
args
.
video_path
:
print
(
'Please waite. It is computing......'
)
# 用于保存预测结果视频
# 用于保存预测结果视频
if
not
osp
.
exists
(
args
.
save_dir
):
if
not
osp
.
exists
(
args
.
save_dir
):
os
.
makedirs
(
args
.
save_dir
)
os
.
makedirs
(
args
.
save_dir
)
...
@@ -123,8 +124,8 @@ def video_infer(args):
...
@@ -123,8 +124,8 @@ def video_infer(args):
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
scoremap
=
255
*
score_map
[:,
:,
1
]
score
_
map
=
255
*
score_map
[:,
:,
1
]
optflow_map
=
postprocess
(
cur_gray
,
scoremap
,
prev_gray
,
prev_cfd
,
\
optflow_map
=
postprocess
(
cur_gray
,
score
_
map
,
prev_gray
,
prev_cfd
,
\
disflow
,
is_init
)
disflow
,
is_init
)
prev_gray
=
cur_gray
.
copy
()
prev_gray
=
cur_gray
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
...
@@ -132,10 +133,11 @@ def video_infer(args):
...
@@ -132,10 +133,11 @@ def video_infer(args):
optflow_map
=
cv2
.
GaussianBlur
(
optflow_map
,
(
3
,
3
),
0
)
optflow_map
=
cv2
.
GaussianBlur
(
optflow_map
,
(
3
,
3
),
0
)
optflow_map
=
threshold_mask
(
optflow_map
=
threshold_mask
(
optflow_map
,
thresh_bg
=
0.2
,
thresh_fg
=
0.8
)
optflow_map
,
thresh_bg
=
0.2
,
thresh_fg
=
0.8
)
img_mat
=
np
.
repeat
(
optflow_map
[:,
:,
np
.
newaxis
],
3
,
axis
=
2
)
img_matting
=
np
.
repeat
(
img_mat
=
recover
(
img_mat
,
im_info
)
optflow_map
[:,
:,
np
.
newaxis
],
3
,
axis
=
2
)
bg_im
=
np
.
ones_like
(
img_mat
)
*
255
img_matting
=
recover
(
img_matting
,
im_info
)
comb
=
(
img_mat
*
frame
+
(
1
-
img_mat
)
*
bg_im
).
astype
(
bg_im
=
np
.
ones_like
(
img_matting
)
*
255
comb
=
(
img_matting
*
frame
+
(
1
-
img_matting
)
*
bg_im
).
astype
(
np
.
uint8
)
np
.
uint8
)
out
.
write
(
comb
)
out
.
write
(
comb
)
else
:
else
:
...
@@ -150,20 +152,20 @@ def video_infer(args):
...
@@ -150,20 +152,20 @@ def video_infer(args):
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
score_map
,
im_info
=
predict
(
frame
,
model
,
test_transforms
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
cur_gray
=
cv2
.
resize
(
cur_gray
,
(
resize_w
,
resize_h
))
scoremap
=
255
*
score_map
[:,
:,
1
]
score
_
map
=
255
*
score_map
[:,
:,
1
]
optflow_map
=
postprocess
(
cur_gray
,
scoremap
,
prev_gray
,
prev_cfd
,
\
optflow_map
=
postprocess
(
cur_gray
,
score
_
map
,
prev_gray
,
prev_cfd
,
\
disflow
,
is_init
)
disflow
,
is_init
)
prev_gray
=
cur_gray
.
copy
()
prev_gray
=
cur_gray
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
prev_cfd
=
optflow_map
.
copy
()
is_init
=
False
is_init
=
False
# optflow_map = optflow_map/255.0
optflow_map
=
cv2
.
GaussianBlur
(
optflow_map
,
(
3
,
3
),
0
)
optflow_map
=
cv2
.
GaussianBlur
(
optflow_map
,
(
3
,
3
),
0
)
optflow_map
=
threshold_mask
(
optflow_map
=
threshold_mask
(
optflow_map
,
thresh_bg
=
0.2
,
thresh_fg
=
0.8
)
optflow_map
,
thresh_bg
=
0.2
,
thresh_fg
=
0.8
)
img_mat
=
np
.
repeat
(
optflow_map
[:,
:,
np
.
newaxis
],
3
,
axis
=
2
)
img_matting
=
np
.
repeat
(
img_mat
=
recover
(
img_mat
,
im_info
)
optflow_map
[:,
:,
np
.
newaxis
],
3
,
axis
=
2
)
bg_im
=
np
.
ones_like
(
img_mat
)
*
255
img_matting
=
recover
(
img_matting
,
im_info
)
comb
=
(
img_mat
*
frame
+
(
1
-
img_mat
)
*
bg_im
).
astype
(
bg_im
=
np
.
ones_like
(
img_matting
)
*
255
comb
=
(
img_matting
*
frame
+
(
1
-
img_matting
)
*
bg_im
).
astype
(
np
.
uint8
)
np
.
uint8
)
cv2
.
imshow
(
'HumanSegmentation'
,
comb
)
cv2
.
imshow
(
'HumanSegmentation'
,
comb
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录