-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.py
57 lines (44 loc) · 1.52 KB
/
reader.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
import pytesseract
import cv2
import os
from PIL import ImageGrab
from PySide6.QtCore import QObject, Slot, Signal
class MainWindow(QObject):
def __init__(self):
QObject.__init__(self)
signalOutput = Signal(str)
signalError = Signal(str)
signalAlert = Signal(str)
result = ""
@Slot(str)
def openFile(self, fileName):
try:
self.result += self.parseImg(fileName[8:])
self.signalAlert.emit("Input parsed successfully")
except Exception as e:
print(e)
self.signalError.emit("Failed to parse image")
self.signalAlert.emit("Error: Failed to parse image")
@Slot()
def getClipboard(self):
tempPath = "./Images/temp.png"
try:
ImageGrab.grabclipboard().save(tempPath, "PNG")
self.result += self.parseImg(tempPath)
self.signalAlert.emit("Input parsed successfully")
except Exception as e:
print(e)
self.signalError.emit("Failed to parse image")
self.signalAlert.emit("Error: Failed to parse image")
return
os.remove(tempPath)
@Slot()
def printContents(self):
# For testing purposes
#self.result += self.parseImg("./Samples/img.png")
if (len(self.result)):
self.signalOutput.emit(self.result)
def parseImg(self, fileName):
myconfig = r"--psm 6 --oem 3"
img = cv2.imread(fileName)
return pytesseract.image_to_string(img, config=myconfig)