OpenCV detecting hundreds of cars in footage with one car

247 Views Asked by At

I've written a very simple script for detecting cars when given footage:

cap = cv.VideoCapture(1)
car_cascade = cv.CascadeClassifier('assets/cars.xml')


while True:
    ret, frame = cap.read()

    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

    cars = car_cascade.detectMultiScale(gray, 1.1, 1)

    for (x, y, w, h) in cars:
        cv.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)


    # Display the resulting frame
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()

I'm using the following file for my cars.xml: https://github.com/Aman-Preet-Singh-Gulati/Vehicle-count-detect/blob/main/Required%20Files/cars.xml. I've seen several projects that utilize this same Cascade file as well.

My problem is that when I spin up the video I see a screen like this, where hundreds of elements in the video are categorized as "cars" by the detectMultiScale function. I've been struggling to find anything on why this might be occuring. The white blobs are sensitive information I drew over

0

There are 0 best solutions below