zhaoxin 2 weeks ago
commit 1929ab9b0d

@ -0,0 +1,46 @@
#coding:utf-8
import cv2
from ultralytics import YOLO
# 所需加载的模型目录
path = 'models/best.pt'
# Load the YOLOv8 model
model = YOLO(path)
ID = 0
while(ID<10):
cap = cv2.VideoCapture(ID)
# get a frame
ret, frame = cap.read()
if ret == False:
ID += 1
else:
print('摄像头ID:',ID)
break
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

@ -0,0 +1,37 @@
#coding:utf-8
import cv2
from ultralytics import YOLO
# 所需加载的模型目录
path = 'models/best.pt'
# 需要检测的图片地址
video_path = "TestFiles/1.mp4"
# Load the YOLOv8 model
model = YOLO(path)
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

@ -0,0 +1,222 @@
# encoding:utf-8
import cv2
from PyQt5.QtGui import QPixmap, QImage
import numpy as np
from PIL import Image,ImageDraw,ImageFont
import csv
import os
# fontC = ImageFont.truetype("Font/platech.ttf", 20, 0)
# 绘图展示
def cv_show(name,img):
cv2.imshow(name, img)
cv2.waitKey(0)
cv2.destroyAllWindows()
def drawRectBox(image, rect, addText, fontC, color):
"""
绘制矩形框与结果
:param image: 原始图像
:param rect: 矩形框坐标, int类型
:param addText: 类别名称
:param fontC: 字体
:return:
"""
# 绘制位置方框
cv2.rectangle(image, (rect[0], rect[1]),
(rect[2], rect[3]),
color, 2)
# 绘制字体背景框
cv2.rectangle(image, (rect[0] - 1, rect[1] - 25), (rect[0] + 60, rect[1]), color, -1, cv2.LINE_AA)
# 图片 添加的文字 位置 字体 字体大小 字体颜色 字体粗细
# cv2.putText(image, addText, (int(rect[0])+2, int(rect[1])-3), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
img = Image.fromarray(image)
draw = ImageDraw.Draw(img)
draw.text((rect[0]+2, rect[1]-27), addText, (255, 255, 255), font=fontC)
imagex = np.array(img)
return imagex
def img_cvread(path):
# 读取含中文名的图片文件
# img = cv2.imread(path)
img = cv2.imdecode(np.fromfile(path, dtype=np.uint8), cv2.IMREAD_COLOR)
return img
def draw_boxes(img, boxes):
for each in boxes:
x1 = each[0]
y1 = each[1]
x2 = each[2]
y2 = each[3]
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
return img
def cvimg_to_qpiximg(cvimg):
height, width, depth = cvimg.shape
cvimg = cv2.cvtColor(cvimg, cv2.COLOR_BGR2RGB)
qimg = QImage(cvimg.data, width, height, width * depth, QImage.Format_RGB888)
qpix_img = QPixmap(qimg)
return qpix_img
def save_video():
# VideoCapture方法是cv2库提供的读取视频方法
cap = cv2.VideoCapture('C:\\Users\\xxx\\Desktop\\sweet.mp4')
# 设置需要保存视频的格式“xvid”
# 该参数是MPEG-4编码类型文件名后缀为.avi
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# 设置视频帧频
fps = cap.get(cv2.CAP_PROP_FPS)
# 设置视频大小
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
# VideoWriter方法是cv2库提供的保存视频方法
# 按照设置的格式来out输出
out = cv2.VideoWriter('C:\\Users\\xxx\\Desktop\\out.avi', fourcc, fps, size)
# 确定视频打开并循环读取
while (cap.isOpened()):
# 逐帧读取ret返回布尔值
# 参数ret为True 或者False,代表有没有读取到图片
# frame表示截取到一帧的图片
ret, frame = cap.read()
if ret == True:
# 垂直翻转矩阵
frame = cv2.flip(frame, 0)
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# 释放资源
cap.release()
out.release()
# 关闭窗口
cv2.destroyAllWindows()
# 封装函数:图片上显示中文
def cv2AddChineseText(img, text, position, textColor=(0, 255, 0), textSize=50):
if (isinstance(img, np.ndarray)): # 判断是否OpenCV图片类型
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
# 创建一个可以在给定图像上绘图的对象
draw = ImageDraw.Draw(img)
# 字体的格式
fontStyle = ImageFont.truetype(
"simsun.ttc", textSize, encoding="utf-8")
# 绘制文本
draw.text(position, text, textColor, font=fontStyle)
# 转换回OpenCV格式
return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
def insert_rows(path, lines ,header):
"""
将n行数据写入csv文件
:param path:
:param lines:
:return:
"""
no_header = False
if not os.path.exists(path):
no_header = True
start_num = 1
else:
start_num = len(open(path).readlines())
csv_head = header
with open(path, 'a', newline='') as f:
csv_write = csv.writer(f)
if no_header:
csv_write.writerow(csv_head) # 写入表头
for each_list in lines:
# 添加序号
each_list = [start_num] + each_list
csv_write.writerow(each_list)
# 序号 + 1
start_num += 1
class Colors:
# 用于绘制不同颜色
def __init__(self):
"""Initialize colors as hex = matplotlib.colors.TABLEAU_COLORS.values()."""
hexs = ('FF3838', 'FF9D97', 'FF701F', 'FFB21D', 'CFD231', '48F90A', '92CC17', '3DDB86', '1A9334', '00D4BB',
'2C99A8', '00C2FF', '344593', '6473FF', '0018EC', '8438FF', '520085', 'CB38FF', 'FF95C8', 'FF37C7')
self.palette = [self.hex2rgb(f'#{c}') for c in hexs]
self.n = len(self.palette)
self.pose_palette = np.array([[255, 128, 0], [255, 153, 51], [255, 178, 102], [230, 230, 0], [255, 153, 255],
[153, 204, 255], [255, 102, 255], [255, 51, 255], [102, 178, 255], [51, 153, 255],
[255, 153, 153], [255, 102, 102], [255, 51, 51], [153, 255, 153], [102, 255, 102],
[51, 255, 51], [0, 255, 0], [0, 0, 255], [255, 0, 0], [255, 255, 255]],
dtype=np.uint8)
def __call__(self, i, bgr=False):
"""Converts hex color codes to rgb values."""
c = self.palette[int(i) % self.n]
return (c[2], c[1], c[0]) if bgr else c
@staticmethod
def hex2rgb(h): # rgb order (PIL)
return tuple(int(h[1 + i:1 + i + 2], 16) for i in (0, 2, 4))
def yolo_to_location(w,h,yolo_data):
# yolo文件转两点坐标注意画图坐标要转换成int格式
x_, y_, w_, h_ = yolo_data
x1 = int(w * x_ - 0.5 * w * w_)
x2 = int(w * x_ + 0.5 * w * w_)
y1 = int(h * y_ - 0.5 * h * h_)
y2 = int(h * y_ + 0.5 * h * h_)
# cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (255, 0, 0))
return [x1,y1,x2,y2]
def location_to_yolo(w, h, locations):
# x1,y1左上角坐标x2,y2右上角坐标
x1, y1, x2, y2 = locations
x_ = (x1 + x2) / 2 / w
x_ = float('%.5f' % x_)
y_ = (y1 + y2) / 2 / h
y_ = float('%.5f' % y_)
w_ = (x2 - x1) / w
w_ = float('%.5f' % w_)
h_ = (y2 - y1) / h
h_ = float('%.5f' % h_)
return [x_,y_,w_,h_]
def draw_yolo_data(img_path, yolo_file_path):
# 读取yolo标注数据并显示
img = cv2.imread(img_path)
h, w, _ = img.shape
print(img.shape)
# yolo标注数据文件名为786_rgb_0616.txt
with open(yolo_file_path, 'r') as f:
data = f.readlines()
for each in data:
temp = each.split()
# ['1', '0.43906', '0.52083', '0.34687', '0.15']
# YOLO转换为两点坐标x1, x2, y1, y2
x_, y_, w_, h_ = eval(temp[1]), eval(temp[2]), eval(temp[3]), eval(temp[4])
x1, y1, x2, y2 = yolo_to_location(w,h,[x_, y_, w_, h_])
# 画图验证框是否正确
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 0, 255))
cv2.imshow('windows', img)
cv2.waitKey(0)
if __name__ == '__main__':
img_path = 'TestFiles/1.jpg'
yolo_file_path = 'save_data/yolo_labels/1.txt'
draw_yolo_data(img_path, yolo_file_path)

