-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera_information_guid.py
212 lines (151 loc) · 8.5 KB
/
camera_information_guid.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtWidgets
from camera_information_class import CameraInformationClass
from plist_set import ProcessSettingsClass
from warning_class import AppWarningsClass
import string
class CameraInfoUI(object):
def __init__(self, rule_distance):
if rule_distance is None:
rule_distance = ""
self.rule_distance = rule_distance
self.params = ProcessSettingsClass()
self.camerainfo = CameraInformationClass()
def setupUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setObjectName("Dialog")
Dialog.setFixedSize(281, 350)
Dialog.setWindowTitle(_translate("Dialog", "Camera information"))
values = self.camerainfo.get_metadata()
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(70, 10, 131, 16))
self.label.setObjectName("label")
self.label.setText(_translate("Dialog", "Camera Information"))
self.labelSensorWidth = QtWidgets.QLabel(Dialog)
self.labelSensorWidth.setGeometry(QtCore.QRect(10, 40, 141, 16))
self.labelSensorWidth.setObjectName("labelSensorWidth")
self.labelSensorWidth.setText(_translate("Dialog", "Sensor Width (mm)"))
self.labelSensorHeight = QtWidgets.QLabel(Dialog)
self.labelSensorHeight.setGeometry(QtCore.QRect(10, 70, 141, 16))
self.labelSensorHeight.setObjectName("labelSensorHeight")
self.labelSensorHeight.setText(_translate("Dialog", "Sensor Height (mm)"))
self.labelPixelesWidth = QtWidgets.QLabel(Dialog)
self.labelPixelesWidth.setGeometry(QtCore.QRect(10, 110, 141, 16))
self.labelPixelesWidth.setObjectName("labelPixelesWidth")
self.labelPixelesWidth.setText(_translate("Dialog", "Image Width (pixeles)"))
self.labelPixelesHeght = QtWidgets.QLabel(Dialog)
self.labelPixelesHeght.setGeometry(QtCore.QRect(10, 140, 141, 16))
self.labelPixelesHeght.setObjectName("labelPixelesHeght")
self.labelPixelesHeght.setText(_translate("Dialog", "Image Height (pixeles)"))
self.labelPitch = QtWidgets.QLabel(Dialog)
self.labelPitch.setGeometry(QtCore.QRect(10, 180, 141, 16))
self.labelPitch.setObjectName("labelPitch")
self.labelPitch.setText(_translate("Dialog", "Pixel pitch (µm)"))
self.input_width = QtWidgets.QLineEdit(Dialog)
self.input_width.setGeometry(QtCore.QRect(162, 40, 101, 21))
self.input_width.setObjectName("input_width")
self.input_width.setText(str(values["widthSensor"]))
self.input_width.textChanged.connect(self.get_pitch)
self.input_height = QtWidgets.QLineEdit(Dialog)
self.input_height.setGeometry(QtCore.QRect(162, 70, 101, 21))
self.input_height.setObjectName("input_height")
self.input_height.setText(str(values["heightSensor"]))
self.input_pixel_height = QtWidgets.QLineEdit(Dialog)
self.input_pixel_height.setGeometry(QtCore.QRect(162, 140, 101, 21))
self.input_pixel_height.setObjectName("input_pixel_height")
self.input_pixel_height.setText(str(values["imgHeight"]))
self.input_pixel_width = QtWidgets.QLineEdit(Dialog)
self.input_pixel_width.setGeometry(QtCore.QRect(162, 110, 101, 21))
self.input_pixel_width.setObjectName("input_pixel_width")
self.input_pixel_width.setText(str(values["imgWidth"]))
self.input_pixel_width.textChanged.connect(self.get_pitch)
self.input_pixel_pitch = QtWidgets.QLineEdit(Dialog)
self.input_pixel_pitch.setGeometry(QtCore.QRect(162, 180, 101, 21))
self.input_pixel_pitch.setObjectName("input_pixel_pitch")
self.input_pixel_pitch.setText(str(values["pitch"]))
#----rule info
self.labelRule = QtWidgets.QLabel(Dialog)
self.labelRule.setGeometry(QtCore.QRect(10, 220, 141, 16))
self.labelRule.setObjectName("labelPixelesWidth")
self.labelRule.setText(_translate("Dialog", "Rule (pixel|mm)"))
self.input_rule_pixel = QtWidgets.QLineEdit(Dialog)
self.input_rule_pixel.setGeometry(QtCore.QRect(162, 220, 48, 21))
rulePixel = self.rule_distance
if self.rule_distance == "":
rulePixel = values["rulePixel"]
#elif values["rulePixel"] == "":
# rulePixel = self.rule_distance
self.input_rule_pixel.setObjectName("rule_pixel_distance")
self.input_rule_pixel.setText(str( rulePixel))
self.input_rule_pixel.setEnabled(False)
self.input_rule_real = QtWidgets.QLineEdit(Dialog)
self.input_rule_real.setGeometry(QtCore.QRect(212, 220, 48, 21))
self.input_rule_real.setObjectName("rule_real_distance")
self.input_rule_real.setText(str(values["ruleReal"]))
self.input_rule_real.textChanged.connect(self.get_resolution)
self.input_rule_real.setEnabled(False)
if self.input_rule_pixel.text() != "":
self.input_rule_real.setEnabled(True)
self.labelPPIResolution = QtWidgets.QLabel(Dialog)
self.labelPPIResolution.setGeometry(QtCore.QRect(10, 260, 141, 16))
self.labelPPIResolution.setObjectName("resolutionPPI")
self.labelPPIResolution.setText(_translate("Dialog", "Resolution (PPI)"))
self.input_ppi_resolution = QtWidgets.QLineEdit(Dialog)
self.input_ppi_resolution.setGeometry(QtCore.QRect(162, 260, 101, 21))
self.input_ppi_resolution.setObjectName("resolution")
self.input_ppi_resolution.setText(str(values["resolution"]))
#---- close & save
self.CancelBT = QtWidgets.QPushButton(Dialog)
self.CancelBT.setGeometry(QtCore.QRect(140, 300, 113, 32))
self.CancelBT.setObjectName("CancelBT")
self.CancelBT.setText(_translate("Dialog", "Close"))
self.CancelBT.clicked.connect(Dialog.close)
self.saveBT = QtWidgets.QPushButton(Dialog)
self.saveBT.setGeometry(QtCore.QRect(30, 300, 113, 32))
self.saveBT.setObjectName("saveBT")
self.saveBT.setText(_translate("Dialog", "Save"))
# self.saveBT.clicked.connect(self.saveValues)
self.saveBT.clicked.connect(lambda state, x=Dialog: self.save_new_camera_values(x))
QtCore.QMetaObject.connectSlotsByName(Dialog)
def clean_chars(self, value):
#return ''.join(filter(str.isdigit, value))
return value
#all = string.maketrans('', '')
#nodigs = all.translate(all, string.digits)
#return value.translate(all, nodigs)
def get_resolution(self):
#img_width = self.input_pixel_width.text()
#img_height = self.input_pixel_height.text()
#diagonal = math.sqrt( (img_width*img_width) + (img_height*img_height) )
rule_pixel = self.clean_chars(self.input_rule_pixel.text())
rule_real = float(self.clean_chars(self.input_rule_real.text())) / 25.4
if rule_real > 0:
ppi = int( float(rule_pixel) / float(rule_real) )
self.input_ppi_resolution.setText( str(ppi) )
def get_pitch(self):
width_sensor = self.clean_chars(self.input_width.text())
img_width = self.clean_chars(self.input_pixel_width.text())
if self.camerainfo.check_if_number(width_sensor) and self.camerainfo.check_if_number(img_width):
if width_sensor != "" and img_width != "":
if float(width_sensor) > 0 and float(img_width) > 0:
pitch = round((float(width_sensor) / float(img_width)) * 1000, 2)
self.input_pixel_pitch.setText(str(pitch))
def non_empty(self,value):
if value.strip() == "":
s = 0
else:
s = value.strip()
return s
def save_new_camera_values(self, x):
o = {"widthSensor": self.clean_chars(int(float(self.non_empty(self.input_width.text())))),
"heightSensor": self.clean_chars(int(float(self.non_empty(self.input_height.text())))),
"imgWidth": self.clean_chars(int(float(self.non_empty(self.input_pixel_width.text())))),
"imgHeight": self.clean_chars(int(float(self.non_empty(self.input_pixel_height.text())))),
"pitch": self.non_empty(self.input_pixel_pitch.text()),
"rulePixel": self.clean_chars(self.non_empty(self.input_rule_pixel.text())),
"ruleReal": self.clean_chars(self.non_empty(self.input_rule_real.text())),
"resolution": self.clean_chars(self.non_empty(self.input_ppi_resolution.text()))
}
s = self.camerainfo.save_camera_values(o)
if s:
x.close()