-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmobile_pre.py
71 lines (64 loc) · 1.97 KB
/
mobile_pre.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from paddleocr import PaddleOCR
from tools.infer.utility import draw_ocr
from PIL import Image
from lstm import test
import re
import miaoshu.miaoshu_test as ms
def one_pred(img_path):
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
result = ocr.ocr(img_path, cls=False)
# print(result)
n = 0
stR=""
phone = ""#电话
shopName="" #店铺名
describe = ""#描述
otherinfo = "没有其他信息"
print("+++",result)
for line in result:
n += 1
texts = line[1][0]
if texts == "":
continue
if len(texts) < 2:
continue
r = test.pre(texts)
if len(texts) < 3:
continue
if r == "商铺名":
shopName = shopName + texts
continue
s = ms.pre(texts)
if s == "描述":
describe = describe + texts
continue
stR = stR+str(line[1][0])+":"+str(line[1][1])+"\n"
phones = texts.split("1")
# print("++",phone)
for i in phones:
# print(i)
if re.match(r'^[1-9]\d{9}$', i):
a = "1" + i
# print(a)
phone = phone + ";"+a
else:
phone = " 图片中没有电话信息"
phone = phone[1:]
print("****",shopName,phone,describe,otherinfo)
#return im_show.show()
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/doc/simfang.ttf')
im_show = Image.fromarray(im_show)
# im_show.show()
# im_show.save是保存识别后的图片
fanhui_img = 'result.jpg'
im_show.save(fanhui_img)
return shopName,phone,describe,otherinfo,fanhui_img
# path是图片路径,
# path=r'F:\chrome\zrbdata\data\images\33.jpg'
# # path="img/4.jpg"
# # save_path=r"img/result_img/result.jpg"
# one_pred("img\ygf.png")