@ -0,0 +1,21 @@
#coding:utf-8
from ultralytics import YOLO
import cv2
# 所需加载的模型目录
path = 'models/best.pt'
# 需要检测的图片地址
img_path = "TestFiles/test4.jpg"
# 加载预训练模型
# conf 0.25 object confidence threshold for detection
# iou 0.7 intersection over union (IoU) threshold for NMS
model = YOLO(path, task='detect')
# model = YOLO(path, task='detect',conf=0.5)
# 检测图片
results = model(img_path)
res = results[0].plot()
cv2.imshow("YOLOv8 Detection", res)
cv2.waitKey(0)

@ -0,0 +1,23 @@
#coding:utf-8
from ultralytics import YOLO
if __name__ == '__main__':
# 加载已训练的人脸模型
model = YOLO("runs/detect/train/weights/best.pt") # 指向你的模型路径
# 训练迷彩服类别
results = model.train(
data='datasets/micai/data.yaml', # 新的迷彩服数据集配置
epochs=10, # 微调不需要太多轮次
device=0,
batch=2, # 根据GPU内存调整
imgsz=640,
cache='disk',
workers=4,
pretrained=True, # 使用预训练权重
optimizer='Adam', # 对于小数据集Adam比SGD更稳定
lr0=0.001 # 较低的学习率,避免破坏预训练权重
)
# 导出为ONNX格式
success = model.export(format='onnx')

