微信公众号:OpenCV开发者联盟
关注获取更多计算机视觉与深度学习知识
引言
文本输入框QEditLine
标签QLabel
按钮QPushButton
单选QRadioButton
复选QCheckBox
调节器QSpinBox
下拉选择QComboBox
多行文本QTextBrowser
水平布局QHBoxLayout
垂直布局QVBoxLayout
网格布局QGridLayout
人脸检测界面程序
https://www.bilibili.com/video/BV1hM4y1M7vQ/
1from PyQt5 import QtWidgets, QtCore, QtGui
2import sys
3import cv2 as cv
4
5
6class FaceDetectDemoPanel(QtWidgets.QWidget):
7 def __init__(self, parent=None):
8 super().__init__(parent)
9 # 文本标签
10 self.weight_file_path = QtWidgets.QLineEdit()
11 self.weight_file_path.setMinimumWidth(150)
12 self.weight_file_path.setEnabled(False)
13 self.weight_file_path.setText("D:/projects/face_detector/opencv_face_detector_uint8.pb")
14 self.config_file_path = QtWidgets.QLineEdit()
15 self.config_file_path.setMinimumWidth(150)
16 self.config_file_path.setEnabled(False)
17 self.config_file_path.setText("D:/projects/face_detector/opencv_face_detector.pbtxt")
18 self.weight_select_btn = QtWidgets.QPushButton("浏览...")
19 self.config_file_btn = QtWidgets.QPushButton("浏览...")
20 hbox_layout1 = QtWidgets.QHBoxLayout()
21 hbox_layout1.addWidget(QtWidgets.QLabel("权重:"))
22 hbox_layout1.addWidget(self.weight_file_path)
23 hbox_layout1.addWidget(self.weight_select_btn)
24 hbox_layout1.addWidget(QtWidgets.QLabel("配置:"))
25 hbox_layout1.addWidget(self.config_file_path)
26 hbox_layout1.addWidget(self.config_file_btn)
27
28 panel1 = QtWidgets.QGroupBox("模型")
29 panel1.setLayout(hbox_layout1)
30
31 self.spinbox1 = QtWidgets.QDoubleSpinBox()
32 self.spinbox1.setRange(0.0, 1.0)
33 self.spinbox1.setSingleStep(0.01)
34 self.spinbox1.setValue(0.25)
35 self.fps_chkbox = QtWidgets.QCheckBox("显示FPS")
36 self.score_chkbox = QtWidgets.QCheckBox("显示置信")
37 self.fps_chkbox.setChecked(True)
38 self.score_chkbox.setChecked(True)
39
40 hbox_layout2 = QtWidgets.QHBoxLayout()
41 hbox_layout2.addWidget(self.fps_chkbox)
42 hbox_layout2.addWidget(self.score_chkbox)
43 hbox_layout2.addWidget(QtWidgets.QLabel("置信阈值:"))
44 hbox_layout2.addWidget(self.spinbox1)
45
46 panel2 = QtWidgets.QGroupBox("参数与显示")
47 panel2.setLayout(hbox_layout2)
48
49 self.rbtn1 = QtWidgets.QRadioButton("图像")
50 self.rbtn2 = QtWidgets.QRadioButton("视频")
51 self.rbtn3 = QtWidgets.QRadioButton("WebCam")
52 self.rbtn1.setChecked(True)
53 self.image_file_path = QtWidgets.QLineEdit()
54 self.image_file_path.setEnabled(False)
55 self.browser_btn = QtWidgets.QPushButton("选择...")
56
57 hbox_layout3 = QtWidgets.QHBoxLayout()
58 hbox_layout3.addWidget(self.rbtn1)
59 hbox_layout3.addWidget(self.rbtn2)
60 hbox_layout3.addWidget(self.rbtn3)
61 hbox_layout3.addWidget(QtWidgets.QLabel("文件路径:"))
62 hbox_layout3.addWidget(self.image_file_path)
63 hbox_layout3.addWidget(self.browser_btn)
64
65 panel3 = QtWidgets.QGroupBox("数据源")
66 panel3.setLayout(hbox_layout3)
67
68 panel4 = QtWidgets.QWidget()
69 vbox_layout4 = QtWidgets.QVBoxLayout()
70 vbox_layout4.addWidget(panel1)
71 vbox_layout4.addWidget(panel2)
72 vbox_layout4.addWidget(panel3)
73 panel4.setLayout(vbox_layout4)
74
75 # 输入文本框
76 self.label = QtWidgets.QLabel()
77 pixmap = QtGui.QPixmap("images/16.jpg")
78 pix = pixmap.scaled(QtCore.QSize(620, 500), QtCore.Qt.KeepAspectRatio)
79 self.label.setPixmap(pix)
80 self.label.setAlignment(QtCore.Qt.AlignCenter)
81 self.label.setStyleSheet("background-color:black; color: green")
82
83 self.run_btn = QtWidgets.QPushButton("运行")
84 self.run_btn.setMaximumWidth(100)
85
86 # 添加到布局管理器中
87 vbox_layout = QtWidgets.QVBoxLayout()
88 vbox_layout.addWidget(panel4)
89 vbox_layout.addWidget(self.run_btn)
90 vbox_layout.addWidget(self.label)
91 vbox_layout.addStretch(1)
92
93 # 面板容器
94 self.setLayout(vbox_layout)
95
96 # setup listener
97 self.weight_select_btn.clicked.connect(self.on_weight_select)
98 self.config_file_btn.clicked.connect(self.on_config_select)
99 self.browser_btn.clicked.connect(self.on_image_select)
100
101 # setup listener
102 self.rbtn1.toggled.connect(self.on_select_changed)
103 self.rbtn2.toggled.connect(self.on_select_changed)
104 self.rbtn3.toggled.connect(self.on_select_changed)
105
106 self.run_btn.clicked.connect(self.on_face_detect)
总结
扫码关注
OpenCV开发者联盟,
专注各种语言的OpenCV开发教程分享
OpenCV周边开发技术应用!
扫码查看OpenCV+OpenVIO+Pytorch系统化学习路线图
推荐阅读
CV全栈开发者说 - 从传统算法到深度学习怎么修炼
2022入坑深度学习,我选择Pytorch框架!
Pytorch轻松实现经典视觉任务
教程推荐 | Pytorch框架CV开发-从入门到实战
OpenCV4 C++学习 必备基础语法知识三
OpenCV4 C++学习 必备基础语法知识二
OpenCV4.5.4 人脸检测+五点landmark新功能测试
OpenCV4.5.4人脸识别详解与代码演示
OpenCV二值图象分析之Blob分析找圆
OpenCV4.5.x DNN + YOLOv5 C++推理
OpenCV4.5.4 直接支持YOLOv5 6.1版本模型推理
OpenVINO2021.4+YOLOX目标检测模型部署测试
比YOLOv5还厉害的YOLOX来了,官方支持OpenVINO推理