forked from MgArcher/Text_select_captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing.py
47 lines (41 loc) · 1.16 KB
/
drawing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
@author: jiajia
@file: drawing.py
@time: 2021/3/28 15:31
"""
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from io import BytesIO
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
def open_image(file):
if isinstance(file, np.ndarray):
img = Image.fromarray(file)
elif isinstance(file, bytes):
img = Image.open(BytesIO(file))
else:
img = Image.open(file)
img = np.array(img)
return img
def draw(img_path, data=[]):
"绘制识别结果"
image_ = open_image(img_path)
plt.imshow(image_, interpolation='none')
current_axis = plt.gca()
for box_ in data:
box = box_['crop']
x1, y1, x2, y2 = box
box_w = x2 - x1
box_h = y2 - y1
current_axis.add_patch(
plt.Rectangle((x1, y1), box_w, box_h, color='blue', fill=False, linewidth=2))
plt.text(
x1,
y1,
s=box_['content'],
color="white",
verticalalignment="top",
bbox={"color": "black", "pad": 0},
)
plt.show()