Python基于YOLOv5的闯红灯检测系统(完整源码&UI操作界面&部署教程)
2023-09-14 09:15:12 时间
1.项目展示
2.视频演示
[项目分享]Python基于YOLOv5的闯红灯检测系统(完整源码&UI操作界面&部署教程)_哔哩哔哩_bilibili
3.红绿灯检测
交通信号灯的检测与识别是无人驾驶与辅助驾驶必不可少的一部分,其识别精度直接关乎智能驾驶的安全。一般而言,在实际的道路场景中采集的交通信号灯图像具有复杂的背景,且感兴趣的信号灯区域只占很少的一部分。针对这些难点,国内外的众多研究者提出了相应的解决方案。总的来说,大多基于传统的图像处理方法;但目前也有用强学习能力的卷积神经网络去进行识别,但这类方法往往需要大量的训练样本避免过拟合的风险。截至目前的大多数方法都是在各种颜色空间中利用信号灯颜色的先验进行分割得到兴趣区域,然后再通过信号灯所特有的形状特征和角点特征等进行进一步的判定。比如,Masako Omachi等人提出在RGB色彩空间分割交通信号灯,使用HOUGH变换检测分割出的信号灯所在的圆形区域;徐成等提出在Lab色彩空间分割交通信号灯,使用模板匹配的方法识别交通信号灯的状态;谷明琴等则在HSV色彩空间中使用颜色直方图统计图像的H分量,确定交通信号灯的类型。本项目将基于传统的图像处理算法来进行交通信号灯的识别,重点介绍核心技术。
4.红绿灯检测代码实现
import cv2
import random
import numpy as np
from enum import Enum
from detectColor import detectColor
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
class TLState(Enum):
red = 1
yellow = 2
green = 3
red_yellowArrow = 4
red_greenArrow = 5
green_yellowArrow = 6
green_greenArrow = 7
redArrow = 8
yellowArrow = 9
greenArrow = 10
flashingYellowArrow = 11
class TLType(Enum):
regular = 0
five_lights = 1
four_lights = 2
def imgResize(image, height, inter = cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
r = height / float(h)
dim = (int(w * r), height)
# resize the image
resized = cv2.resize(image, dim, interpolation = inter)
# return the resized image
return resized
def detectState(image, TLType):
image = imgResize(image, 200)
(height, width) = image.shape[:2]
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 霍夫圆环检测
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=15,maxRadius=30)
overallState = 0
stateArrow = 0
stateSolid = 0
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
if i[1] < i[2]:
i[1] = i[2]
roi = image[(i[1]-i[2]):(i[1]+i[2]),(i[0]-i[2]):(i[0]+i[2])]
color = detectColor(roi)
if color > 0:
if TLType == 1 and i[0] < width/2 and i[1] > height/3:
stateArrow = color
elif TLType == 2:
stateArrow = color
if i[1] > height/2 and i[1] < height/4*3:
stateArrow = color + 2
else:
stateSolid = color
if TLType == 1:
overallState = stateArrow + stateSolid + 1
elif TLType == 2:
overallState = stateArrow + 7
else:
overallState = stateSolid
return overallState
def plot_light_result(images):
for i, image in enumerate(images):
plt.subplot(1, len(images), i+1)
lena = mpimg.imread(image)
label = TLState(detectState(cv2.imread(image),TLType.regular.value)).name
plt.title(label)
plt.imshow(lena)
plt.show()
light_path = ["images/red.jpg","images/green.png", "images/yellow.png"]
random.shuffle(light_path)
plot_light_result(light_path)
def plot_arrow_result(images):
for i, image in enumerate(images):
plt.subplot(1, len(images), i+1)
lena = mpimg.imread(image)
label = TLState(detectState(cv2.imread(image),TLType.five_lights.value)).name
plt.title(label)
plt.imshow(imgResize(lena, 200))
plt.show()
arrow_path = ["images/red_greenarrow.png", "images/red_yellowarrow.png"]
random.shuffle(arrow_path)
plot_arrow_result(arrow_path)
6.项目整合
7.完整源码&环境部署视频教程&自定义UI界面:
百度面包多搜索标题名即可下载源码
8.参考文献
[1]张光旭.非理想条件下视频序列人脸识别算法研究与实现[D].河北科技大学,2019,.
[2]白雪.人工智能技术在智慧交通领域的应用研究[J].产业与科技论坛,2019,(10):49-50.
[3]华佳峰.吴昌成.袁晓君.行人闯红灯治理措施及建议[J].中国公共安全(学术版),2019,(4):86-88.
[4]韩玉鹏.阎春利.杨淇.李昕.徐琳琳.罗晓亮.道路交叉口3D光屏信号装置研究[J].山西建筑,2019,(9):131-132.
相关文章
- Python源码保护[通俗易懂]
- 入门Python,看完这篇就行了!
- 【python教程入门学习】PyCharm下载和安装教程(包含配置Python解释器)
- Python进阶33-Django cookie和session
- python详细安装教程环境配置_Python配置环境
- pycharm配置python运行环境_C中调用Python
- python整除和取余写法_Python的整除和取余[通俗易懂]
- python之多线程
- python教程:用简单的Python编写Web应用程序
- Python元组_python元组的定义方式
- 简述Python特点_python优缺点
- python浪漫表白源码(附带详细教程)_python网站开发实例
- python 路径管理以及常见报错
- 【测试开发】python系列教程:第一个Python程序
- 毕设必备!Python智慧教室:考试作弊系统、动态点名等功能
- 关于python中lambda函数的描述_Python全局变量
- Q学习(Q-learning)入门小例子及python实现
- 【测试开发】python系列教程:Python数据类型转换
- 【测试开发】python系列教程:Python 推导式
- 以蛇形模式打印矩阵的Python程序
- python-Python与PostgreSQL数据库-使用Python执行PostgreSQL查询(一)
- Python jiba 分词详解程序员
- python实现堆排序算法代码详解编程语言
- 提升Linux环境:升级Python(linux升级python)
- 安装Python MySQL驱动之快速指南(python安装mysql驱动)
- 使用Python连接SQL Server数据库(python连接sqlserver数据库)
- Python如何连接PostgreSQL数据库?(python连接postgresql)
- Python实现Oracle数据库连接(python连接oracle数据库)
- 从 Python 连接到 MySQL:实现更多强大的数据库应用(python和mysql)