YOLOv8交通违规行为识别系统
一、系统架构与核心功能
1.1 系统架构
mermaid
graph TD
A[视频输入] --> B[YOLOv8目标检测]
B --> C[DeepSORT目标追踪]
C --> D[交通信号识别]
C --> E[行驶轨迹分析]
D & E --> F[违规行为判定]
F --> G[报警与证据保存]
1.2 支持的违规行为
- 闯红灯检测
- 逆向行驶检测
- 不按导向车道行驶
- 违停检测
- 超速检测
二、完整代码实现
python
import cv2
import numpy as np
from ultralytics import YOLO
from collections import defaultdict, deque
import time
import json
from shapely.geometry import LineString, Point
class TrafficViolationDetector:
def __init__(self, confi