-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (96 loc) · 2.7 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from PyQt5.QtWidgets import (
QApplication,
QWidget,
QVBoxLayout,
QHBoxLayout,
QLabel,
QCheckBox,
QLineEdit,
QFormLayout,
QPushButton,
QFileDialog
)
from PyQt5.QtGui import QIntValidator
from PyQt5.QtCore import Qt
from process_img import process
# basic GUI setup
app = QApplication(['Advanced Image Processing Project'])
window = QWidget()
window.setFixedSize(500, 200)
layout = QVBoxLayout()
flo = QFormLayout()
bottom = QHBoxLayout()
layout.addLayout(flo)
layout.addLayout(bottom)
# setup flags
segmentCharacters = False
segmentLines = True
segmentParagraphs = True
# setup parameter inputs
lineCloseKernelWidth = 40
paragraphCloseKernelHeight = 10
def lckwChanged(val):
if val != '':
global lineCloseKernelWidth
lineCloseKernelWidth = int(val)
def pckwChanged(val):
if val != '':
global paragraphCloseKernelHeight
paragraphCloseKernelHeight = int(val)
def flagChanged(flag):
checked = lambda state: state == Qt.Checked
if flag == 'characters':
def f(state):
global segmentCharacters
segmentCharacters = checked(state)
return f
if flag == 'lines':
def f(state):
global segmentLines
segmentLines = checked(state)
return f
if flag == 'paragraphs':
def f(state):
global segmentParagraphs
segmentParagraphs = checked(state)
return f
c1 = QCheckBox()
c1.setChecked(segmentCharacters)
c1.stateChanged.connect(flagChanged('characters'))
c2 = QCheckBox()
c2.setChecked(segmentLines)
c2.stateChanged.connect(flagChanged('lines'))
c3 = QCheckBox()
c3.setChecked(segmentParagraphs)
c3.stateChanged.connect(flagChanged('paragraphs'))
e1 = QLineEdit()
e1.setValidator(QIntValidator(1, 100))
e1.setText('40')
e1.textChanged.connect(lckwChanged)
e2 = QLineEdit()
e2.setValidator(QIntValidator(1, 50))
e2.setText('10')
e2.textChanged.connect(pckwChanged)
flo.addRow('Segment characters', c1)
flo.addRow('Segment lines', c2)
flo.addRow('Segment paragraphs', c3)
flo.addRow('Kernel height for joining paragraphs', e2)
flo.addRow('Kernel width for joining lines', e1)
# setup open image button
def selectImage():
path = QFileDialog.getOpenFileName()[0]
if path != '':
flags = {
'characters': segmentCharacters,
'lines': segmentLines,
'paragraphs': segmentParagraphs
}
process(path, flags, lineCloseKernelWidth, paragraphCloseKernelHeight)
bottom.addWidget(QLabel('Select an image to process!'))
openFileButton = QPushButton('Open an image')
openFileButton.clicked.connect(selectImage)
bottom.addWidget(openFileButton)
# run the GUI
window.setLayout(layout)
window.show()
app.exec_()