This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.py
323 lines (279 loc) · 14.2 KB
/
interface.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
from PyQt5.QtWidgets import(
QMainWindow, QSlider,QApplication,QLabel,
QWidget,QScrollArea,QVBoxLayout,QHBoxLayout,QTabWidget,
)
from PyQt5.QtCore import Qt,QSize
class Opencv_slider(QMainWindow):
'''
使用pyqt6创建的滑动条类
'''
def __init__(self,name):
super().__init__()
self.change_label = 0 #初始化相关变量
self.sld = []
self.showMaximized() #设置窗口全屏显示
self.setWindowTitle(name) #设置窗口的标题
self.setStyleSheet("QLabel{font-size:18px;}") #设置字体大小
self.init_ui() #初始化ui
self.slider_create() #创建滑动条
#滑动条中英文对照表
self.name_dict = {
'armor_h_low':'自瞄_lowHue',
'armor_s_low':'自瞄_lowSat',
'armor_v_low':'自瞄_lowVal',
'armor_h_high':'自瞄_highHue',
'armor_s_high':'自瞄_highSat',
'armor_v_high':'自瞄_highVal',
'energy_h_high':'打符_highHue',
'energy_s_high':'打符_highSat',
'energy_v_high':'打符_highVal',
'energy_h_low':'打符_lowHue',
'energy_s_low':'打符_lowSat',
'energy_v_low':'打符_lowVal',
'MaxRsS':'R的最大面积',
'MinRsS':'R的最小面积',
'MaxRsRatio':'R的最大长宽比',
'fan_armor_distence_max':'装甲板与扇叶中心最大值',
'fan_armor_distence_min':'装甲板与扇叶中心最小值',
'armor_R_distance_max':'装甲板与R距离的最大值',
'armor_R_distance_min':'装甲板与R距离的最小值',
'minlighterarea':'最小灯条面积',
'maxlighterarea':'最大灯条面积',
'minlighterProp':'最小灯条长比宽',
'maxlighterProp':'最大灯条长比宽',
'minAngleError':'最小灯条角度',
'maxAngleError':'最大灯条角度',
'maxarealongRatio':'灯条长长比最大值',
'minarealongRatio':'灯条长长比最小值',
'lightBarAreaDiff':'灯条面积差最大值',
'armorAngleMin':'装甲板角度最小值',
'minarmorArea':'装甲板面积最小值',
'maxarmorArea':'装甲板面积最大值',
'minarmorProp':'小装甲板长宽比最小值',
'maxarmorProp':'小装甲板长宽比最大值',
'minBigarmorProp':'大装甲板长宽比最小值',
'maxBigarmorProp':'大装甲板长宽比最小值',
'angleDiff_near':'近距离灯条角度差最大值',
'angleDiff_far':'远距离灯条角度差最大值',
'minareawidthRatio':'自瞄_lowHue',
'maxareawidthRatio':'自瞄_lowHue',
'minareaRatio':'灯条面积比最小值',
'maxareaRatio':'灯条面积比最大值',
'area_limit':'远近距离区分——面积',
'xcenterdismax':'灯条横向中心距最大值',
'ylengthmin':'装甲板高度最小值',
'ylengcenterRatio':'灯条纵向高度差(灯条纵向距离与装甲板纵向长度比)',
'yixaingangleDiff_near':'近距离灯条异向角度差',
'yixaingangleDiff_far':'远距离灯条异向角度差',
'kh':'测距参数',
}
self.value_dict={
}
def init_ui(self):
'''
初始化ui,实例化需要的控件并且建立关系
'''
self.centralWidget = QWidget(self)
self.centralWidget.setObjectName("centralWidget")
desktop = QApplication.desktop()
self.desktop_size = QSize(int(desktop.width()),int(desktop.height()*0.9))
self.horizontalLayout = QHBoxLayout(self.centralWidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.tabWidget = QTabWidget(self.centralWidget)
self.tabWidget.setEnabled(True)
self.tabWidget.setMinimumSize(self.desktop_size)
self.tabWidget.setObjectName("tabWidget")
self.tabWidget.setCurrentIndex(0)
self.tab_1 = QWidget()
self.tab_1.setObjectName("tab_1")
self.tab_2 = QWidget()
self.tab_2.setObjectName("tab_2")
self.tab_3 = QWidget()
self.tab_3.setObjectName("tab_3")
self.tab_4 = QWidget()
self.tab_4.setObjectName("tab_4")
self.tabWidget.addTab(self.tab_1, "hsv调参")
self.tabWidget.addTab(self.tab_2, "能量机关筛选参数")
self.tabWidget.addTab(self.tab_3, "灯条筛选参数")
self.tabWidget.addTab(self.tab_4, "装甲板筛选参数")
self.weight_sa_1 = self.widget_contents_create(self.tab_1)
self.weight_sa_2 = self.widget_contents_create(self.tab_2)
self.weight_sa_3 = self.widget_contents_create(self.tab_3)
self.weight_sa_4 = self.widget_contents_create(self.tab_4)
self.change_label = 1
self.setCentralWidget(self.centralWidget)
def get_first_vlaue(self,armor_list,energy_list):
#获取滑动条的初值
[self.armor_h_low,\
self.armor_s_low,\
self.armor_v_low,\
self.armor_h_high,\
self.armor_s_high,\
self.armor_v_high,\
self.minlighterarea,\
self.maxlighterarea,\
self.minlighterProp,\
self.maxlighterProp,\
self.minAngleError,\
self.maxAngleError,\
self.maxarealongRatio,\
self.minarealongRatio,\
self.lightBarAreaDiff,\
self.armorAngleMin,\
self.minarmorArea,\
self.maxarmorArea,\
self.minarmorProp,\
self.maxarmorProp,\
self.minBigarmorProp,\
self.maxBigarmorProp,\
self.angleDiff_near,\
self.angleDiff_far,\
self.minareawidthRatio,\
self.maxareawidthRatio,\
self.minareaRatio,\
self.maxareaRatio,\
self.area_limit,\
self.xcenterdismax,\
self.ylengthmin,\
self.ylengcenterRatio,\
self.yixaingangleDiff_near,\
self.yixaingangleDiff_far,\
self.kh] = armor_list
[self.energy_h_low, \
self.energy_s_low, \
self.energy_v_low, \
self.energy_h_high, \
self.energy_s_high, \
self.energy_v_high, \
self.MaxRsS,\
self.MinRsS,\
self.MaxRsRatio,\
self.fan_armor_distence_max,\
self.fan_armor_distence_min,\
self.armor_R_distance_max,\
self.armor_R_distance_min] = energy_list
def widget_contents_create(self,widget):
'''
初始化标签页里的滚动条页,返回用于添加滑动条的QWidget
'''
widget_btn = QWidget(widget)
widget_btn.setObjectName("widget_btn")
widget_btn.adjustSize()
horizontalLayout_3 = QHBoxLayout(widget_btn)
horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
horizontalLayout_3.setObjectName("horizontalLayout_3")
scrollArea = QScrollArea(widget_btn)
scrollArea.adjustSize()
scrollArea.setWidgetResizable(True)
scrollArea.setObjectName("scrollArea")
scrollAreaWidgetContents = QWidget(widget_btn)
scrollAreaWidgetContents.adjustSize()
scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
verticalLayout = QVBoxLayout(scrollAreaWidgetContents)
verticalLayout.setObjectName("verticalLayout")
scrollArea.setWidget(scrollAreaWidgetContents)
horizontalLayout_3.addWidget(scrollArea)
return widget_btn,verticalLayout,scrollAreaWidgetContents
def slider_create(self):
'''
创建滑动条
'''
self.TrackerBar_create('armor_h_low',self.armor_h_low,255,self.weight_sa_1)
self.TrackerBar_create('armor_s_low',self.armor_s_low,255,self.weight_sa_1)
self.TrackerBar_create('armor_v_low',self.armor_v_low,255,self.weight_sa_1)
self.TrackerBar_create('armor_h_high',self.armor_h_high,255,self.weight_sa_1)
self.TrackerBar_create('armor_s_high',self.armor_s_high,255,self.weight_sa_1)
self.TrackerBar_create('armor_v_high',self.armor_v_high,255,self.weight_sa_1)
self.TrackerBar_create('minlighterarea',self.minlighterarea,255,self.weight_sa_3)
self.TrackerBar_create('maxlighterarea',self.maxlighterarea,10000,self.weight_sa_3)
self.TrackerBar_create('minlighterProp',self.minlighterProp,500,self.weight_sa_3)
self.TrackerBar_create('maxlighterProp',self.maxlighterProp,3000,self.weight_sa_3)
self.TrackerBar_create('minAngleError',self.minAngleError,3600,self.weight_sa_3)
self.TrackerBar_create('maxAngleError',self.maxAngleError,3600,self.weight_sa_3)
self.TrackerBar_create('maxarealongRatio', self.maxarealongRatio, 300, self.weight_sa_4)
self.TrackerBar_create('minarealongRatio', self.minarealongRatio, 100, self.weight_sa_4)
self.TrackerBar_create('lightBarAreaDiff', self.lightBarAreaDiff, 10000, self.weight_sa_4)
self.TrackerBar_create('armorAngleMin', self.armorAngleMin, 3600, self.weight_sa_4)
self.TrackerBar_create('minarmorArea', self.minarmorArea, 5000, self.weight_sa_4)
self.TrackerBar_create('maxarmorArea', self.maxarmorArea, 100000, self.weight_sa_4)
self.TrackerBar_create('minarmorProp', self.minarmorProp, 255, self.weight_sa_4)
self.TrackerBar_create('maxarmorProp', self.maxarmorProp, 600, self.weight_sa_4)
self.TrackerBar_create('minBigarmorProp', self.minBigarmorProp, 300, self.weight_sa_4)
self.TrackerBar_create('maxBigarmorProp', self.maxBigarmorProp, 600, self.weight_sa_4)
self.TrackerBar_create('angleDiff_near', self.angleDiff_near, 100, self.weight_sa_4)
self.TrackerBar_create('angleDiff_far', self.angleDiff_far, 100, self.weight_sa_4)
self.TrackerBar_create('minareawidthRatio', self.minareawidthRatio, 600, self.weight_sa_4)
self.TrackerBar_create('maxareawidthRatio', self.maxareawidthRatio, 600, self.weight_sa_4)
self.TrackerBar_create('minareaRatio', self.minareaRatio, 600, self.weight_sa_4)
self.TrackerBar_create('maxareaRatio', self.maxareaRatio, 600, self.weight_sa_4)
self.TrackerBar_create('area_limit', self.area_limit, 600, self.weight_sa_4)
self.TrackerBar_create('xcenterdismax', self.xcenterdismax, 600, self.weight_sa_4)
self.TrackerBar_create('ylengthmin', self.ylengthmin, 10, self.weight_sa_4)
self.TrackerBar_create('ylengcenterRatio', self.ylengcenterRatio, 10, self.weight_sa_4)
self.TrackerBar_create('yixaingangleDiff_near', self.yixaingangleDiff_near, 10, self.weight_sa_4)
self.TrackerBar_create('yixaingangleDiff_far', self.yixaingangleDiff_far, 10, self.weight_sa_4)
self.TrackerBar_create('kh', self.kh, 40000, self.weight_sa_4)
self.TrackerBar_create('energy_h_high',self.energy_h_high,255,self.weight_sa_1)
self.TrackerBar_create('energy_s_high',self.energy_s_high,255,self.weight_sa_1)
self.TrackerBar_create('energy_v_high',self.energy_v_high,255,self.weight_sa_1)
self.TrackerBar_create('energy_h_low',self.energy_h_low,255,self.weight_sa_1)
self.TrackerBar_create('energy_s_low',self.energy_s_low,255,self.weight_sa_1)
self.TrackerBar_create('energy_v_low',self.energy_v_low,255,self.weight_sa_1)
self.TrackerBar_create('MaxRsS',self.MaxRsS,10000,self.weight_sa_2)
self.TrackerBar_create('MinRsS',self.MinRsS,10000,self.weight_sa_2)
self.TrackerBar_create('MaxRsRatio',self.MaxRsRatio,2000,self.weight_sa_2)
self.TrackerBar_create('fan_armor_distence_max',self.fan_armor_distence_max,500,self.weight_sa_2)
self.TrackerBar_create('fan_armor_distence_min',self.fan_armor_distence_min,255,self.weight_sa_2)
self.TrackerBar_create('armor_R_distance_max',self.armor_R_distance_max,1000,self.weight_sa_2)
self.TrackerBar_create('armor_R_distance_min',self.armor_R_distance_min,500,self.weight_sa_2)
def TrackerBar_create(self,name,value,range_max,GroupBox):
'''
创建单个滑动条
'''
temp_name = self.name_dict[name]
_,verticalLayout,scrollAreaWidgetContents = GroupBox
sld = QSlider(Qt.Orientation.Horizontal,scrollAreaWidgetContents)
sld.setRange(0,range_max) #设置滑动条范围
sld.setValue(int(value)) #设置滑动条初始值
sld.setMinimumSize(500,30)
sld.setMaximumSize(1200,1000)
sld.adjustSize()
sld.valueChanged[int].connect(self.changeValue) #绑定信号,随时更新滑动条的值
sld.setTickPosition(sld.TickPosition.TicksBelow) #左对齐
label = QLabel(str(temp_name)+':'+str(value)) #初始化上标文字
label.setAlignment(Qt.AlignmentFlag.AlignLeft) #左对齐
label.setMinimumSize(500,30)
label.adjustSize()
verticalLayout.addWidget(label)
verticalLayout.addWidget(sld)
self.sld.append([sld,label,name,value])
def changeValue(self):
#值更改时候的回调函数,实时显示对应的滑动条更改
signalSource = self.sender()
#寻找对应的label
for i,s in enumerate(self.sld):
if s[0] is signalSource:
label = s[1]
temp_i = i
break
text_list = str(label.text()).split(':')
new_name = text_list[0]+':'+str(signalSource.value())
label.setText(new_name)
self.sld[temp_i][3] = signalSource.value()
def resizeEvent(self, event):
'''
改变窗口大小时触发的回调函数,根据窗口大小重绘
'''
if self.change_label:
windows_size = self.size()
for temp_sa in [self.weight_sa_1,self.weight_sa_2,self.weight_sa_3,self.weight_sa_4]:
widget_btn,_,_ = temp_sa
widget_btn.resize(int(windows_size.width()-10),int(windows_size.height()-30))
def return_value_aimbot(self):
#返回自瞄需要的值
temp = [i[3] for i in self.sld]
return temp[0:35]
def return_value_energy(self):
#返回自瞄需要的值
temp = [i[3] for i in self.sld]
return temp[35:-1]