今天给大家分享用pyqt5桌面小组件搭建一个检测系统,暂定为公共场合猫狗检测系统,检测算法为YOLOX。后续会更新YOLOv8+pyqt5教程
系统界面展示:

该系统可以进行图片检测,实时检测,视频检测
首先创建一个.py文件复制下面代码:
from PIL import Image
import numpy as np
import time
import os
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
import cv2
import sys
from PyQt5.QtWidgets import *
# from detect_qt5 import main_detect,my_lodelmodel
from demo import main
'''摄像头和视频实时检测界面'''
class Ui_MainWindow(QWidget):
def __init__(self, parent=None):
super(Ui_MainWindow, self).__init__(parent)
# self.face_recong = face.Recognition()
self.timer_camera1 = QtCore.QTimer()
self.timer_camera2 = QtCore.QTimer()
self.timer_camera3 = QtCore.QTimer()
self.timer_camera4 = QtCore.QTimer()
self.cap = cv2.VideoCapture()
self.CAM_NUM = 0
# self.slot_init()
self.__flag_work = 0
self.x = 0
self.count = 0
self.setWindowTitle("公共场合猫狗检测系统")
self.setWindowIcon(QIcon(os.getcwd() + '\\data\\source_image\\Detective.ico'))
self.setFixedSize(1600, 900)
self.yolo=main()
# self.my_model = my_lodelmodel()
self.button_open_camera = QPushButton(self)
self.button_open_camera.setText(u'打开摄像头')
self.button_open_camera.setStyleSheet('''
QPushButton
{text-align : center;
background-color : white;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
QPushButton:pressed
{text-align : center;
background-color : light gray;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
''')
self.button_open_camera.move(10, 40)
self.button_open_camera.clicked.connect(self.button_open_camera_click)
# self.button_open_camera.clicked.connect(self.button_open_camera_click1)
# btn.clicked.connect(self.openimage)
self.btn1 = QPushButton(self)
self.btn1.setText("检测摄像头")
self.btn1.setStyleSheet('''
QPushButton
{text-align : center;
background-color : white;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
QPushButton:pressed
{text-align : center;
background-color : light gray;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
''')
self.btn1.move(10, 80)
self.btn1.clicked.connect(self.button_open_camera_click1)
# print("QPushButton构建")
self.open_video = QPushButton(self)
self.open_video.setText("打开视频")
self.open_video.setStyleSheet('''
QPushButton
{text-align : center;
background-color : white;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
QPushButton:pressed
{text-align : center;
background-color : light gray;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
''')
self.open_video.move(10, 160)
self.open_video.clicked.connect(self.open_video_button)
print("QPushButton构建")
self.btn1 = QPushButton(self)
self.btn1.setText("检测视频文件")
self.btn1.setStyleSheet('''
QPushButton
{text-align : center;
background-color : white;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
QPushButton:pressed
{text-align : center;
background-color : light gray;
font: bold;
border-color: gray;
border-width: 2px;
border-radius: 10px;
padding: 6px;
height : 14px;
border-style: outset;
font : 14px;}
''')
self.btn1.move(10, 200)
self.btn1.clicked.connect(self.detect_video)
print("QPushButton构建")
# btn1.clicked.connect(self.detect())
# btn1.clicked.connect(self.button1_test)
# btn1.clicked.connect(self.detect())
# btn1.clicked.connect(self.button1_test)
btn2 = QPushButton(self)
btn2.setText("返回上一界面")
btn2.setStyleSheet('''
QPushButton
{text-align : center;
background-color : white;
font: bold;
border-color: gray;
bo

文章展示了如何使用PyQt5构建一个用户界面,结合YOLOX对象检测算法,实现对公共场合中猫狗的实时检测。用户可以选择开启摄像头或上传视频进行检测,检测结果会在界面上即时显示。系统还提供了图片检测功能,可检测单张图片中的猫狗。
最低0.47元/天 解锁文章
922

被折叠的 条评论
为什么被折叠?



