Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
725185cd
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
725185cd
编写于
10月 28, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add comment db post_process
上级
5299d8e6
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
31 addition
and
11 deletion
+31
-11
ppocr/postprocess/db_postprocess.py
ppocr/postprocess/db_postprocess.py
+31
-11
未找到文件。
ppocr/postprocess/db_postprocess.py
浏览文件 @
725185cd
...
...
@@ -24,6 +24,7 @@ import string
import
cv2
from
shapely.geometry
import
Polygon
import
pyclipper
from
copy
import
deepcopy
class
DBPostProcess
(
object
):
...
...
@@ -39,13 +40,15 @@ class DBPostProcess(object):
self
.
min_size
=
3
self
.
dilation_kernel
=
np
.
array
([[
1
,
1
],
[
1
,
1
]])
def
boxes_from_bitmap
(
self
,
pred
,
_bitmap
,
dest_width
,
dest_height
):
'''
_bitmap: single map with shape (1, H, W),
whose values are binarized as {0, 1}
'''
bitmap
=
_bitmap
def
boxes_from_bitmap
(
self
,
pred
,
mask
):
"""
Get boxes from the binarized image predicted by DB.
:param pred: the binarized image predicted by DB.
:param mask: new 'pred' after threshold filtering.
:return: (boxes, the score of each boxes)
"""
dest_height
,
dest_width
=
pred
.
shape
[
-
2
:]
bitmap
=
deepcopy
(
mask
)
height
,
width
=
bitmap
.
shape
outs
=
cv2
.
findContours
((
bitmap
*
255
).
astype
(
np
.
uint8
),
cv2
.
RETR_LIST
,
...
...
@@ -87,6 +90,11 @@ class DBPostProcess(object):
return
boxes
,
scores
def
unclip
(
self
,
box
):
"""
Shrink or expand the boxaccording to 'unclip_ratio'
:param box: The predicted box.
:return: uncliped box
"""
unclip_ratio
=
self
.
unclip_ratio
poly
=
Polygon
(
box
)
distance
=
poly
.
area
*
unclip_ratio
/
poly
.
length
...
...
@@ -96,6 +104,11 @@ class DBPostProcess(object):
return
expanded
def
get_mini_boxes
(
self
,
contour
):
"""
Get boxes from the contour or box.
:param contour: The predicted contour.
:return: The predicted box.
"""
bounding_box
=
cv2
.
minAreaRect
(
contour
)
points
=
sorted
(
list
(
cv2
.
boxPoints
(
bounding_box
)),
key
=
lambda
x
:
x
[
0
])
...
...
@@ -119,6 +132,12 @@ class DBPostProcess(object):
return
box
,
min
(
bounding_box
[
1
])
def
box_score_fast
(
self
,
bitmap
,
_box
):
"""
Calculate the score of box.
:param bitmap: The binarized image predicted by DB.
:param _box: The predicted box
:return: score
"""
h
,
w
=
bitmap
.
shape
[:
2
]
box
=
_box
.
copy
()
xmin
=
np
.
clip
(
np
.
floor
(
box
[:,
0
].
min
()).
astype
(
np
.
int
),
0
,
w
-
1
)
...
...
@@ -137,13 +156,14 @@ class DBPostProcess(object):
pred
=
pred
[:,
0
,
:,
:]
segmentation
=
pred
>
self
.
thresh
boxes_batch
=
[]
for
batch_index
in
range
(
pred
.
shape
[
0
]):
height
,
width
=
pred
.
shape
[
-
2
:]
mask
=
cv2
.
dilate
(
np
.
array
(
segmentation
[
batch_index
]).
astype
(
np
.
uint8
),
self
.
dilation_kernel
)
tmp_boxes
,
tmp_scores
=
self
.
boxes_from_bitmap
(
pred
[
batch_index
],
mask
,
width
,
height
)
mask
=
cv2
.
dilate
(
np
.
array
(
segmentation
[
batch_index
]).
astype
(
np
.
uint8
),
self
.
dilation_kernel
)
tmp_boxes
,
tmp_scores
=
self
.
boxes_from_bitmap
(
pred
[
batch_index
],
mask
)
boxes
=
[]
for
k
in
range
(
len
(
tmp_boxes
)):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录