Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
c15d3bb0
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看板
提交
c15d3bb0
编写于
5月 14, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add visualize code to predict_eval
上级
073b8517
变更
21
显示空白变更内容
内联
并排
Showing
21 changed file
with
78 addition
and
25 deletion
+78
-25
README.md
README.md
+9
-9
doc/imgs/.DS_Store
doc/imgs/.DS_Store
+0
-0
doc/imgs_results/1.jpg
doc/imgs_results/1.jpg
+0
-0
doc/imgs_results/10.jpg
doc/imgs_results/10.jpg
+0
-0
doc/imgs_results/11.jpg
doc/imgs_results/11.jpg
+0
-0
doc/imgs_results/12.jpg
doc/imgs_results/12.jpg
+0
-0
doc/imgs_results/13.png
doc/imgs_results/13.png
+0
-0
doc/imgs_results/15.jpg
doc/imgs_results/15.jpg
+0
-0
doc/imgs_results/16.png
doc/imgs_results/16.png
+0
-0
doc/imgs_results/17.png
doc/imgs_results/17.png
+0
-0
doc/imgs_results/2.jpg
doc/imgs_results/2.jpg
+0
-0
doc/imgs_results/22.jpg
doc/imgs_results/22.jpg
+0
-0
doc/imgs_results/3.jpg
doc/imgs_results/3.jpg
+0
-0
doc/imgs_results/4.jpg
doc/imgs_results/4.jpg
+0
-0
doc/imgs_results/5.jpg
doc/imgs_results/5.jpg
+0
-0
doc/imgs_results/6.jpg
doc/imgs_results/6.jpg
+0
-0
doc/imgs_results/7.jpg
doc/imgs_results/7.jpg
+0
-0
doc/imgs_results/8.jpg
doc/imgs_results/8.jpg
+0
-0
doc/imgs_results/9.jpg
doc/imgs_results/9.jpg
+0
-0
tools/infer/predict_system.py
tools/infer/predict_system.py
+22
-3
tools/infer/utility.py
tools/infer/utility.py
+47
-13
未找到文件。
README.md
浏览文件 @
c15d3bb0
...
@@ -11,7 +11,7 @@ PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力
...
@@ -11,7 +11,7 @@ PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力
## **超轻量级中文OCR体验**
## **超轻量级中文OCR体验**
![](
./doc/imgs_draw
/11.jpg
)
![](
doc/imgs_results
/11.jpg
)
上图是超轻量级中文OCR模型效果展示,更多效果图请见文末
[
效果展示
](
#效果展示
)
。
上图是超轻量级中文OCR模型效果展示,更多效果图请见文末
[
效果展示
](
#效果展示
)
。
...
@@ -97,14 +97,14 @@ PaddleOCR文本识别算法的训练和使用请参考文档教程中[文本识
...
@@ -97,14 +97,14 @@ PaddleOCR文本识别算法的训练和使用请参考文档教程中[文本识
<a
name=
"效果展示"
></a>
<a
name=
"效果展示"
></a>
## 效果展示
## 效果展示
![](
./doc/imgs_draw
/1.jpg
)
![](
doc/imgs_results
/1.jpg
)
![](
./doc/imgs_draw
/7.jpg
)
![](
doc/imgs_results
/7.jpg
)
![](
./doc/imgs_draw
/12.jpg
)
![](
doc/imgs_results
/12.jpg
)
![](
./doc/imgs_draw
/4.jpg
)
![](
doc/imgs_results
/4.jpg
)
![](
./doc/imgs_draw
/6.jpg
)
![](
doc/imgs_results
/6.jpg
)
![](
./doc/imgs_draw
/9.jpg
)
![](
doc/imgs_results
/9.jpg
)
![](
./doc/imgs_draw
/16.png
)
![](
doc/imgs_results
/16.png
)
![](
./doc/imgs_draw
/22.jpg
)
![](
doc/imgs_results
/22.jpg
)
## 参考文献
## 参考文献
...
...
doc/imgs/.DS_Store
已删除
100644 → 0
浏览文件 @
073b8517
文件已删除
doc/imgs_
draw
/1.jpg
→
doc/imgs_
results
/1.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/10.jpg
→
doc/imgs_
results
/10.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/11.jpg
→
doc/imgs_
results
/11.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/12.jpg
→
doc/imgs_
results
/12.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/13.png
→
doc/imgs_
results
/13.png
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/15.jpg
→
doc/imgs_
results
/15.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/16.png
→
doc/imgs_
results
/16.png
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/17.png
→
doc/imgs_
results
/17.png
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/2.jpg
→
doc/imgs_
results
/2.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/22.jpg
→
doc/imgs_
results
/22.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/3.jpg
→
doc/imgs_
results
/3.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/4.jpg
→
doc/imgs_
results
/4.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/5.jpg
→
doc/imgs_
results
/5.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/6.jpg
→
doc/imgs_
results
/6.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/7.jpg
→
doc/imgs_
results
/7.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/8.jpg
→
doc/imgs_
results
/8.jpg
浏览文件 @
c15d3bb0
文件已移动
doc/imgs_
draw
/9.jpg
→
doc/imgs_
results
/9.jpg
浏览文件 @
c15d3bb0
文件已移动
tools/infer/predict_system.py
浏览文件 @
c15d3bb0
...
@@ -22,6 +22,10 @@ import copy
...
@@ -22,6 +22,10 @@ import copy
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
time
import
time
from
ppocr.utils.utility
import
get_image_file_list
from
PIL
import
Image
from
tools.infer.utility
import
draw_ocr
import
os
class
TextSystem
(
object
):
class
TextSystem
(
object
):
...
@@ -99,8 +103,9 @@ def sorted_boxes(dt_boxes):
...
@@ -99,8 +103,9 @@ def sorted_boxes(dt_boxes):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
args
=
utility
.
parse_args
()
args
=
utility
.
parse_args
()
image_file_list
=
utility
.
get_image_file_list
(
args
.
image_dir
)
image_file_list
=
get_image_file_list
(
args
.
image_dir
)
text_sys
=
TextSystem
(
args
)
text_sys
=
TextSystem
(
args
)
is_visualize
=
True
for
image_file
in
image_file_list
:
for
image_file
in
image_file_list
:
img
=
cv2
.
imread
(
image_file
)
img
=
cv2
.
imread
(
image_file
)
if
img
is
None
:
if
img
is
None
:
...
@@ -114,8 +119,22 @@ if __name__ == "__main__":
...
@@ -114,8 +119,22 @@ if __name__ == "__main__":
dt_boxes_final
=
[]
dt_boxes_final
=
[]
for
dno
in
range
(
dt_num
):
for
dno
in
range
(
dt_num
):
text
,
score
=
rec_res
[
dno
]
text
,
score
=
rec_res
[
dno
]
if
score
>=
0
:
if
score
>=
0
.5
:
text_str
=
"%s, %.3f"
%
(
text
,
score
)
text_str
=
"%s, %.3f"
%
(
text
,
score
)
print
(
text_str
)
print
(
text_str
)
dt_boxes_final
.
append
(
dt_boxes
[
dno
])
dt_boxes_final
.
append
(
dt_boxes
[
dno
])
utility
.
draw_text_det_res
(
dt_boxes_final
,
image_file
)
if
is_visualize
:
image
=
Image
.
fromarray
(
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
))
boxes
=
dt_boxes
txts
=
[
rec_res
[
i
][
0
]
for
i
in
range
(
len
(
rec_res
))]
scores
=
[
rec_res
[
i
][
1
]
for
i
in
range
(
len
(
rec_res
))]
draw_img
=
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
,
drop_score
=
0.5
)
draw_img_save
=
"./doc/imgs_results/"
if
not
os
.
path
.
exists
(
draw_img_save
):
os
.
makedirs
(
draw_img_save
)
cv2
.
imwrite
(
os
.
path
.
join
(
draw_img_save
,
os
.
path
.
basename
(
image_file
)),
draw_img
)
tools/infer/utility.py
浏览文件 @
c15d3bb0
...
@@ -112,36 +112,70 @@ def draw_text_det_res(dt_boxes, img_path):
...
@@ -112,36 +112,70 @@ def draw_text_det_res(dt_boxes, img_path):
cv2
.
imwrite
(
"./output/%s"
%
img_name_pure
,
src_im
)
cv2
.
imwrite
(
"./output/%s"
%
img_name_pure
,
src_im
)
def
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
):
def
resize_img
(
img
,
input_size
=
600
):
"""
"""
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
)
return
im
def
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
,
drop_score
=
0.5
):
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
PIL
import
Image
,
ImageDraw
,
ImageFont
w
,
h
=
image
.
size
w
,
h
=
image
.
size
img
=
image
.
copy
()
img
=
image
.
copy
()
draw
=
ImageDraw
.
Draw
(
img
)
draw
=
ImageDraw
.
Draw
(
img
)
for
(
box
,
txt
)
in
zip
(
boxes
,
txts
):
for
(
box
,
score
)
in
zip
(
boxes
,
scores
):
if
score
<
drop_score
:
continue
draw
.
line
([(
box
[
0
][
0
],
box
[
0
][
1
]),
(
box
[
1
][
0
],
box
[
1
][
1
])],
fill
=
'red'
)
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
[
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
[
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
[
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'
)
if
draw_txt
:
if
draw_txt
:
txt_color
=
(
0
,
0
,
0
)
txt_color
=
(
0
,
0
,
0
)
img
=
np
.
array
(
resize_img
(
img
))
blank_img
=
np
.
ones
(
shape
=
[
h
,
800
],
dtype
=
np
.
int8
)
*
255
_h
=
img
.
shape
[
0
]
blank_img
=
np
.
ones
(
shape
=
[
_h
,
600
],
dtype
=
np
.
int8
)
*
255
blank_img
=
Image
.
fromarray
(
blank_img
).
convert
(
"RGB"
)
blank_img
=
Image
.
fromarray
(
blank_img
).
convert
(
"RGB"
)
draw_txt
=
ImageDraw
.
Draw
(
blank_img
)
draw_txt
=
ImageDraw
.
Draw
(
blank_img
)
font_size
=
30
font_size
=
20
gap
=
40
if
h
//
len
(
txts
)
>=
font_size
else
h
//
len
(
txts
)
gap
=
20
title
=
"index text score"
for
i
,
txt
in
enumerate
(
txts
):
font
=
ImageFont
.
truetype
(
font
=
ImageFont
.
truetype
(
"./doc/simfang.TTF"
,
font_size
,
encoding
=
"utf-8"
)
"./doc/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
)
draw_txt
.
text
((
20
,
0
),
title
,
txt_color
,
font
=
font
)
count
=
0
for
idx
,
txt
in
enumerate
(
txts
):
if
scores
[
idx
]
<
drop_score
:
continue
font
=
ImageFont
.
truetype
(
"./doc/simfang.ttf"
,
font_size
,
encoding
=
"utf-8"
)
new_txt
=
str
(
count
)
+
': '
+
txt
+
' '
+
str
(
scores
[
count
])
draw_txt
.
text
(
(
20
,
gap
*
(
count
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
count
+=
1
img
=
np
.
concatenate
([
np
.
array
(
img
),
np
.
array
(
blank_img
)],
axis
=
1
)
img
=
np
.
concatenate
([
np
.
array
(
img
),
np
.
array
(
blank_img
)],
axis
=
1
)
return
img
return
img
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录