Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
c15d3bb0
"...data/git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "9c813bb332b6321c17564ce5dc2f0a63f8972c31"
Commit
c15d3bb0
authored
May 14, 2020
by
LDOUBLEV
Browse files
add visualize code to predict_eval
parent
073b8517
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
13 deletions
+47
-13
tools/infer/utility.py
tools/infer/utility.py
+47
-13
No files found.
tools/infer/utility.py
View file @
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
(
"./doc/simfang.ttf"
,
font_size
,
encoding
=
"utf-8"
)
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
(
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
])
new_txt
=
str
(
count
)
+
': '
+
txt
+
' '
+
str
(
scores
[
count
])
draw_txt
.
text
((
20
,
gap
*
(
i
+
1
)),
new_txt
,
txt_color
,
font
=
font
)
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
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment