Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
00e9e079
P
PaddleOCR
项目概览
s920243400
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
00e9e079
编写于
5月 28, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug in results visualization
上级
23c4d490
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
28 deletion
+22
-28
ppocr/data/det/db_process.py
ppocr/data/det/db_process.py
+12
-0
tools/infer/utility.py
tools/infer/utility.py
+10
-28
未找到文件。
ppocr/data/det/db_process.py
浏览文件 @
00e9e079
...
...
@@ -25,6 +25,10 @@ from .make_border_map import MakeBorderMap
class
DBProcessTrain
(
object
):
"""
DB pre-process for Train mode
"""
def
__init__
(
self
,
params
):
self
.
img_set_dir
=
params
[
'img_set_dir'
]
self
.
image_shape
=
params
[
'image_shape'
]
...
...
@@ -109,6 +113,10 @@ class DBProcessTrain(object):
class
DBProcessTest
(
object
):
"""
DB pre-process for Test mode
"""
def
__init__
(
self
,
params
):
super
(
DBProcessTest
,
self
).
__init__
()
self
.
resize_type
=
0
...
...
@@ -124,6 +132,10 @@ class DBProcessTest(object):
def
resize_image_type0
(
self
,
im
):
"""
resize image to a size multiple of 32 which is required by the network
args:
img(array): array with shape [h, w, c]
return(tuple):
img, (ratio_h, ratio_w)
"""
max_side_len
=
self
.
max_side_len
h
,
w
,
_
=
im
.
shape
...
...
tools/infer/utility.py
浏览文件 @
00e9e079
...
...
@@ -107,7 +107,7 @@ def create_predictor(args, mode):
return
predictor
,
input_tensor
,
output_tensors
def
draw_text_det_res
(
dt_boxes
,
img_path
,
return_img
=
True
):
def
draw_text_det_res
(
dt_boxes
,
img_path
):
src_im
=
cv2
.
imread
(
img_path
)
for
box
in
dt_boxes
:
box
=
np
.
array
(
box
).
astype
(
np
.
int32
).
reshape
(
-
1
,
2
)
...
...
@@ -117,10 +117,10 @@ def draw_text_det_res(dt_boxes, img_path, return_img=True):
def
resize_img
(
img
,
input_size
=
600
):
"""
resize img and limit the longest side of the image to input_size
"""
img
=
np
.
array
(
img
)
im_shape
=
img
.
shape
im_size_min
=
np
.
min
(
im_shape
[
0
:
2
])
im_size_max
=
np
.
max
(
im_shape
[
0
:
2
])
im_scale
=
float
(
input_size
)
/
float
(
im_size_max
)
im
=
cv2
.
resize
(
img
,
None
,
None
,
fx
=
im_scale
,
fy
=
im_scale
)
...
...
@@ -131,7 +131,7 @@ def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5):
"""
Visualize the results of OCR detection and recognition
args:
image(Image
): image from Image.open
image(Image
|array): RGB image
boxes(list): boxes with shape(N, 4, 2)
txts(list): the texts
scores(list): txxs corresponding scores
...
...
@@ -140,31 +140,14 @@ def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5):
return(array):
the visualized img
"""
from
PIL
import
Image
,
ImageDraw
,
ImageFont
img
=
image
.
copy
()
draw
=
ImageDraw
.
Draw
(
img
)
img
=
image
if
scores
is
None
:
scores
=
[
1
]
*
len
(
boxes
)
for
(
box
,
score
)
in
zip
(
boxes
,
scores
):
if
score
<
drop_score
:
if
score
<
drop_score
or
math
.
isnan
(
score
)
:
continue
draw
.
line
([(
box
[
0
][
0
],
box
[
0
][
1
]),
(
box
[
1
][
0
],
box
[
1
][
1
])],
fill
=
'red'
)
draw
.
line
([(
box
[
1
][
0
],
box
[
1
][
1
]),
(
box
[
2
][
0
],
box
[
2
][
1
])],
fill
=
'red'
)
draw
.
line
([(
box
[
2
][
0
],
box
[
2
][
1
]),
(
box
[
3
][
0
],
box
[
3
][
1
])],
fill
=
'red'
)
draw
.
line
([(
box
[
3
][
0
],
box
[
3
][
1
]),
(
box
[
0
][
0
],
box
[
0
][
1
])],
fill
=
'red'
)
draw
.
line
(
[(
box
[
0
][
0
]
-
1
,
box
[
0
][
1
]
+
1
),
(
box
[
1
][
0
]
-
1
,
box
[
1
][
1
]
+
1
)],
fill
=
'red'
)
draw
.
line
(
[(
box
[
1
][
0
]
-
1
,
box
[
1
][
1
]
+
1
),
(
box
[
2
][
0
]
-
1
,
box
[
2
][
1
]
+
1
)],
fill
=
'red'
)
draw
.
line
(
[(
box
[
2
][
0
]
-
1
,
box
[
2
][
1
]
+
1
),
(
box
[
3
][
0
]
-
1
,
box
[
3
][
1
]
+
1
)],
fill
=
'red'
)
draw
.
line
(
[(
box
[
3
][
0
]
-
1
,
box
[
3
][
1
]
+
1
),
(
box
[
0
][
0
]
-
1
,
box
[
0
][
1
]
+
1
)],
fill
=
'red'
)
box
=
np
.
reshape
(
np
.
array
(
box
),
[
-
1
,
1
,
2
]).
astype
(
np
.
int64
)
img
=
cv2
.
polylines
(
np
.
array
(
image
),
[
box
],
True
,
(
255
,
0
,
0
),
3
)
if
draw_txt
:
img
=
np
.
array
(
resize_img
(
img
,
input_size
=
600
))
...
...
@@ -233,7 +216,7 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
count
,
index
=
0
,
0
for
idx
,
txt
in
enumerate
(
texts
):
index
+=
1
if
scores
[
idx
]
<
threshold
:
if
scores
[
idx
]
<
threshold
or
math
.
isnan
(
scores
[
idx
])
:
index
-=
1
continue
first_line
=
True
...
...
@@ -260,7 +243,7 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
draw_txt
.
text
((
0
,
gap
*
(
count
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
count
+=
1
# whether add new blank img or not
if
count
>
=
img_h
//
gap
-
1
and
idx
+
1
<
len
(
texts
):
if
count
>
img_h
//
gap
-
1
and
idx
+
1
<
len
(
texts
):
txt_img_list
.
append
(
np
.
array
(
blank_img
))
blank_img
,
draw_txt
=
create_blank_img
()
count
=
0
...
...
@@ -270,7 +253,6 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
blank_img
=
np
.
array
(
txt_img_list
[
0
])
else
:
blank_img
=
np
.
concatenate
(
txt_img_list
,
axis
=
1
)
# cv2.imwrite("./draw_txt.jpg", np.array(blank_img))
return
np
.
array
(
blank_img
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录