I am trying to make a parking space detection system, I opened a question 2 days ago. It didn't work what ever I tried, I decided I start again with it. I have did alot of things to make this better, currently it only detects straight line, and I want to get this to detect parking spots. I wanted to know how can I do this?
I think there are some major problems with the method I am currently using
I try using a car haarcascade
to detect cars and not drawing the lines but it doesn't seem to work. This is all i tried, because i couldn't think of any other way of doing this
Code
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()
I am also really new to openCV