forked from YCG09/chinese_ocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
28 lines (24 loc) · 816 Bytes
/
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
#-*- coding:utf-8 -*-
import os
import ocr
import time
import shutil
import numpy as np
from PIL import Image
from glob import glob
image_files = glob('./test_images/*.*')
if __name__ == '__main__':
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):
image = np.array(Image.open(image_file).convert('RGB'))
t = time.time()
result, image_framed = ocr.model(image)
output_file = os.path.join(result_dir, image_file.split('/')[-1])
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])