-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathocr.py
37 lines (31 loc) · 823 Bytes
/
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
import sys
import json
from PIL import Image
import os
import pytesseract
image = sys.argv[1]
filename = "json/output.json"
f = open(filename, "r+")
data = json.load(f)
def format(img, obj):
xtop = int(obj["x1"])
ytop = int(obj["y1"])
xbot = int(obj["x2"])
ybot = int(obj["y2"])
outy = img.crop((xtop, ytop, xbot, ybot))
#print(name)
#print("1")
#outy.show()
width, height = outy.size
newOuty = outy.resize((width*2, height*2))
name = pytesseract.image_to_string(newOuty)
#newOuty.show()
#print(button)
obj["name"] = name
for i in data:
format(Image.open(image), i)
#print("test")
#pytesseract.image_to_string(Image.open(outy))
#print("testover")
n = open(filename, 'w')
n.write(json.dumps(data))