Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
5d70fd44
P
PaddleOCR
项目概览
weixin_41840029
/
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看板
提交
5d70fd44
编写于
5月 13, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add visulize code
上级
9126cb6f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
12 deletion
+81
-12
doc/simfang.ttf
doc/simfang.ttf
+0
-0
tools/infer/predict_eval.py
tools/infer/predict_eval.py
+23
-12
tools/infer/utility.py
tools/infer/utility.py
+58
-0
未找到文件。
doc/simfang.ttf
0 → 100644
浏览文件 @
5d70fd44
文件已添加
tools/infer/predict_eval.py
浏览文件 @
5d70fd44
...
...
@@ -22,28 +22,25 @@ import numpy as np
import
math
import
time
import
json
import
os
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
tools.infer.utility
import
draw_ocr
from
ppocr.utils.utility
import
get_image_file_list
if
__name__
==
"__main__"
:
args
=
utility
.
parse_args
()
text_sys
=
predict_system
.
TextSystem
(
args
)
image_file_list
=
[]
label_file_path
=
"./eval_perform/gt_res/test_chinese_ic15_500_4pts.txt"
img_set_path
=
"./eval_perform/"
with
open
(
label_file_path
,
"rb"
)
as
fin
:
lines
=
fin
.
readlines
()
for
line
in
lines
:
substr
=
line
.
decode
(
'utf-8'
).
strip
(
"
\n
"
).
split
(
"
\t
"
)
if
"lsvt"
in
substr
[
0
]:
continue
image_file_list
.
append
(
substr
[
0
])
if
not
os
.
path
.
exists
(
args
.
image_dir
):
raise
Exception
(
"{} not exists !!"
.
format
(
args
.
image_dir
))
image_file_list
=
get_image_file_list
(
args
.
image_dir
)
total_time_all
=
0
count
=
0
save_path
=
"./output/predict.txt"
save_path
=
"./
inference_
output/predict.txt"
fout
=
open
(
save_path
,
"wb"
)
for
image_name
in
image_file_list
:
image_file
=
im
g_set_path
+
im
age_name
image_file
=
image_name
img
=
cv2
.
imread
(
image_file
)
if
img
is
None
:
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
...
...
@@ -68,6 +65,20 @@ if __name__ == "__main__":
"points"
:
points
,
"scores"
:
score
*
1.0
})
# draw predict box and text in image
# and save drawed image in save_path
image
=
Image
.
open
(
image_file
)
boxes
,
txts
,
scores
=
[],
[],
[]
for
dic
in
bbox_list
:
boxes
.
append
(
dic
[
'points'
])
txts
.
append
(
dic
[
'transcription'
])
scores
.
append
(
round
(
dic
[
'scores'
],
3
))
new_img
=
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
)
draw_img_save
=
os
.
path
.
join
(
os
.
path
.
dirname
(
save_path
),
"inference_draw"
,
os
.
path
.
basename
(
image_file
))
cv2
.
imwrite
(
draw_img_save
,
new_img
)
# save predicted results in txt file
otstr
=
image_name
+
"
\t
"
+
json
.
dumps
(
bbox_list
)
+
"
\n
"
fout
.
write
(
otstr
.
encode
(
'utf-8'
))
avg_time
=
total_time_all
/
count
...
...
tools/infer/utility.py
浏览文件 @
5d70fd44
...
...
@@ -21,6 +21,8 @@ from paddle.fluid.core import AnalysisConfig
from
paddle.fluid.core
import
create_paddle_predictor
import
cv2
import
numpy
as
np
import
json
from
PIL
import
Image
,
ImageDraw
,
ImageFont
def
parse_args
():
...
...
@@ -108,3 +110,59 @@ def draw_text_det_res(dt_boxes, img_path):
cv2
.
polylines
(
src_im
,
[
box
],
True
,
color
=
(
255
,
255
,
0
),
thickness
=
2
)
img_name_pure
=
img_path
.
split
(
"/"
)[
-
1
]
cv2
.
imwrite
(
"./output/%s"
%
img_name_pure
,
src_im
)
def
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
):
from
PIL
import
Image
,
ImageDraw
,
ImageFont
w
,
h
=
image
.
size
img
=
image
.
copy
()
draw
=
ImageDraw
.
Draw
(
img
)
for
(
box
,
txt
)
in
zip
(
boxes
,
txts
):
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'
)
if
draw_txt
:
txt_color
=
(
0
,
0
,
0
)
blank_img
=
np
.
ones
(
shape
=
[
h
,
800
],
dtype
=
np
.
int8
)
*
255
blank_img
=
Image
.
fromarray
(
blank_img
).
convert
(
"RGB"
)
draw_txt
=
ImageDraw
.
Draw
(
blank_img
)
font_size
=
30
gap
=
40
if
h
//
len
(
txts
)
>=
font_size
else
h
//
len
(
txts
)
for
i
,
txt
in
enumerate
(
txts
):
font
=
ImageFont
.
truetype
(
"/simfang.TTF"
,
font_size
,
encoding
=
"utf-8"
)
new_txt
=
str
(
i
)
+
': '
+
txt
+
' '
+
str
(
scores
[
i
])
draw_txt
.
text
((
20
,
gap
*
(
i
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
img
=
np
.
concatenate
([
np
.
array
(
img
),
np
.
array
(
blank_img
)],
axis
=
1
)
return
img
if
__name__
==
'__main__'
:
test_img
=
"./doc/test_v2"
predict_txt
=
"./doc/predict.txt"
f
=
open
(
predict_txt
,
'r'
)
data
=
f
.
readlines
()
img_path
,
anno
=
data
[
0
].
strip
().
split
(
'
\t
'
)
img_name
=
os
.
path
.
basename
(
img_path
)
img_path
=
os
.
path
.
join
(
test_img
,
img_name
)
image
=
Image
.
open
(
img_path
)
data
=
json
.
loads
(
anno
)
boxes
,
txts
,
scores
=
[],
[],
[]
for
dic
in
data
:
boxes
.
append
(
dic
[
'points'
])
txts
.
append
(
dic
[
'transcription'
])
scores
.
append
(
round
(
dic
[
'scores'
],
3
))
new_img
=
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
)
cv2
.
imwrite
(
img_name
,
new_img
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录