Skip to content

Commit 1c05865

Browse files
PyQt/OCR added init
1 parent 9d9b6c8 commit 1c05865

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

PyQtDesigner/#Guide.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
pip3 install PyQt5
22
pip3 install PyQt5-tools
3+
============================================================================
4+
pip install pywin32
5+
pip install pyinstaller
6+
7+
in cmd
8+
pyinstaller --onedir --onefile --name=Webscrapping --windowed "H:\Github\PythonScripts\PyQtDesigner\WebScrapper\WebScrapper.py"
9+
10+
============================================================================
11+
12+
in cmd :
13+
cd G:\Program Files\Python36\Scripts
14+
15+
G:\Program Files\Python36\Scripts>pyuic5 -x "H:\Github\PythonScripts\PyQtDesigner\WebScrapper\WebScrapper.ui" -o "H:\Github\PythonScripts\PyQtDesigner\WebScrapper\WebScrapperUI.py"
16+
17+
============================================================================
318

419
css
520
background-image:url(H:/Github/PythonScripts/PyQtDesigner/Watcher/trail.jpg);

PyQtDesigner/OCR/Ocr.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from PyQt5 import QtCore, QtGui, QtWidgets , uic
2+
from PyQt5.QtGui import QIcon ,QPixmap
3+
import sys
4+
import os
5+
import re
6+
import cv2
7+
import pytesseract
8+
# set file path
9+
10+
11+
#Init PythonUI MainWindow
12+
class Ocr(QtWidgets.QMainWindow):
13+
def __init__(self):
14+
super(Ocr,self).__init__()
15+
pytesseract.pytesseract.tesseract_cmd = 'H:\Program Files (x86)\Tesseract-OCR\\tesseract.exe'
16+
self.scriptDir = os.path.dirname(os.path.realpath(__file__))
17+
filePath = self.scriptDir + os.path.sep + 'ocrUI.ui'
18+
filePath = os.path.join(os.path.dirname(sys.executable), filePath)
19+
uic.loadUi(filePath,self)
20+
self.setWindowTitle('OCR')
21+
self.buttonGetImage.clicked.connect(self.getImage)
22+
self.buttonExtractText.clicked.connect(self.extractText)
23+
self.buttonExtractText.setEnabled(False)
24+
QtCore.pyqtSlot()
25+
26+
def getImage(self):
27+
options = QtWidgets.QFileDialog.Options()
28+
options |= QtWidgets.QFileDialog.DontUseNativeDialog
29+
self.fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Open an image", "","All Files (*);;Python Files (*.py)", options=options)
30+
if self.fileName:
31+
print(self.fileName)
32+
pattern = ".(jpg|png|jpeg|bmp|jpe|tiff)$"
33+
if re.search(pattern,self.fileName):
34+
self.setImage(self.fileName)
35+
36+
37+
def setImage(self,fileName):
38+
self.labelImage.setPixmap(QPixmap(fileName))
39+
self.buttonExtractText.setEnabled(True)
40+
41+
def extractText(self):
42+
config = ('-l eng --oem 1 --psm 3')
43+
img = cv2.imread(self.fileName, cv2.IMREAD_COLOR)
44+
# Run tesseract OCR on image
45+
text = pytesseract.image_to_string(img, config=config)
46+
# Print recognized text
47+
self.textBrowser.append(text)
48+
print(text)
49+
50+
51+
if __name__ == "__main__":
52+
app = QtWidgets.QApplication(sys.argv)
53+
ocr = Ocr()
54+
ocr.show()
55+
56+
sys.exit(app.exec_())

PyQtDesigner/OCR/Para.jpg

51.4 KB
Loading

PyQtDesigner/OCR/ocrUI.ui

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>1289</width>
10+
<height>719</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>MainWindow</string>
15+
</property>
16+
<widget class="QWidget" name="centralwidget">
17+
<widget class="QPushButton" name="buttonGetImage">
18+
<property name="geometry">
19+
<rect>
20+
<x>30</x>
21+
<y>620</y>
22+
<width>130</width>
23+
<height>40</height>
24+
</rect>
25+
</property>
26+
<property name="font">
27+
<font>
28+
<pointsize>10</pointsize>
29+
</font>
30+
</property>
31+
<property name="text">
32+
<string>Load image</string>
33+
</property>
34+
</widget>
35+
<widget class="QLabel" name="labelImage">
36+
<property name="geometry">
37+
<rect>
38+
<x>30</x>
39+
<y>50</y>
40+
<width>711</width>
41+
<height>521</height>
42+
</rect>
43+
</property>
44+
<property name="frameShape">
45+
<enum>QFrame::WinPanel</enum>
46+
</property>
47+
<property name="text">
48+
<string/>
49+
</property>
50+
</widget>
51+
<widget class="QTextBrowser" name="textBrowser">
52+
<property name="geometry">
53+
<rect>
54+
<x>860</x>
55+
<y>50</y>
56+
<width>411</width>
57+
<height>521</height>
58+
</rect>
59+
</property>
60+
</widget>
61+
<widget class="QPushButton" name="buttonExtractText">
62+
<property name="geometry">
63+
<rect>
64+
<x>190</x>
65+
<y>620</y>
66+
<width>130</width>
67+
<height>40</height>
68+
</rect>
69+
</property>
70+
<property name="font">
71+
<font>
72+
<pointsize>10</pointsize>
73+
</font>
74+
</property>
75+
<property name="text">
76+
<string>Extract text</string>
77+
</property>
78+
</widget>
79+
<widget class="QPushButton" name="butttonClear">
80+
<property name="geometry">
81+
<rect>
82+
<x>860</x>
83+
<y>610</y>
84+
<width>130</width>
85+
<height>40</height>
86+
</rect>
87+
</property>
88+
<property name="font">
89+
<font>
90+
<pointsize>10</pointsize>
91+
</font>
92+
</property>
93+
<property name="text">
94+
<string>Clear</string>
95+
</property>
96+
</widget>
97+
<widget class="QPushButton" name="buttonSave">
98+
<property name="geometry">
99+
<rect>
100+
<x>1030</x>
101+
<y>610</y>
102+
<width>130</width>
103+
<height>40</height>
104+
</rect>
105+
</property>
106+
<property name="text">
107+
<string>Save</string>
108+
</property>
109+
</widget>
110+
</widget>
111+
<widget class="QMenuBar" name="menubar">
112+
<property name="geometry">
113+
<rect>
114+
<x>0</x>
115+
<y>0</y>
116+
<width>1289</width>
117+
<height>21</height>
118+
</rect>
119+
</property>
120+
</widget>
121+
<widget class="QStatusBar" name="statusbar"/>
122+
</widget>
123+
<resources/>
124+
<connections/>
125+
</ui>

0 commit comments

Comments
 (0)