YOLO和OpenCV的智能停车位检测系统

文章目录

  • YOLO和OpenCV的智能停车位检测系统 ️
  • 项目概述
  • ️ 核心功能
  • 演示效果
  • ️ 安装指南
  • 项目结构
  • 未来扩展计划

YOLO和OpenCV的智能停车位检测系统 ️

项目概述

本项目利用YOLO(You Only Look Once)目标检测算法和OpenCV图像处理库,实时检测并监控停车场内的车位状态。通过高精度的空位与占用车位识别,帮助优化停车场管理效率。

️ 核心功能

✅ 基于YOLOv4/YOLOv8的实时车位检测
✅ OpenCV图像处理技术
✅ 车辆边界框标注与目标检测
✅ 可自定义的停车区域映射
✅ 支持实时摄像头流与视频输入

演示效果

![Screenshot 2025-02-19 211822]

️ 安装指南

1️⃣ 进代码


cd Smart-Parking-Space-Detector-using-YOLO-and-OpenCV

2️⃣ 安装依赖库

pip install -r requirements.txt

3️⃣ 下载YOLO权重文件
从YOLO官网下载YOLOv4权重或使用预训练的YOLOv8模型,将权重文件放入models/目录。
4️⃣ 运行检测脚本

python detect_parking.py --source video.mp4

或使用摄像头实时检测:

python detect_parking.py --source 0
import cv2
import pickle
import numpy as np

try:
  with open(r"E:\Car_Parking_Space_Detector_YOLOv8-main\Car_Parking_Space_Detector_YOLOv8-main\Space_ROIs",
              'rb') as f:
      posList = pickle.load(f)
except FileNotFoundError:
    posList = []

polygon_points = []  # List to store points of the polygon

def mouseClick(event, x, y, flags, params):
    global polygon_points, posList

    if event == cv2.EVENT_LBUTTONDOWN:
        polygon_points.append((x, y))

        if len(polygon_points) == 4:
            posList.append(polygon_points.copy())
            with open('carParkPos', 'wb') as f:
                pickle.dump(posList, f)
            polygon_points = []

    elif event == cv2.EVENT_RBUTTONDOWN:
        for i, polygon in enumerate(posList):
            if cv2.pointPolygonTest(np.array(polygon, dtype=np.int32), (x, y), False) >= 0:
                posList.pop(i)
                with open('carParkPos', 'wb') as f:
                    pickle.dump(posList, f)
                break

while True:
    img = cv2.imread(r"E:\Car_Parking_Space_Detector_YOLOv8-main\Car_Parking_Space_Detector_YOLOv8-main\ROI_Reference.png")
    for polygon in posList:
        pts = np.array(polygon, np.int32)
        pts = pts.reshape((-1, 1, 2))
        cv2.polylines(img, [pts], True, (0, 0, 255), 2)

    for point in polygon_points:
        cv2.circle(img, point, 5, (0, 255, 0), -1)

    cv2.imshow("Image", img)
    cv2.setMouseCallback("Image", mouseClick)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

项目结构

 Smart-Parking-Space-Detector  
 ┣  models/              # YOLO模型权重文件  
 ┣  data/                # 停车场图像/视频数据  
 ┣  utils/               # 辅助功能函数  
 ┣  detect_parking.py    # 主检测脚本  
 ┣  requirements.txt     # 依赖库列表  
 ┣  README.md            # 项目文档

未来扩展计划

开发移动端应用提供便捷访问
接入云数据库存储停车统计信息 ☁️
集成车牌识别功能加强安保

你可能感兴趣的:(计算机视觉实战项目集合,YOLO,opencv,人工智能,计算机视觉,python,智能停车位检测)