You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于OpenCV的停车位检测系统开发求助:当前仅能检测直线

停车位检测系统开发问题

我正在开发一套停车位检测系统,两天前提问过但试了多种方法都没解决,决定重新开发。目前系统只能检测直线,我想实现停车位检测功能,怀疑现有方法有问题。尝试用car haarcascade检测车辆但没成功,想不到其他办法。我是OpenCV新手,附上当前代码。

原始图片:ORIGINAL IMAGE
当前效果:HOW IT WORKS RIGHT NOW

import cv2 as cv
import numpy as np

example_image = 'Data/Input/carPark.mp4'
car_cascade = cv.CascadeClassifier('Data/Input/haarcascade_car.xml')
img = cv.VideoCapture(example_image)

while img.isOpened():
    ret, frame = img.read()
    if not ret:
        break;
    img_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    cars = car_cascade.detectMultiScale(img_gray, 1.1, 3)
    img_blur = cv.GaussianBlur(img_gray, (5, 3), cv.BORDER_DEFAULT)
    edges = cv.Canny(img_blur, 150, 150)
    dilated = cv.dilate(edges, (5, 5), iterations=3)
    lines = cv.HoughLinesP(dilated, 1, np.pi / 180, threshold=100, minLineLength=100, maxLineGap=10)

    # Check if lines were found
    if lines is not None:
        if len(cars) == 0:
            for line in lines:
                x1, y1, x2, y2 = line[0]  # Access the points of the line
                cv.line(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)

    if cv.waitKey(1) & 0xFF == ord('q'):
        break
    cv.imshow("Image", frame)

img.release()
cv.destroyAllWindows()

内容的提问来源于stack exchange,提问作者Bhargav Raj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 02:12:27