This repository was archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathread_ocr.py
49 lines (37 loc) · 1.44 KB
/
read_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
import os
import io
import ocr_vision
import googlevision
from contextlib import redirect_stdout
python_cmd = 'python'
if os.path.exists('use_venv_for_cmd'):
python_cmd = 'venv/bin/python3'
def run_for_ocr(opt):
translation = False
start_key = 'auto'
end_key = 'auto'
if 'config' in opt:
translation = False if not opt['config']['translation'] else opt['config']['translation']
if 'start_key' in opt['config']:
start_key = opt['config']['start_key']
if 'end_key' in opt['config']:
end_key = opt['config']['end_key']
## step 1 - run something to generate the poly.txt file
print('Running ocr_vision.py file to generate _outputs/poly.txt')
f = io.StringIO()
with redirect_stdout(f):
ocr_vision.run(opt['url'])
result = f.getvalue()
with open('_outputs/bounds.txt', 'w') as f:
f.write(result)
f.close()
## step 2 - generate ocrconfig.meta file for that state (this overwrites previous file)
print('Generating ocrconfig.meta file for {}'.format(opt['state_code']))
os.system('bash generate_ocrconfig.sh {} {} {}'.format(
opt['state_code'].lower(),
'{},{}'.format(start_key, end_key),
translation
))
## step 3 - run googlevision.py file
print('running googlevision.py using ocrconfig.meta file for {}'.format(opt['state_code']))
googlevision.main(config_file='_outputs/ocrconfig.meta', file_name=opt['url'])