-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageProcess.py
59 lines (50 loc) · 1.17 KB
/
ImageProcess.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
import os
import re
import time
import cv2
import easyocr
import numpy as np
test = [
'154러7070',
'265버9344',
'123가4568',
'21고7824',
'33너2222'
]
reader = easyocr.Reader(['ko'], gpu = True)
def save_img(file, name, img_dir="Images"):
nparr = np.fromstring(file.read(), np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if not os.path.isdir(img_dir):
os.mkdir(img_dir)
cv2.imwrite(os.path.join(img_dir,str(name)+".jpg"), img)
def read_img(board):
result = None
results = reader.readtext(f"Images/{board}.jpg")
matched_text = 0
if results:
pattern1 = r'\d{2}[가-힣]\s\d{4}'
pattern2 = r'\d{3}[가-힣]\s\d{4}'
text =str(results[0][1])
match1 = re.search(pattern1, text)
match2 = re.search(pattern2, text)
if match1 or match2:
if match1:
matched_text = str(match1.group())
else:
matched_text = str(match2.group())
# print(matched_text)
else:
print(text)
try:
matched_text = matched_text.replace(" ", "")
except:
pass
if matched_text in test:
result = 1
else:
result = 0
print(matched_text)
return result
def now_time():
return time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))