-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.py
516 lines (453 loc) · 24.3 KB
/
ui.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# ui.py
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QComboBox, QVBoxLayout, QWidget, QGroupBox, QLabel, QSlider, QDoubleSpinBox, QHBoxLayout
from PySide6.QtWidgets import QPushButton, QLineEdit, \
QTextEdit, QFrame, QCheckBox
# !/usr/bin/env python
# coding=utf-8
class UiMainWindow:
def setupUi(self, main_window):
central_widget = QWidget(main_window)
main_window.setCentralWidget(central_widget)
# 创建水平布局
main_layout = QHBoxLayout(central_widget)
# 创建菜单布局
# 创建一个QFrame作为按钮的容器,并设置渐变色背景
""" background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #DAD299,
stop:1 #B0DAB9);"""
self.menu_frame = QFrame()
self.menu_frame.setFixedSize(230, 450)
self.menu_frame.setStyleSheet("""
background-color: ;
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #DAD299,
stop:1 #B0DAB9);
border: 2px solid white;
border-radius: 20px;
""")
# 创建图像左侧布局
left_layout = QVBoxLayout()
# background-color: #FFFFE0; /* 设置背景颜色为淡黄色 */
""" background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #EDE574,
stop:1 #E1F5C4);"""
self.left_frame = QLabel()
self.left_frame.setFixedSize(550, 550)
self.left_frame.setStyleSheet("""
QLabel {
background-color: #FFFFE0; /* 设置背景颜色为淡黄色 */
border: 1px solid white; /* 设置边框颜色为黑色 */
border-radius : 5px;
}
""")
# 创建图像右侧布局
right_layout = QVBoxLayout()
self.right_frame = QLabel()
self.right_frame.setFixedSize(550, 550)
self.right_frame.setStyleSheet(("""
QLabel {
background-color: #FFFFE0; /* 设置背景颜色为淡黄色 */
border: 1px solid white; /* 设置边框颜色为黑色 */
border-radius : 5px;
}
"""))
# 创建文本框
self.textbox = QTextEdit("运行结果将显示在这里")
self.textbox.setFixedSize(1100, 150)
self.textbox.setReadOnly(True) # 设置文本框为只读
# 设置文本框的CSS样式
self.textbox.setStyleSheet("""
QTextEdit {
background-color: white; /* 浅蓝色 */
border: 1px solid white; /* 设置边框颜色为白色 */
border-radius: 10px; /* 设置边框圆角 */
padding: 5px; /* 添加内边距 */
font-size: 16px; /* 设置字体大小 */
color : gray
}
""")
# 创建导出图片地址输入框
# background-color: rgb(204,225,227); /* 设置背景颜色为浅青色 */
""" background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 #076585,
stop:1 #fff);"""
self.address_line = QLineEdit()
self.address_line.setPlaceholderText("请输入导出检测结果的地址")
self.address_line.setFixedSize(950, 50)
self.address_line.setStyleSheet("""
QLineEdit {
background-color: rgb(204,225,227); /* 设置背景颜色为浅青色 */
border: 1px solid white; /* 设置边框颜色为白色 */
border-radius: 10px; /* 设置边框圆角 */
padding: 5px; /* 可以添加一些内边距 */
color: black; /* 输入文本的颜色 */
font-size: 16px; /* 设置字体大小 */
}
""")
# 创建导出按钮
self.export_image_button = QPushButton("导出图片")
self.export_image_button.setFixedSize(150, 40)
self.export_image_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
" border: 2px solid white; border-radius: 20px;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"color: white;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
## 创建按钮
# 开始检测按钮
self.start_button = QPushButton("开始检测")
self.start_button.setFixedSize(200, 40) # 设置按钮的大小
self.start_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 上传图片按钮
self.upload_image_button = QPushButton("上传图片")
self.upload_image_button.setFixedSize(200, 40)
self.upload_image_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 选择模型按钮
self.upload_pt_button = QPushButton("上传模型")
self.upload_pt_button.setFixedSize(200, 40)
self.upload_pt_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 运行AnyLabeling按钮
self.Labelrun_button = QPushButton("运行label")
self.Labelrun_button.setFixedSize(200, 40)
self.Labelrun_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 运行ActiveLearnRun按钮
self.activeRun_button = QPushButton("运行run")
self.activeRun_button.setFixedSize(200, 40)
self.activeRun_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 运行ActiveLearnTrain按钮
self.activeTrain_button = QPushButton("运行train")
self.activeTrain_button.setFixedSize(200, 40)
self.activeTrain_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# export格式转换按钮
self.export_button = QPushButton("运行export")
self.export_button.setFixedSize(200, 40)
self.export_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 停止进程按钮
self.stop_button = QPushButton("停止进程")
self.stop_button.setFixedSize(200, 40)
self.stop_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 关闭按钮
self.close_button = QPushButton("关闭应用")
self.close_button.setFixedSize(200, 40)
self.close_button.setStyleSheet(u"QPushButton{\n"
"background-repeat: no-repeat;\n"
"background-position: left center;\n"
"background-color: rgba(200, 100, 214, 100);\n"
"border: 1px black solid;\n"
"text-align: center;\n"
"padding-left: 0px;\n"
"font: 700 12pt \"Nirmala UI\";\n"
"color: white;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
"background-color: rgba(150, 140, 214, 199);\n"
"}\n"
)
# 创建垂直按钮布局
button_layout = QVBoxLayout()
button_layout.setSpacing(9) # 设置布局中部件之间的间距为 5 像素
button_layout.addWidget(self.start_button)
button_layout.addWidget(self.upload_image_button)
button_layout.addWidget(self.upload_pt_button)
button_layout.addWidget(self.Labelrun_button)
button_layout.addWidget(self.activeRun_button)
button_layout.addWidget(self.activeTrain_button)
button_layout.addWidget(self.export_button)
button_layout.addWidget(self.stop_button)
button_layout.addWidget(self.close_button)
button_layout.addStretch(5) # 添加伸缩项,将按钮推到顶部
setting_layout = QVBoxLayout()
""" "qlineargradient(x1:0, y1:0, x2:1, y2:1, "
"stop:0 #FFB6C1,"
" stop:1 #FF69B4);""" # 线性粉色渐变 #青色rgb(0,126,126)
# rgb(204,225,227) 浅青色
""""background: qlineargradient(x1:0, y1:0, x2:1, y2:1, "
"stop:0 #76b852,"
"stop:1 #8DC26F);"""
# 创建一个大边框
group_box = QGroupBox()
group_box.setFixedSize(230, 310)
group_box.setStyleSheet(
"QGroupBox {"
" border: 2px solid white; "
"border-radius: 20px;"
" background-color: ;"
"background: qlineargradient(x1:0, y1:0, x2:1, y2:1, "
"stop:0 #76b852,"
"stop:1 #8DC26F);}")
group_layout = QVBoxLayout()
# 在大边框中添加一个QLabel来显示文本
label = QLabel("设置参数")
label.setAlignment(Qt.AlignCenter) # 文本居中对齐
label.setFixedSize(200, 30)
label.setStyleSheet("QLabel { color: white; font : 20px }")
pt_layout = QHBoxLayout() # pt模型 水平布局
# 添加标准IOU值范围标签
pt_label = QLabel("选择模型:")
pt_label.setStyleSheet("QLabel { color: white; }")
pt_layout.addWidget(pt_label)
self.comboBox = QComboBox()
self.comboBox.setStyleSheet(
"QComboBox { border: 2px solid white; border-radius: 10px; background-color: white; }"
"QComboBox::down-arrow { image: url(:/box_down.png); }"
"QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: center right; width: 20px; border-left-width: 0px; border-radius: 10px; }"
"QComboBox::drop-down:hover { background-color: lightgray; }"
"QComboBox::item { color: black; font-family: SimSun; }") # 设置下拉框样式和文本样式
self.comboBox.setFixedSize(150, 30)
pt_layout.addWidget(self.comboBox)
# 创建一个水平布局来容纳标准IOU值范围和可调整数值
iou_layout = QHBoxLayout()
# 添加标准IOU值范围标签
iou_label = QLabel("标准(iou):")
iou_label.setStyleSheet("QLabel { color: white; }")
iou_layout.addWidget(iou_label)
# 添加滑动块
self.iou_slider = QSlider(Qt.Horizontal)
self.iou_slider.setMinimum(0)
self.iou_slider.setMaximum(100)
self.iou_slider.setTickInterval(1)
iou_layout.addWidget(self.iou_slider)
# 添加可调整数值输入框
self.iou_spinbox = QDoubleSpinBox()
self.iou_spinbox.setDecimals(2)
self.iou_spinbox.setRange(0.0, 1.0)
self.iou_spinbox.setSingleStep(0.01) # 设置步长为0.01
iou_layout.addWidget(self.iou_spinbox)
# 将文本和下拉框添加到大边框布局中
group_layout.addWidget(label)
group_layout.addLayout(pt_layout)
# 将水平布局添加到大边框布局中
group_layout.addLayout(iou_layout)
# 在大边框布局中添加 conf 滑块和标签
conf_layout = QHBoxLayout()
# 添加标签
conf_label = QLabel("配置(conf):")
conf_label.setStyleSheet("QLabel { color: white; }")
conf_layout.addWidget(conf_label)
# 添加滑动块
self.conf_slider = QSlider(Qt.Horizontal)
self.conf_slider.setMinimum(0)
self.conf_slider.setMaximum(100)
self.conf_slider.setTickInterval(1)
conf_layout.addWidget(self.conf_slider)
# 添加可调整数值输入框
self.conf_spinbox = QDoubleSpinBox()
self.conf_spinbox.setDecimals(2)
self.conf_spinbox.setRange(0.0, 1.0)
self.conf_spinbox.setSingleStep(0.01) # 设置步长为0.01
conf_layout.addWidget(self.conf_spinbox)
# 将 conf 布局添加到大边框布局中
group_layout.addLayout(conf_layout)
# 在大边框布局中添加延时滑块和标签
delay_layout = QHBoxLayout()
# 添加标签
delay_label = QLabel("延时(ms):")
delay_label.setStyleSheet("QLabel { color: white; }")
delay_layout.addWidget(delay_label)
# 添加滑动块
self.delay_slider = QSlider(Qt.Horizontal)
self.delay_slider.setMinimum(1) # 最小值为1,因为您要求默认值是10
self.delay_slider.setMaximum(100)
self.delay_slider.setTickInterval(1)
delay_layout.addWidget(self.delay_slider)
# 添加可调整数值输入框
self.delay_spinbox = QDoubleSpinBox()
self.delay_spinbox.setDecimals(0) # 延时应该是整数,不需要小数点
self.delay_spinbox.setRange(1, 100)
self.delay_spinbox.setSingleStep(1) # 步长为1
# 配置输入框的默认步长为0.01
self.delay_spinbox.setSingleStep(1) # 步长为0.01
# 配置输入框的上下箭头按一次是跳0.01
self.delay_spinbox.setAccelerated(True)
delay_layout.addWidget(self.delay_spinbox)
# 设置默认值
self.iou_spinbox.setValue(0.45)
self.conf_spinbox.setValue(0.25)
self.delay_spinbox.setValue(10) # 默认值设置为10
# 设置组件数值
self.iou_spinbox.setValue(0.45)
self.conf_spinbox.setValue(0.25)
self.delay_spinbox.setValue(10) # 默认值设置为10
self.iou_slider.setValue(45)
self.conf_slider.setValue(25)
self.delay_slider.setValue(10)
# 将延时布局添加到大边框布局中
group_layout.addLayout(delay_layout)
group_box.setLayout(group_layout)
# 将大边框添加到主布局中
setting_layout.addWidget(group_box)
# 在大边框布局中添加保存格式复选框的布局
self.save_format_layout = QHBoxLayout()
self.save_format_label = QLabel("保存格式:")
self.save_format_label.setStyleSheet("QLabel { color: white; }")
self.save_format_layout.addWidget(self.save_format_label)
# 复选框:是否保存为 mp4/jpg
self.save_mp4_jpg_checkbox = QCheckBox("MP4/JPG")
self.save_mp4_jpg_checkbox.setStyleSheet("QCheckBox { color: white; }")
self.save_format_layout.addWidget(self.save_mp4_jpg_checkbox)
self.save_mp4_jpg_checkbox.setCheckState(Qt.CheckState.Checked)
# 复选框:是否保存 labels (.txt)
self.save_labels_checkbox = QCheckBox("Labels")
self.save_labels_checkbox.setStyleSheet("QCheckBox { color: white; }")
self.save_format_layout.addWidget(self.save_labels_checkbox)
self.save_labels_checkbox.setCheckState(Qt.CheckState.Unchecked)
# 在大边框布局中添加运行后删除文件复选框的布局
self.delete_after_run_layout = QHBoxLayout()
self.delete_after_run_label = QLabel("清空日志/图片/标记:")
self.delete_after_run_label.setStyleSheet("QLabel { color: white; }")
self.delete_after_run_layout.addWidget(self.delete_after_run_label)
# 复选框: 是否删除所有内容
self.delete_content_checkbox = QCheckBox("是/否")
self.delete_content_checkbox.setStyleSheet("QCheckBox { color: white; }")
self.delete_after_run_layout.addWidget(self.delete_content_checkbox)
self.delete_content_checkbox.setCheckState(Qt.CheckState.Unchecked)
group_layout.addLayout(self.save_format_layout)
group_layout.addLayout(self.delete_after_run_layout)
group_box.setLayout(group_layout)
# 将button_layout添加到self.left_frame中
self.menu_frame.setLayout(button_layout)
# 将self.left_frame添加到left_layout中
left_layout.addWidget(self.menu_frame)
left_layout.addLayout(setting_layout)
# 添加组件到右侧布局
address_line_layout = QHBoxLayout()
address_line_layout.addWidget(self.address_line)
address_line_layout.addWidget(self.export_image_button)
# 添加命令行输入框到右侧布局
frames_layout = QHBoxLayout() # H是水平布局,V是垂直布局
frames_layout.addWidget(self.left_frame)
frames_layout.addWidget(self.right_frame)
# 右侧布局
right_layout.addLayout(address_line_layout)
right_layout.addLayout(frames_layout)
right_layout.addWidget(self.textbox)
# 添加布局到主布局
main_layout.addLayout(left_layout, 1)
main_layout.addLayout(right_layout, 2)
# 设置窗口标题和大小
main_window.setWindowTitle("YOLOv5 目标检测")
main_window.setGeometry(500, 500, 1100, 500)
return main_window