摘 要
本文提出了一种基于图像处理的智能交通灯控制系统,旨在通过先进的图像处理技术优化交通灯的配时,以提高交通效率和减少拥堵。系统的核心硬件平台采用STM32微控制器,由图像采集模块、图像处理模块和电源模块三个主要部分组成。图像采集模块利用两个摄像头实时捕捉路口交通情况,而图像处理模块则基于树莓派搭载的OpenCV库进行图像的中值滤波、背景提取、更新以及背景差分算法处理。通过阈值分割,系统能够生成运动车辆的二值化前景图像。进一步地,系统采用改进的加权面积法从二值化图像中准确统计车流信息,包括车辆的存在与否及数量状态。综合各路口的车流信息,系统能够实现对红绿灯的最优配时。此外,电源模块确保了系统的稳定运行。为了验证系统的有效性,我们构建了实物模型并进行了功能测试,结果表明系统能够准确提取路口车辆信息,并在典型路况下实现合理的红绿灯配时。此外,系统还考虑了左转灯的设置,通过增加两个摄像头来监测四个方向的交通情况,以进一步提升系统的准确性和实用性。
关键词:智能交通灯控制系统;图像处理;STM32;OpenCV;车流统计
Abstract
This paper presents an intelligent traffic light control system based on image processing, aiming to optimize traffic light timing through advanced image processing techniques to improve traffic efficiency and reduce congestion. The core hardware platform of the system adopts STM 32 microcontroller, which is composed of three main parts: image acquisition module, image processing module and power supply module. The image acquisition module uses two cameras to capture the traffic situation at the intersection in real time, while the image processing module performs the median filter, background extraction, update and background difference algorithm processing based on the OpenCV library carried by Raspberry Pi. By thresholding, the system is able to generate a binary foreground image of the moving vehicle. Further, the system uses the improved weighted area method to accurately count the traffic flow information from the binarized image, including the presence or absence of vehicles and the quantity status. Integrating the traffic flow information of each intersection, the system can realize the optimal timing of the traffic lights. Furthermore, the power supply module ensures the stable operation of the system. To verify the effectiveness of the system, we constructed a mock-up and conducted functional tests, and the results show that the system can accurately extract vehicle information at the intersection and achieve reasonable traffic light timing in typical road conditions. In addition, the system also considers the setting of the left turn lamp, by adding two cameras to monitor the traffic situation in the four directions, in order to further improve the accuracy and practicality of the system.
Key words: intelligent traffic light control system; image processing; STM 32; OpenCV; traffic flow statistics
目 录
1 课题背景 2
1.1 概述 2
1.2 传统交通路口信号灯 3
1.3.1 国内研究现状 3
1.3.2 国外研究现状 4
1.3.3 目前主流方式 4
1.4 课题任务分析 5
2.1 视觉检测 7
2.1.1 树莓派 7
2.1.2 OpenCV 9
2.1.3 USB 摄像头 10
2.2 硬件控制技术 11
3 需求分析 15
3.1 可行性分析 15
3.1.1 技术可行性分析 15
3.1.2 经济可行性分析 15
3.1.3 社会可行性分析 16
3.2 功能性需求 16
3.2.2 交通灯控制 17
3.2.3 图像采集 17
3.2.4 图像处理算法 17
3.2.5 分析通过路口的需求 17
3.2 非功能性需求 18
3.3.1 环境需求 18
3.3.2 系统完善需求 18
4 概要设计 19
4.1 总体设计 19
4.1.2 交通灯控制 19
4.1.3 图像采集 20
4.1.4 图像处理 21
4.1.5 需求分析 22
5 详细设计 23
5.1 系统硬件控制设计 23
5.1.1 交通信号灯 23
5.1.2 紧急情况的中断 23
5.1.3 串口通信 24
5.1 视觉算法设计 24
5.1.1 图像采集 24
5.1.2 图像处理 25
5.1.3 数据统计与分析 27
6 系统测试 29
6.1 硬件模块测试 29
6.1.1 正常情况下 29
6.1.2 紧急情况下 31
6.1.3 改变路口车流量 32
6.2 动态识别模块测试 35
7 总结与展望 36


















