-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
90 lines (73 loc) · 2.27 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import tkinter as tk
from PIL import Image,ImageTk
import pyscreenshot as ImageGrab
import pyautogui
import pytesseract
import pyperclip
import io
import sys
if("win" in sys.platform):
pytesseract.pytesseract.tesseract_cmd =r'D:\tess\tesseract' #Make sure to chnage the path to your tesseract executable
window = tk.Tk()
state=0
sx,sy=0,0
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("!")
pop = tk.Label(popup, text=msg)
pop.pack(side="top", fill="x", pady=10)
B1 = tk.Button(popup, text="Okay", command = sys.exit)
B1.pack()
popup.mainloop()
def motion(event):
global state
x, y = event.x, event.y
global label,sx,sy
if(state==1):
label.coords(rec,sx,sy,x,y)
def draw(e):
global state
if(state!=2):
print(pyautogui.position().x,pyautogui.position().y)
global label
global sx,sy
sx,sy=e.x,e.y
label.delete("all")
global rec
rec=label.create_rectangle(e.x,e.y,e.x,e.y,fill='black')
state=1
def fin(e):
global state
if(state!=2):
state=2
bbox = (sx, sy, e.x, e.y)
pic=ImageGrab.grab(bbox=bbox)
#pic.save('read.png')
buffer = io.BytesIO()
pic.save(buffer,format='png')
try:
pyperclip.copy(pytesseract.image_to_string(pic,config='--psm 6 --oem 1'))
except:
window.destroy()
popupmsg("tesseract might not be installed on your system")
window.destroy()
window.attributes('-fullscreen', True)
window.title("On Screen OCR")
window.configure(bg='grey')
window.wait_visibility(window)
window.attributes("-alpha", 0.5)
window.config(cursor="crosshair")
if("win" in sys.platform):
window.attributes("-transparentcolor", "black")
label = tk.Canvas(window,background='grey',borderwidth=0,highlightthickness=0)
label.pack()
pic=ImageGrab.grab()
img=ImageTk.PhotoImage(pic)
print(img.width(),img.height())
window.geometry(str(img.width())+'x'+str(img.height())+"+0+0")
window.resizable(0, 0)
label.place(x=0,y=0,width=img.width(),height=img.height())
label.bind('<Motion>', motion)
label.bind('<Button-1>',draw)
label.bind('<ButtonRelease>',fin)
window.mainloop()