@ -0,0 +1,623 @@
# -*- coding: utf-8 -*-
import time
from PyQt5.QtWidgets import QApplication , QMainWindow, QFileDialog, \
QMessageBox,QWidget,QHeaderView,QTableWidgetItem, QAbstractItemView
import sys
import os
from PIL import ImageFont
from ultralytics import YOLO
sys.path.append('UIProgram')
from UIProgram.UiMain import Ui_MainWindow
import sys
from PyQt5.QtCore import QTimer, Qt, QThread, pyqtSignal,QCoreApplication
import detect_tools as tools
import cv2
import Config
from UIProgram.QssLoader import QSSLoader
from UIProgram.precess_bar import ProgressBar
import numpy as np
# import torch
class MainWindow(QMainWindow):
def __init__(self, parent=None):
# 调用父类 QMainWindow 的构造函数,初始化当前窗口实例
super(QMainWindow, self).__init__(parent)
# 创建 Ui_MainWindow 类的实例,该类用于管理界面元素
self.ui = Ui_MainWindow()
# 调用 setupUi 方法,将界面元素设置到当前窗口
self.ui.setupUi(self)
# 调用 initMain 方法,进行窗口的初始化操作
self.initMain()
# 调用 signalconnect 方法,连接界面元素的信号与相应的槽函数
self.signalconnect()
# 加载css渲染效果
# 指定 CSS 样式文件的路径
style_file = 'UIProgram/style.css'
# 调用 QSSLoader 类的 read_qss_file 方法,读取 CSS 样式文件内容
qssStyleSheet = QSSLoader.read_qss_file(style_file)
# 将读取到的 CSS 样式应用到当前窗口
self.setStyleSheet(qssStyleSheet)
def signalconnect(self):
self.ui.PicBtn.clicked.connect(self.open_img)
self.ui.comboBox.activated.connect(self.combox_change)
self.ui.VideoBtn.clicked.connect(self.vedio_show)
self.ui.CapBtn.clicked.connect(self.camera_show)
self.ui.SaveBtn.clicked.connect(self.save_detect_video)
self.ui.ExitBtn.clicked.connect(QCoreApplication.quit)
self.ui.FilesBtn.clicked.connect(self.detact_batch_imgs)
def initMain(self):
self.show_width = 770
self.show_height = 480
self.org_path = None
self.is_camera_open = False
self.cap = None
# self.device = 0 if torch.cuda.is_available() else 'cpu'
# 加载检测模型
self.model = YOLO(Config.model_path, task='detect')
self.model(np.zeros((48, 48, 3))) #预先加载推理模型
self.fontC = ImageFont.truetype("Font/platech.ttf", 25, 0)
# 用于绘制不同颜色矩形框
self.colors = tools.Colors()
# 更新视频图像
self.timer_camera = QTimer()
# 更新检测信息表格
# self.timer_info = QTimer()
# 保存视频
self.timer_save_video = QTimer()
# 表格
self.ui.tableWidget.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)
self.ui.tableWidget.verticalHeader().setDefaultSectionSize(40)
self.ui.tableWidget.setColumnWidth(0, 80) # 设置列宽
self.ui.tableWidget.setColumnWidth(1, 200)
self.ui.tableWidget.setColumnWidth(2, 150)
self.ui.tableWidget.setColumnWidth(3, 90)
self.ui.tableWidget.setColumnWidth(4, 230)
self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows) # 设置表格整行选中
self.ui.tableWidget.verticalHeader().setVisible(False) # 隐藏列标题
self.ui.tableWidget.setAlternatingRowColors(True) # 表格背景交替
def open_img(self):
if self.cap:
# 打开图片前关闭摄像头
self.video_stop()
self.is_camera_open = False
self.ui.CaplineEdit.setText('摄像头未开启')
self.cap = None
# 弹出的窗口名称:'打开图片'
# 默认打开的目录:'./'
# 只能打开.jpg与.gif结尾的图片文件
# file_path, _ = QFileDialog.getOpenFileName(self.ui.centralwidget, '打开图片', './', "Image files (*.jpg *.gif)")
file_path, _ = QFileDialog.getOpenFileName(None, '打开图片', './', "Image files (*.jpg *.jepg *.png)")
if not file_path:
return
self.ui.comboBox.setDisabled(False)
self.org_path = file_path
self.org_img = tools.img_cvread(self.org_path)
# 目标检测
t1 = time.time()
self.results = self.model(self.org_path)[0]
t2 = time.time()
take_time_str = '{:.3f} s'.format(t2 - t1)
self.ui.time_lb.setText(take_time_str)
location_list = self.results.boxes.xyxy.tolist()
self.location_list = [list(map(int, e)) for e in location_list]
cls_list = self.results.boxes.cls.tolist()
self.cls_list = [int(i) for i in cls_list]
self.conf_list = self.results.boxes.conf.tolist()
self.conf_list = ['%.2f %%' % (each*100) for each in self.conf_list]
# now_img = self.cv_img.copy()
# for loacation, type_id, conf in zip(self.location_list, self.cls_list, self.conf_list):
# type_id = int(type_id)
# color = self.colors(int(type_id), True)
# # cv2.rectangle(now_img, (int(x1), int(y1)), (int(x2), int(y2)), colors(int(type_id), True), 3)
# now_img = tools.drawRectBox(now_img, loacation, Config.CH_names[type_id], self.fontC, color)
now_img = self.results.plot()
self.draw_img = now_img
# 获取缩放后的图片尺寸
self.img_width, self.img_height = self.get_resize_size(now_img)
resize_cvimg = cv2.resize(now_img,(self.img_width, self.img_height))
pix_img = tools.cvimg_to_qpiximg(resize_cvimg)
self.ui.label_show.setPixmap(pix_img)
self.ui.label_show.setAlignment(Qt.AlignCenter)
# 设置路径显示
self.ui.PiclineEdit.setText(self.org_path)
# 目标数目
target_nums = len(self.cls_list)
self.ui.label_nums.setText(str(target_nums))
# 设置目标选择下拉框
choose_list = ['全部']
target_names = [Config.names[id]+ '_'+ str(index) for index,id in enumerate(self.cls_list)]
# object_list = sorted(set(self.cls_list))
# for each in object_list:
# choose_list.append(Config.CH_names[each])
choose_list = choose_list + target_names
self.ui.comboBox.clear()
self.ui.comboBox.addItems(choose_list)
if target_nums >= 1:
self.ui.type_lb.setText(Config.CH_names[self.cls_list[0]])
self.ui.label_conf.setText(str(self.conf_list[0]))
# 默认显示第一个目标框坐标
# 设置坐标位置值
self.ui.label_xmin.setText(str(self.location_list[0][0]))
self.ui.label_ymin.setText(str(self.location_list[0][1]))
self.ui.label_xmax.setText(str(self.location_list[0][2]))
self.ui.label_ymax.setText(str(self.location_list[0][3]))
else:
self.ui.type_lb.setText('')
self.ui.label_conf.setText('')
self.ui.label_xmin.setText('')
self.ui.label_ymin.setText('')
self.ui.label_xmax.setText('')
self.ui.label_ymax.setText('')
# # 删除表格所有行
self.ui.tableWidget.setRowCount(0)
self.ui.tableWidget.clearContents()
self.tabel_info_show(self.location_list, self.cls_list, self.conf_list,path=self.org_path)
def detact_batch_imgs(self):
if self.cap:
# 打开图片前关闭摄像头
self.video_stop()
self.is_camera_open = False
self.ui.CaplineEdit.setText('摄像头未开启')
self.cap = None
directory = QFileDialog.getExistingDirectory(self,
"选取文件夹",
"./") # 起始路径
if not directory:
return
self.org_path = directory
img_suffix = ['jpg','png','jpeg','bmp']
for file_name in os.listdir(directory):
full_path = os.path.join(directory,file_name)
if os.path.isfile(full_path) and file_name.split('.')[-1].lower() in img_suffix:
# self.ui.comboBox.setDisabled(False)
img_path = full_path
self.org_img = tools.img_cvread(img_path)
# 目标检测
t1 = time.time()
self.results = self.model(img_path)[0]
t2 = time.time()
take_time_str = '{:.3f} s'.format(t2 - t1)
self.ui.time_lb.setText(take_time_str)
location_list = self.results.boxes.xyxy.tolist()
self.location_list = [list(map(int, e)) for e in location_list]
cls_list = self.results.boxes.cls.tolist()
self.cls_list = [int(i) for i in cls_list]
self.conf_list = self.results.boxes.conf.tolist()
self.conf_list = ['%.2f %%' % (each * 100) for each in self.conf_list]
now_img = self.results.plot()
self.draw_img = now_img
# 获取缩放后的图片尺寸
self.img_width, self.img_height = self.get_resize_size(now_img)
resize_cvimg = cv2.resize(now_img, (self.img_width, self.img_height))
pix_img = tools.cvimg_to_qpiximg(resize_cvimg)
self.ui.label_show.setPixmap(pix_img)
self.ui.label_show.setAlignment(Qt.AlignCenter)
# 设置路径显示
self.ui.PiclineEdit.setText(img_path)
# 目标数目
target_nums = len(self.cls_list)
self.ui.label_nums.setText(str(target_nums))
# 设置目标选择下拉框
choose_list = ['全部']
target_names = [Config.names[id] + '_' + str(index) for index, id in enumerate(self.cls_list)]
choose_list = choose_list + target_names
self.ui.comboBox.clear()
self.ui.comboBox.addItems(choose_list)
if target_nums >= 1:
self.ui.type_lb.setText(Config.CH_names[self.cls_list[0]])
self.ui.label_conf.setText(str(self.conf_list[0]))
# 默认显示第一个目标框坐标
# 设置坐标位置值
self.ui.label_xmin.setText(str(self.location_list[0][0]))
self.ui.label_ymin.setText(str(self.location_list[0][1]))
self.ui.label_xmax.setText(str(self.location_list[0][2]))
self.ui.label_ymax.setText(str(self.location_list[0][3]))
else:
self.ui.type_lb.setText('')
self.ui.label_conf.setText('')
self.ui.label_xmin.setText('')
self.ui.label_ymin.setText('')
self.ui.label_xmax.setText('')
self.ui.label_ymax.setText('')
# # 删除表格所有行
# self.ui.tableWidget.setRowCount(0)
# self.ui.tableWidget.clearContents()
self.tabel_info_show(self.location_list, self.cls_list, self.conf_list, path=img_path)
self.ui.tableWidget.scrollToBottom()
QApplication.processEvents() #刷新页面
def draw_rect_and_tabel(self, results, img):
now_img = img.copy()
location_list = results.boxes.xyxy.tolist()
self.location_list = [list(map(int, e)) for e in location_list]
cls_list = results.boxes.cls.tolist()
self.cls_list = [int(i) for i in cls_list]
self.conf_list = results.boxes.conf.tolist()
self.conf_list = ['%.2f %%' % (each * 100) for each in self.conf_list]
for loacation, type_id, conf in zip(self.location_list, self.cls_list, self.conf_list):
type_id = int(type_id)
color = self.colors(int(type_id), True)
# cv2.rectangle(now_img, (int(x1), int(y1)), (int(x2), int(y2)), colors(int(type_id), True), 3)
now_img = tools.drawRectBox(now_img, loacation, Config.CH_names[type_id], self.fontC, color)
# 获取缩放后的图片尺寸
self.img_width, self.img_height = self.get_resize_size(now_img)
resize_cvimg = cv2.resize(now_img, (self.img_width, self.img_height))
pix_img = tools.cvimg_to_qpiximg(resize_cvimg)
self.ui.label_show.setPixmap(pix_img)
self.ui.label_show.setAlignment(Qt.AlignCenter)
# 设置路径显示
self.ui.PiclineEdit.setText(self.org_path)
# 目标数目
target_nums = len(self.cls_list)
self.ui.label_nums.setText(str(target_nums))
if target_nums >= 1:
self.ui.type_lb.setText(Config.CH_names[self.cls_list[0]])
self.ui.label_conf.setText(str(self.conf_list[0]))
self.ui.label_xmin.setText(str(self.location_list[0][0]))
self.ui.label_ymin.setText(str(self.location_list[0][1]))
self.ui.label_xmax.setText(str(self.location_list[0][2]))
self.ui.label_ymax.setText(str(self.location_list[0][3]))
else:
self.ui.type_lb.setText('')
self.ui.label_conf.setText('')
self.ui.label_xmin.setText('')
self.ui.label_ymin.setText('')
self.ui.label_xmax.setText('')
self.ui.label_ymax.setText('')
# 删除表格所有行
self.ui.tableWidget.setRowCount(0)
self.ui.tableWidget.clearContents()
self.tabel_info_show(self.location_list, self.cls_list, self.conf_list, path=self.org_path)
return now_img
def combox_change(self):
com_text = self.ui.comboBox.currentText()
if com_text == '全部':
cur_box = self.location_list
cur_img = self.results.plot()
self.ui.type_lb.setText(Config.CH_names[self.cls_list[0]])
self.ui.label_conf.setText(str(self.conf_list[0]))
else:
index = int(com_text.split('_')[-1])
cur_box = [self.location_list[index]]
cur_img = self.results[index].plot()
self.ui.type_lb.setText(Config.CH_names[self.cls_list[index]])
self.ui.label_conf.setText(str(self.conf_list[index]))
# 设置坐标位置值
self.ui.label_xmin.setText(str(cur_box[0][0]))
self.ui.label_ymin.setText(str(cur_box[0][1]))
self.ui.label_xmax.setText(str(cur_box[0][2]))
self.ui.label_ymax.setText(str(cur_box[0][3]))
resize_cvimg = cv2.resize(cur_img, (self.img_width, self.img_height))
pix_img = tools.cvimg_to_qpiximg(resize_cvimg)
self.ui.label_show.clear()
self.ui.label_show.setPixmap(pix_img)
self.ui.label_show.setAlignment(Qt.AlignCenter)
def get_video_path(self):
file_path, _ = QFileDialog.getOpenFileName(None, '打开视频', './', "Image files (*.avi *.mp4 *.jepg *.png)")
if not file_path:
return None
self.org_path = file_path
self.ui.VideolineEdit.setText(file_path)
return file_path
def video_start(self):
# 删除表格所有行
self.ui.tableWidget.setRowCount(0)
self.ui.tableWidget.clearContents()
# 清空下拉框
self.ui.comboBox.clear()
# 定时器开启,每隔一段时间,读取一帧
self.timer_camera.start(1)
self.timer_camera.timeout.connect(self.open_frame)
def tabel_info_show(self, locations, clses, confs, path=None):
path = path
for location, cls, conf in zip(locations, clses, confs):
row_count = self.ui.tableWidget.rowCount() # 返回当前行数(尾部)
self.ui.tableWidget.insertRow(row_count) # 尾部插入一行
item_id = QTableWidgetItem(str(row_count+1)) # 序号
item_id.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) # 设置文本居中
item_path = QTableWidgetItem(str(path)) # 路径
# item_path.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
item_cls = QTableWidgetItem(str(Config.CH_names[cls]))
item_cls.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) # 设置文本居中
item_conf = QTableWidgetItem(str(conf))
item_conf.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) # 设置文本居中
item_location = QTableWidgetItem(str(location)) # 目标框位置
# item_location.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) # 设置文本居中
self.ui.tableWidget.setItem(row_count, 0, item_id)
self.ui.tableWidget.setItem(row_count, 1, item_path)
self.ui.tableWidget.setItem(row_count, 2, item_cls)
self.ui.tableWidget.setItem(row_count, 3, item_conf)
self.ui.tableWidget.setItem(row_count, 4, item_location)
self.ui.tableWidget.scrollToBottom()
def video_stop(self):
self.cap.release()
self.timer_camera.stop()
# self.timer_info.stop()
def open_frame(self):
ret, now_img = self.cap.read()
if ret:
# 目标检测
t1 = time.time()
results = self.model(now_img)[0]
t2 = time.time()
take_time_str = '{:.3f} s'.format(t2 - t1)
self.ui.time_lb.setText(take_time_str)
location_list = results.boxes.xyxy.tolist()
self.location_list = [list(map(int, e)) for e in location_list]
cls_list = results.boxes.cls.tolist()
self.cls_list = [int(i) for i in cls_list]
self.conf_list = results.boxes.conf.tolist()
self.conf_list = ['%.2f %%' % (each * 100) for each in self.conf_list]
now_img = results.plot()
# 获取缩放后的图片尺寸
self.img_width, self.img_height = self.get_resize_size(now_img)
resize_cvimg = cv2.resize(now_img, (self.img_width, self.img_height))
pix_img = tools.cvimg_to_qpiximg(resize_cvimg)
self.ui.label_show.setPixmap(pix_img)
self.ui.label_show.setAlignment(Qt.AlignCenter)
# 目标数目
target_nums = len(self.cls_list)
self.ui.label_nums.setText(str(target_nums))
# 设置目标选择下拉框
choose_list = ['全部']
target_names = [Config.names[id] + '_' + str(index) for index, id in enumerate(self.cls_list)]
# object_list = sorted(set(self.cls_list))
# for each in object_list:
# choose_list.append(Config.CH_names[each])
choose_list = choose_list + target_names
self.ui.comboBox.clear()
self.ui.comboBox.addItems(choose_list)
if target_nums >= 1:
self.ui.type_lb.setText(Config.CH_names[self.cls_list[0]])
self.ui.label_conf.setText(str(self.conf_list[0]))
# 默认显示第一个目标框坐标
# 设置坐标位置值
self.ui.label_xmin.setText(str(self.location_list[0][0]))
self.ui.label_ymin.setText(str(self.location_list[0][1]))
self.ui.label_xmax.setText(str(self.location_list[0][2]))
self.ui.label_ymax.setText(str(self.location_list[0][3]))
else:
self.ui.type_lb.setText('')
self.ui.label_conf.setText('')
self.ui.label_xmin.setText('')
self.ui.label_ymin.setText('')
self.ui.label_xmax.setText('')
self.ui.label_ymax.setText('')
# 删除表格所有行
# self.ui.tableWidget.setRowCount(0)
# self.ui.tableWidget.clearContents()
self.tabel_info_show(self.location_list, self.cls_list, self.conf_list, path=self.org_path)
else:
self.cap.release()
self.timer_camera.stop()
def vedio_show(self):
if self.is_camera_open:
self.is_camera_open = False
self.ui.CaplineEdit.setText('摄像头未开启')
video_path = self.get_video_path()
if not video_path:
return None
self.cap = cv2.VideoCapture(video_path)
self.video_start()
self.ui.comboBox.setDisabled(True)
def camera_show(self):
self.is_camera_open = not self.is_camera_open
if self.is_camera_open:
self.ui.CaplineEdit.setText('摄像头开启')
self.cap = cv2.VideoCapture(0)
self.video_start()
self.ui.comboBox.setDisabled(True)
else:
self.ui.CaplineEdit.setText('摄像头未开启')
self.ui.label_show.setText('')
if self.cap:
self.cap.release()
cv2.destroyAllWindows()
self.ui.label_show.clear()
def get_resize_size(self, img):
_img = img.copy()
img_height, img_width , depth= _img.shape
ratio = img_width / img_height
if ratio >= self.show_width / self.show_height:
self.img_width = self.show_width
self.img_height = int(self.img_width / ratio)
else:
self.img_height = self.show_height
self.img_width = int(self.img_height * ratio)
return self.img_width, self.img_height
def save_detect_video(self):
if self.cap is None and not self.org_path:
QMessageBox.about(self, '提示', '当前没有可保存信息,请先打开图片或视频!')
return
if self.is_camera_open:
QMessageBox.about(self, '提示', '摄像头视频无法保存!')
return
if self.cap:
res = QMessageBox.information(self, '提示', '保存视频检测结果可能需要较长时间,请确认是否继续保存?',QMessageBox.Yes | QMessageBox.No , QMessageBox.Yes)
if res == QMessageBox.Yes:
self.video_stop()
com_text = self.ui.comboBox.currentText()
self.btn2Thread_object = btn2Thread(self.org_path, self.model, com_text)
self.btn2Thread_object.start()
self.btn2Thread_object.update_ui_signal.connect(self.update_process_bar)
else:
return
else:
if os.path.isfile(self.org_path):
fileName = os.path.basename(self.org_path)
name , end_name= fileName.rsplit(".",1)
save_name = name + '_detect_result.' + end_name
save_img_path = os.path.join(Config.save_path, save_name)
# 保存图片
cv2.imwrite(save_img_path, self.draw_img)
QMessageBox.about(self, '提示', '图片保存成功!\n文件路径:{}'.format(save_img_path))
else:
img_suffix = ['jpg', 'png', 'jpeg', 'bmp']
for file_name in os.listdir(self.org_path):
full_path = os.path.join(self.org_path, file_name)
if os.path.isfile(full_path) and file_name.split('.')[-1].lower() in img_suffix:
name, end_name = file_name.rsplit(".",1)
save_name = name + '_detect_result.' + end_name
save_img_path = os.path.join(Config.save_path, save_name)
results = self.model(full_path)[0]
now_img = results.plot()
# 保存图片
cv2.imwrite(save_img_path, now_img)
QMessageBox.about(self, '提示', '图片保存成功!\n文件路径:{}'.format(Config.save_path))
def update_process_bar(self,cur_num, total):
if cur_num == 1:
self.progress_bar = ProgressBar(self)
self.progress_bar.show()
if cur_num >= total:
self.progress_bar.close()
QMessageBox.about(self, '提示', '视频保存成功!\n文件在{}目录下'.format(Config.save_path))
return
if self.progress_bar.isVisible() is False:
# 点击取消保存时,终止进程
self.btn2Thread_object.stop()
return
value = int(cur_num / total *100)
self.progress_bar.setValue(cur_num, total, value)
QApplication.processEvents()
class btn2Thread(QThread):
"""
进行检测后的视频保存
"""
# 声明一个信号
update_ui_signal = pyqtSignal(int,int)
def __init__(self, path, model, com_text):
super(btn2Thread, self).__init__()
self.org_path = path
self.model = model
self.com_text = com_text
# 用于绘制不同颜色矩形框
self.colors = tools.Colors()
self.is_running = True # 标志位,表示线程是否正在运行
def run(self):
# VideoCapture方法是cv2库提供的读取视频方法
cap = cv2.VideoCapture(self.org_path)
# 设置需要保存视频的格式“xvid”
# 该参数是MPEG-4编码类型文件名后缀为.avi
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# 设置视频帧频
fps = cap.get(cv2.CAP_PROP_FPS)
# 设置视频大小
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
# VideoWriter方法是cv2库提供的保存视频方法
# 按照设置的格式来out输出
fileName = os.path.basename(self.org_path)
name, end_name = fileName.split('.')
save_name = name + '_detect_result.avi'
save_video_path = os.path.join(Config.save_path, save_name)
out = cv2.VideoWriter(save_video_path, fourcc, fps, size)
prop = cv2.CAP_PROP_FRAME_COUNT
total = int(cap.get(prop))
print("[INFO] 视频总帧数:{}".format(total))
cur_num = 0
# 确定视频打开并循环读取
while (cap.isOpened() and self.is_running):
cur_num += 1
print('当前第{}帧,总帧数{}'.format(cur_num, total))
# 逐帧读取ret返回布尔值
# 参数ret为True 或者False,代表有没有读取到图片
# frame表示截取到一帧的图片
ret, frame = cap.read()
if ret == True:
# 检测
results = self.model(frame)[0]
frame = results.plot()
out.write(frame)
self.update_ui_signal.emit(cur_num, total)
else:
break
# 释放资源
cap.release()
out.release()
def stop(self):
self.is_running = False
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec_())

