-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathocr.py
72 lines (58 loc) · 1.88 KB
/
ocr.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
71
72
#!/usr/bin/python3
# encoding:utf-8
import apisettings as apis
import os,time,tools,msvcrt
global path,access_token
from colorama import init
init(autoreset=True)
def printline():
print("-----------------------------------")
def welcomeinfo():
print("--------------------------------------------------")
print(" 欢迎使用身份证批量OCR工具"+"\033[31m[v0.0.1]")
print('\033[0m--------------------------------------------------')
def checkapi():
token = None
while(token == None):
print("\033[32m正在检查百度Api是否正确设置......")
token = apis.get_token()
if token==False:
print("\033[31m设置错误! 请输入正确的Api Key和Secret Key")
apis.configSeting()
token = apis.get_token()
global access_token
access_token = token
# print(access_token)
print("\033[32m设置正确!")
print("-----------------------------------")
return True
def setpath():
global path
path = input("请填写身份证图片所在文件夹:")
while not os.path.exists(path):
print("\033[31m路径设置错误! 请重新输入")
printline()
path = input("请填写身份证图片所在文件夹:")
print("\033[32m路径设置正确")
printline()
def ocrmain():
tools.create_sheet()
tools.set_sheet()
f_list = os.listdir(path)
# print f_list
for filename in f_list:
# os.path.splitext():分离文件名与扩展名
suf = os.path.splitext(filename)[1]
if suf == '.jpg' or suf == '.png':
global access_token
apis.ocr(path,filename,access_token)
time.sleep(1)
if __name__ =="__main__":
welcomeinfo()
checkapi()
setpath()
ocrmain()
print("识别完成,按d退出程序")
while True:
if ord(msvcrt.getch()) in [68, 100]:
break