0

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

Jet.B.Pope
  • 642
  • 1
  • 5
  • 25
  • probably bad training data (very few images, badly labeled), or [the data is for the **backsides** of cars only](https://github.com/andrewssobral/vehicle_detection_haarcascades). it's a random github repo by a random person. don't trust it to be any good. – Christoph Rackwitz Apr 06 '22 at 22:51
  • That was my initial thought, but all of the main articles and tutorials on car recognition utilize this same file. It's not necessarily all pulled from this repo, but it's the same file being circulated around. I think I'm just going to create my own tbh and hopefully it'll turn out half-decent. – Jet.B.Pope Apr 06 '22 at 22:55

0 Answers0