Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
e0b641cc
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看板
提交
e0b641cc
编写于
5月 28, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix visual bug
上级
00e9e079
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
13 deletion
+10
-13
tools/infer/utility.py
tools/infer/utility.py
+10
-13
未找到文件。
tools/infer/utility.py
浏览文件 @
e0b641cc
...
@@ -140,22 +140,21 @@ def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5):
...
@@ -140,22 +140,21 @@ def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5):
return(array):
return(array):
the visualized img
the visualized img
"""
"""
img
=
image
if
scores
is
None
:
if
scores
is
None
:
scores
=
[
1
]
*
len
(
boxes
)
scores
=
[
1
]
*
len
(
boxes
)
for
(
box
,
score
)
in
zip
(
boxes
,
scores
):
for
(
box
,
score
)
in
zip
(
boxes
,
scores
):
if
score
<
drop_score
or
math
.
isnan
(
score
):
if
score
<
drop_score
or
math
.
isnan
(
score
):
continue
continue
box
=
np
.
reshape
(
np
.
array
(
box
),
[
-
1
,
1
,
2
]).
astype
(
np
.
int64
)
box
=
np
.
reshape
(
np
.
array
(
box
),
[
-
1
,
1
,
2
]).
astype
(
np
.
int64
)
im
g
=
cv2
.
polylines
(
np
.
array
(
image
),
[
box
],
True
,
(
255
,
0
,
0
),
3
)
im
age
=
cv2
.
polylines
(
np
.
array
(
image
),
[
box
],
True
,
(
255
,
0
,
0
),
2
)
if
draw_txt
:
if
draw_txt
:
img
=
np
.
array
(
resize_img
(
im
g
,
input_size
=
600
))
img
=
np
.
array
(
resize_img
(
im
age
,
input_size
=
600
))
txt_img
=
text_visual
(
txt_img
=
text_visual
(
txts
,
scores
,
img_h
=
img
.
shape
[
0
],
img_w
=
600
,
threshold
=
drop_score
)
txts
,
scores
,
img_h
=
img
.
shape
[
0
],
img_w
=
600
,
threshold
=
drop_score
)
img
=
np
.
concatenate
([
np
.
array
(
img
),
np
.
array
(
txt_img
)],
axis
=
1
)
img
=
np
.
concatenate
([
np
.
array
(
img
),
np
.
array
(
txt_img
)],
axis
=
1
)
return
img
return
im
g
return
im
age
def
str_count
(
s
):
def
str_count
(
s
):
...
@@ -213,7 +212,7 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
...
@@ -213,7 +212,7 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
gap
=
font_size
+
5
gap
=
font_size
+
5
txt_img_list
=
[]
txt_img_list
=
[]
count
,
index
=
0
,
0
count
,
index
=
1
,
0
for
idx
,
txt
in
enumerate
(
texts
):
for
idx
,
txt
in
enumerate
(
texts
):
index
+=
1
index
+=
1
if
scores
[
idx
]
<
threshold
or
math
.
isnan
(
scores
[
idx
]):
if
scores
[
idx
]
<
threshold
or
math
.
isnan
(
scores
[
idx
]):
...
@@ -230,24 +229,22 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
...
@@ -230,24 +229,22 @@ def text_visual(texts, scores, img_h=400, img_w=600, threshold=0.):
new_txt
=
' '
+
txt
new_txt
=
' '
+
txt
draw_txt
.
text
((
0
,
gap
*
(
count
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
draw_txt
.
text
((
0
,
gap
*
(
count
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
txt
=
tmp
[
img_w
//
font_size
-
4
:]
txt
=
tmp
[
img_w
//
font_size
-
4
:]
count
+=
1
if
count
>=
img_h
//
gap
-
1
:
if
count
>=
img_h
//
gap
-
1
:
txt_img_list
.
append
(
np
.
array
(
blank_img
))
txt_img_list
.
append
(
np
.
array
(
blank_img
))
blank_img
,
draw_txt
=
create_blank_img
()
blank_img
,
draw_txt
=
create_blank_img
()
count
=
0
count
=
0
count
+=
1
if
first_line
:
if
first_line
:
new_txt
=
str
(
index
)
+
': '
+
txt
+
' '
+
'%.3f'
%
(
scores
[
idx
])
new_txt
=
str
(
index
)
+
': '
+
txt
+
' '
+
'%.3f'
%
(
scores
[
idx
])
else
:
else
:
new_txt
=
" "
+
txt
+
" "
+
'%.3f'
%
(
scores
[
idx
])
new_txt
=
" "
+
txt
+
" "
+
'%.3f'
%
(
scores
[
idx
])
draw_txt
.
text
((
0
,
gap
*
(
count
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
draw_txt
.
text
((
0
,
gap
*
count
),
new_txt
,
txt_color
,
font
=
font
)
count
+=
1
# whether add new blank img or not
# 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
))
txt_img_list
.
append
(
np
.
array
(
blank_img
))
blank_img
,
draw_txt
=
create_blank_img
()
blank_img
,
draw_txt
=
create_blank_img
()
count
=
0
count
=
0
count
+=
1
txt_img_list
.
append
(
np
.
array
(
blank_img
))
txt_img_list
.
append
(
np
.
array
(
blank_img
))
if
len
(
txt_img_list
)
==
1
:
if
len
(
txt_img_list
)
==
1
:
blank_img
=
np
.
array
(
txt_img_list
[
0
])
blank_img
=
np
.
array
(
txt_img_list
[
0
])
...
@@ -275,4 +272,4 @@ if __name__ == '__main__':
...
@@ -275,4 +272,4 @@ if __name__ == '__main__':
new_img
=
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
)
new_img
=
draw_ocr
(
image
,
boxes
,
txts
,
scores
,
draw_txt
=
True
)
cv2
.
imwrite
(
img_name
,
new_img
)
cv2
.
imwrite
(
img_name
,
new_img
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录