赞
踩
当设计一个结合了 YOLOv5 目标检测、单目测距与速度测量以及 PyQt 界面的毕业设计时,需要考虑以下几个方面的具体细节:
YOLOv5 目标检测:
单目测距与速度测量:
PyQt 界面设计:
图片输入:
#qq-1309399183
import cv2
img = cv2.imread("image.jpg")
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel, QApplication
import sys
app = QApplication(sys.argv)
label = QLabel()
pixmap = QPixmap.fromImage(img.data, img.shape[1], img.shape[0], QImage.Format_RGB888)
label.setPixmap(pixmap)
label.show()
sys.exit(app.exec_())
视频输入:
import cv2
cap = cv2.VideoCapture("video.avi")
import cv2
cap = cv2.VideoCapture("http://xxx.xxx.xxx.xxx:xxxx/xxx.m3u8")
from PyQt5.QtGui import QImage
import sys
while True:
ret, frame = cap.read()
if not ret:
break
img = QImage(frame.data, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
label.setPixmap(QPixmap.fromImage(img))
QApplication.processEvents()
摄像头输入:
import cv2
cap = cv2.VideoCapture(0)
from PyQt5.QtCore import QTimer
import sys
def update():
ret, frame = cap.read()
if not ret:
return
img = QImage(frame.data, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
label.setPixmap(QPixmap.fromImage(img))
timer = QTimer()
timer.timeout.connect(update)
timer.start(1000 // 30)
app.exec_()
YOLOv5 改进:
SE 注意力模块:
class Squeeze(nn.Module):
def forward(self, x):
return torch.squeeze(x.mean((2, 3)), dim=(-1, -2))
class Excitation(nn.Module):
def __init__(self, channels, reduction=16):
super(Excitation, self).__init__()
mid_channels = max(channels // reduction, 1)
self.fc1 = nn.Linear(channels, mid_channels)
self.fc2 = nn.Linear(mid_channels, channels)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
out = self.fc1(x)
out = self.relu(out)
out = self.fc2(out)
out = self.sigmoid(out)
out = out.unsqueeze(-1).unsqueeze(-1)
return x * out
class SE(nn.Module):
def __init__(self, channels, reduction=16):
super(SE, self).__init__()
self.squeeze = Squeeze()
self.excitation = Excitation(channels, reduction)
def forward(self, x):
out = self.squeeze(x)
out = self.excitation(out)
return out
基于 YOLOv5 的改进:
class Conv(nn.Module):
def __init__(self, ch_in, ch_out, k=1, s=1, p=None, g=1, act=True, se=False):
super(Conv, self).__init__()
self.conv = nn.Conv2d(ch_in, ch_out, kernel_size=k, stride=s, padding=p, groups=g, bias=False)
self.bn = nn.BatchNorm2d(ch_out)
self.act = nn.SiLU() if act else nn.Identity()
self.se = SE(ch_out) if se else nn.Identity()
def forward(self, x):
out = self.conv(x)
out = self.bn(out)
out = self.act(out)
out = self.se(out)
return out
通过细致设计和实施上述方案,可以打造一款功能完善、性能优越的毕业设计项目,展现出对目标检测与测量技术的深度理解和创新应用,为未来相关领域的研究和发展提供有益的参考和启示。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。