-
Notifications
You must be signed in to change notification settings - Fork 133
/
demo.py
36 lines (31 loc) · 1.11 KB
/
demo.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
import os
from ocr import ocr
import time
import shutil
import numpy as np
from PIL import Image
from glob import glob
def single_pic_proc(image_file):
image = np.array(Image.open(image_file).convert('RGB'))
result, image_framed = ocr(image)
return result,image_framed
if __name__ == '__main__':
image_files = glob('./test_images/*.*')
result_dir = './test_result'
if os.path.exists(result_dir):
shutil.rmtree(result_dir)
os.mkdir(result_dir)
for image_file in sorted(image_files):
t = time.time()
result, image_framed = single_pic_proc(image_file)
output_file = os.path.join(result_dir, image_file.split('/')[-1])
txt_file = os.path.join(result_dir, image_file.split('/')[-1].split('.')[0]+'.txt')
print(txt_file)
txt_f = open(txt_file, 'w')
Image.fromarray(image_framed).save(output_file)
print("Mission complete, it took {:.3f}s".format(time.time() - t))
print("\nRecognition Result:\n")
for key in result:
print(result[key][1])
txt_f.write(result[key][1]+'\n')
txt_f.close()