@ -0,0 +1,8 @@
class QSSLoader:
def __init__(self):
pass
@staticmethod
def read_qss_file(qss_file_name):
with open(qss_file_name, 'r', encoding='UTF-8') as file:
return file.read()

@ -0,0 +1,519 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'UiMain.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1250, 830)
MainWindow.setMinimumSize(QtCore.QSize(1250, 830))
MainWindow.setMaximumSize(QtCore.QSize(1250, 830))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/目标检测.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(10, 100, 791, 711))
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.frame_2 = QtWidgets.QFrame(self.frame)
self.frame_2.setGeometry(QtCore.QRect(10, 0, 771, 481))
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.label_show = QtWidgets.QLabel(self.frame_2)
self.label_show.setGeometry(QtCore.QRect(0, 0, 770, 480))
self.label_show.setMinimumSize(QtCore.QSize(770, 480))
self.label_show.setMaximumSize(QtCore.QSize(770, 480))
self.label_show.setStyleSheet("border-image: url(C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/face.png);")
self.label_show.setText("")
self.label_show.setObjectName("label_show")
self.frame_3 = QtWidgets.QFrame(self.frame)
self.frame_3.setGeometry(QtCore.QRect(10, 480, 771, 221))
self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.groupBox_3 = QtWidgets.QGroupBox(self.frame_3)
self.groupBox_3.setGeometry(QtCore.QRect(0, 10, 771, 221))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
self.groupBox_3.setFont(font)
self.groupBox_3.setObjectName("groupBox_3")
self.tableWidget = QtWidgets.QTableWidget(self.groupBox_3)
self.tableWidget.setGeometry(QtCore.QRect(10, 30, 751, 181))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(14)
self.tableWidget.setFont(font)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(5)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
self.frame_4 = QtWidgets.QFrame(self.centralwidget)
self.frame_4.setGeometry(QtCore.QRect(810, 100, 431, 711))
self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_4.setObjectName("frame_4")
self.groupBox = QtWidgets.QGroupBox(self.frame_4)
self.groupBox.setGeometry(QtCore.QRect(0, 0, 431, 171))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
self.groupBox.setFont(font)
self.groupBox.setObjectName("groupBox")
self.PiclineEdit = QtWidgets.QLineEdit(self.groupBox)
self.PiclineEdit.setGeometry(QtCore.QRect(70, 40, 311, 31))
self.PiclineEdit.setInputMask("")
self.PiclineEdit.setObjectName("PiclineEdit")
self.VideolineEdit = QtWidgets.QLineEdit(self.groupBox)
self.VideolineEdit.setGeometry(QtCore.QRect(70, 80, 311, 31))
self.VideolineEdit.setObjectName("VideolineEdit")
self.CapBtn = QtWidgets.QPushButton(self.groupBox)
self.CapBtn.setGeometry(QtCore.QRect(30, 120, 30, 30))
self.CapBtn.setStyleSheet("border-image: url(C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/camera.png);")
self.CapBtn.setText("")
self.CapBtn.setObjectName("CapBtn")
self.PicBtn = QtWidgets.QPushButton(self.groupBox)
self.PicBtn.setGeometry(QtCore.QRect(30, 40, 30, 30))
self.PicBtn.setStyleSheet("border-image: url(C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/img.png);")
self.PicBtn.setText("")
self.PicBtn.setObjectName("PicBtn")
self.VideoBtn = QtWidgets.QPushButton(self.groupBox)
self.VideoBtn.setGeometry(QtCore.QRect(30, 80, 30, 30))
self.VideoBtn.setStyleSheet("border-image: url(C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/video.png);")
self.VideoBtn.setText("")
self.VideoBtn.setObjectName("VideoBtn")
self.CaplineEdit = QtWidgets.QLineEdit(self.groupBox)
self.CaplineEdit.setGeometry(QtCore.QRect(70, 120, 311, 31))
self.CaplineEdit.setObjectName("CaplineEdit")
self.FilesBtn = QtWidgets.QPushButton(self.groupBox)
self.FilesBtn.setGeometry(QtCore.QRect(390, 40, 30, 30))
self.FilesBtn.setStyleSheet("border-image: url(C:/Users/pc/Desktop/YOLOv8face/UIProgram/ui_imgs/icons/folder.png);")
self.FilesBtn.setText("")
self.FilesBtn.setObjectName("FilesBtn")
self.groupBox_2 = QtWidgets.QGroupBox(self.frame_4)
self.groupBox_2.setGeometry(QtCore.QRect(0, 180, 431, 371))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
self.groupBox_2.setFont(font)
self.groupBox_2.setObjectName("groupBox_2")
self.frame_6 = QtWidgets.QFrame(self.groupBox_2)
self.frame_6.setGeometry(QtCore.QRect(0, 190, 431, 171))
self.frame_6.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_6.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_6.setObjectName("frame_6")
self.label_4 = QtWidgets.QLabel(self.frame_6)
self.label_4.setGeometry(QtCore.QRect(10, 10, 131, 41))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
self.label_4.setFont(font)
self.label_4.setStyleSheet("")
self.label_4.setObjectName("label_4")
self.layoutWidget = QtWidgets.QWidget(self.frame_6)
self.layoutWidget.setGeometry(QtCore.QRect(20, 60, 161, 37))
self.layoutWidget.setObjectName("layoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_6 = QtWidgets.QLabel(self.layoutWidget)
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
font.setBold(False)
font.setWeight(50)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.horizontalLayout.addWidget(self.label_6)
self.label_xmin = QtWidgets.QLabel(self.layoutWidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_xmin.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_xmin.setFont(font)
self.label_xmin.setText("")
self.label_xmin.setObjectName("label_xmin")
self.horizontalLayout.addWidget(self.label_xmin)
self.layoutWidget1 = QtWidgets.QWidget(self.frame_6)
self.layoutWidget1.setGeometry(QtCore.QRect(210, 60, 161, 37))
self.layoutWidget1.setObjectName("layoutWidget1")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget1)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_8 = QtWidgets.QLabel(self.layoutWidget1)
self.label_8.setObjectName("label_8")
self.horizontalLayout_2.addWidget(self.label_8)
self.label_ymin = QtWidgets.QLabel(self.layoutWidget1)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_ymin.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_ymin.setFont(font)
self.label_ymin.setText("")
self.label_ymin.setObjectName("label_ymin")
self.horizontalLayout_2.addWidget(self.label_ymin)
self.layoutWidget2 = QtWidgets.QWidget(self.frame_6)
self.layoutWidget2.setGeometry(QtCore.QRect(20, 120, 161, 37))
self.layoutWidget2.setObjectName("layoutWidget2")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget2)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_7 = QtWidgets.QLabel(self.layoutWidget2)
self.label_7.setObjectName("label_7")
self.horizontalLayout_3.addWidget(self.label_7)
self.label_xmax = QtWidgets.QLabel(self.layoutWidget2)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_xmax.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_xmax.setFont(font)
self.label_xmax.setText("")
self.label_xmax.setObjectName("label_xmax")
self.horizontalLayout_3.addWidget(self.label_xmax)
self.layoutWidget3 = QtWidgets.QWidget(self.frame_6)
self.layoutWidget3.setGeometry(QtCore.QRect(210, 120, 161, 37))
self.layoutWidget3.setObjectName("layoutWidget3")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget3)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_9 = QtWidgets.QLabel(self.layoutWidget3)
self.label_9.setObjectName("label_9")
self.horizontalLayout_4.addWidget(self.label_9)
self.label_ymax = QtWidgets.QLabel(self.layoutWidget3)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_ymax.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_ymax.setFont(font)
self.label_ymax.setText("")
self.label_ymax.setObjectName("label_ymax")
self.horizontalLayout_4.addWidget(self.label_ymax)
self.layoutWidget4 = QtWidgets.QWidget(self.groupBox_2)
self.layoutWidget4.setGeometry(QtCore.QRect(208, 40, 211, 37))
self.layoutWidget4.setObjectName("layoutWidget4")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget4)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.label = QtWidgets.QLabel(self.layoutWidget4)
self.label.setObjectName("label")
self.horizontalLayout_5.addWidget(self.label)
self.label_nums = QtWidgets.QLabel(self.layoutWidget4)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.label_nums.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_nums.setFont(font)
self.label_nums.setText("")
self.label_nums.setObjectName("label_nums")
self.horizontalLayout_5.addWidget(self.label_nums)
self.layoutWidget5 = QtWidgets.QWidget(self.groupBox_2)
self.layoutWidget5.setGeometry(QtCore.QRect(10, 90, 291, 38))
self.layoutWidget5.setObjectName("layoutWidget5")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget5)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.label_5 = QtWidgets.QLabel(self.layoutWidget5)
self.label_5.setObjectName("label_5")
self.horizontalLayout_6.addWidget(self.label_5)
self.comboBox = QtWidgets.QComboBox(self.layoutWidget5)
self.comboBox.setObjectName("comboBox")
self.horizontalLayout_6.addWidget(self.comboBox)
self.layoutWidget_2 = QtWidgets.QWidget(self.groupBox_2)
self.layoutWidget_2.setGeometry(QtCore.QRect(10, 40, 171, 37))
self.layoutWidget_2.setObjectName("layoutWidget_2")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_2)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.label_10 = QtWidgets.QLabel(self.layoutWidget_2)
self.label_10.setObjectName("label_10")
self.horizontalLayout_7.addWidget(self.label_10)
self.time_lb = QtWidgets.QLabel(self.layoutWidget_2)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.time_lb.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.time_lb.setFont(font)
self.time_lb.setText("")
self.time_lb.setObjectName("time_lb")
self.horizontalLayout_7.addWidget(self.time_lb)
self.layoutWidget6 = QtWidgets.QWidget(self.groupBox_2)
self.layoutWidget6.setGeometry(QtCore.QRect(210, 140, 191, 41))
self.layoutWidget6.setObjectName("layoutWidget6")
self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.layoutWidget6)
self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.label_11 = QtWidgets.QLabel(self.layoutWidget6)
self.label_11.setObjectName("label_11")
self.horizontalLayout_8.addWidget(self.label_11)
self.label_conf = QtWidgets.QLabel(self.layoutWidget6)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_conf.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_conf.setFont(font)
self.label_conf.setText("")
self.label_conf.setObjectName("label_conf")
self.horizontalLayout_8.addWidget(self.label_conf)
self.layoutWidget_3 = QtWidgets.QWidget(self.groupBox_2)
self.layoutWidget_3.setGeometry(QtCore.QRect(10, 140, 191, 41))
self.layoutWidget_3.setObjectName("layoutWidget_3")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.layoutWidget_3)
self.horizontalLayout_9.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.label_13 = QtWidgets.QLabel(self.layoutWidget_3)
self.label_13.setMaximumSize(QtCore.QSize(60, 16777215))
self.label_13.setObjectName("label_13")
self.horizontalLayout_9.addWidget(self.label_13)
self.type_lb = QtWidgets.QLabel(self.layoutWidget_3)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.type_lb.setPalette(palette)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.type_lb.setFont(font)
self.type_lb.setText("")
self.type_lb.setObjectName("type_lb")
self.horizontalLayout_9.addWidget(self.type_lb)
self.groupBox_4 = QtWidgets.QGroupBox(self.frame_4)
self.groupBox_4.setGeometry(QtCore.QRect(0, 560, 431, 141))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(16)
self.groupBox_4.setFont(font)
self.groupBox_4.setObjectName("groupBox_4")
self.SaveBtn = QtWidgets.QPushButton(self.groupBox_4)
self.SaveBtn.setGeometry(QtCore.QRect(30, 50, 151, 51))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/icons/ui_imgs/icons/保存.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.SaveBtn.setIcon(icon1)
self.SaveBtn.setIconSize(QtCore.QSize(30, 30))
self.SaveBtn.setObjectName("SaveBtn")
self.ExitBtn = QtWidgets.QPushButton(self.groupBox_4)
self.ExitBtn.setGeometry(QtCore.QRect(250, 50, 151, 51))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/icons/ui_imgs/icons/退出.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ExitBtn.setIcon(icon2)
self.ExitBtn.setIconSize(QtCore.QSize(30, 30))
self.ExitBtn.setObjectName("ExitBtn")
self.frame_5 = QtWidgets.QFrame(self.centralwidget)
self.frame_5.setGeometry(QtCore.QRect(10, 10, 1231, 91))
self.frame_5.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_5.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_5.setObjectName("frame_5")
self.label_3 = QtWidgets.QLabel(self.frame_5)
self.label_3.setGeometry(QtCore.QRect(240, 0, 811, 51))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(30)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_2 = QtWidgets.QLabel(self.frame_5)
self.label_2.setGeometry(QtCore.QRect(20, 60, 311, 21))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(14)
font.setUnderline(True)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_12 = QtWidgets.QLabel(self.frame_5)
self.label_12.setGeometry(QtCore.QRect(1070, 60, 131, 21))
font = QtGui.QFont()
font.setFamily("华文楷体")
font.setPointSize(14)
font.setUnderline(True)
self.label_12.setFont(font)
self.label_12.setObjectName("label_12")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "基于YOLOv8的人脸检测系统"))
self.groupBox_3.setTitle(_translate("MainWindow", "检测结果与位置信息"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "序号"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "文件路径"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "类别"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "置信度"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "坐标位置"))
self.groupBox.setTitle(_translate("MainWindow", "文件导入"))
self.PiclineEdit.setPlaceholderText(_translate("MainWindow", "请选择图片文件"))
self.VideolineEdit.setPlaceholderText(_translate("MainWindow", "请选择视频文件"))
self.CaplineEdit.setPlaceholderText(_translate("MainWindow", "摄像头未开启"))
self.groupBox_2.setTitle(_translate("MainWindow", "检测结果"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">目标位置:</span></p></body></html>"))
self.label_6.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">xmin:</span></p></body></html>"))
self.label_8.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">ymin</span></p></body></html>"))
self.label_7.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">xmax</span></p></body></html>"))
self.label_9.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">ymax</span></p></body></html>"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">目标数目:</span></p></body></html>"))
self.label_5.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">目标选择:</span></p></body></html>"))
self.label_10.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">用时:</span></p></body></html>"))
self.label_11.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">置信度:</span></p></body></html>"))
self.label_13.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">类型:</span></p></body></html>"))
self.groupBox_4.setTitle(_translate("MainWindow", "操作"))
self.SaveBtn.setText(_translate("MainWindow", "保存"))
self.ExitBtn.setText(_translate("MainWindow", "退出"))
self.label_3.setText(_translate("MainWindow", "基于YOLOv8的人脸检测系统"))

