forked from formazione/utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grabimagetext.py
45 lines (36 loc) · 968 Bytes
/
grabimagetext.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
# grabscreen.py
import pyscreenshot as ImageGrab
import os
from pynput.mouse import Listener
import sys
import pytesseract
def grab(x, y, w, h):
im = ImageGrab.grab(bbox=(x, y, w, h))
save(im)
ocr()
def save(im):
im.save('im.png')
os.startfile('im.png')
def ocr():
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'
print(pytesseract.image_to_string(r'im.png'))
click1 = 0
x1 = 0
y1 = 0
def on_click(x, y, button, pressed):
global click1, x1, y1
if pressed:
if click1 == 0:
x1 = x
y1 = y
click1 = 1
else:
grab(x1, y1, x, y)
listener.stop()
sys.exit()
print("Click once on top left and once on bottom right")
# with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener:
with Listener(on_click=on_click) as listener:
listener.join()
# listener.stop()
# sys.exit()