-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgoogle-ocr.py
More file actions
35 lines (25 loc) · 814 Bytes
/
google-ocr.py
File metadata and controls
35 lines (25 loc) · 814 Bytes
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
import glob
import os
files = []
for filename in glob.glob('*.jpg'):
files.append(filename)
for image in sorted(files):
print "uploading " + image
command = "gdput.py -t ocr " + image + " > result.log"
print "running " + command
os.system(command)
resultfile = open("result.log","r").readlines()
for line in resultfile:
if "id:" in line:
fileid = line.split(":")[1].strip()
filename = image.split(".")[0] + ".txt"
get_command = "gdget.py -f txt -s " + filename + " " + fileid
print "running "+ get_command
os.system(get_command)
print "Merging all text files into ocr-result.txt"
files = glob.glob('*.txt' )
with open('ocr-result.txt', 'w' ) as result:
for textfile in files:
for line in open( textfile, 'r' ):
result.write( line )
print "Done"