File diff suppressed because it is too large Load Diff

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# 进度条
from PyQt5.QtWidgets import QDialog, QLabel, QProgressBar, QPushButton, QVBoxLayout, QHBoxLayout
class ProgressBar(QDialog):
def __init__(self, parent=None):
super(ProgressBar, self).__init__(parent)
self.resize(350, 100)
self.setWindowTitle(self.tr("视频保存进度信息"))
self.TipLabel = QLabel(self.tr("当前帧/总帧数:0/0"))
self.FeatLabel = QLabel(self.tr("保存进度:"))
self.FeatProgressBar = QProgressBar(self)
self.FeatProgressBar.setMinimum(0)
self.FeatProgressBar.setMaximum(100) # 总进程换算为100
self.FeatProgressBar.setValue(0) # 进度条初始值为0
TipLayout = QHBoxLayout()
TipLayout.addWidget(self.TipLabel)
FeatLayout = QHBoxLayout()
FeatLayout.addWidget(self.FeatLabel)
FeatLayout.addWidget(self.FeatProgressBar)
self.cancelButton = QPushButton('取消保存', self)
buttonlayout = QHBoxLayout()
buttonlayout.addStretch(1)
buttonlayout.addWidget(self.cancelButton)
layout = QVBoxLayout()
layout.addLayout(FeatLayout)
layout.addLayout(TipLayout)
layout.addLayout(buttonlayout)
self.setLayout(layout)
self.cancelButton.clicked.connect(self.onCancel)
# self.show()
def setValue(self, start, end, progress):
self.TipLabel.setText(self.tr("当前帧/总帧数:" + " " + str(start) + "/" + str(end)))
self.FeatProgressBar.setValue(progress)
def onCancel(self, event):
self.close()

@ -0,0 +1,16 @@
QGroupBox {
border: 2px solid gray;
}
QPushButton#SaveBtn{color:black;
background-color:rgb(255, 130, 71);
border-radius:6px}
QPushButton#ExitBtn{color:black;
background-color:rgb(255, 130, 71);
border-radius:6px}
QPushButton:hover{color:red}
QPushButton:pressed{background-color:rgb(180,180,180);border: None;}
#MainWindow{border-image:url(UIProgram/ui_imgs/bg14.png)}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ui_sources.qrc'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.

@ -0,0 +1,13 @@
<RCC>
<qresource prefix="icons">
<file>ui_imgs/icons/目标检测.png</file>
<file>ui_imgs/icons/保存.png</file>
<file>ui_imgs/icons/退出.png</file>
<file>ui_imgs/huoyan.png</file>
<file>ui_imgs/icons/camera.png</file>
<file>ui_imgs/icons/folder.png</file>
<file>ui_imgs/icons/img.png</file>
<file>ui_imgs/icons/video.png</file>
</qresource>
<qresource prefix="bgs"/>
</RCC>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save