so basically I am writing a program in python using openCV that can detect cars and then turns the picture into a gray-scale image. However, it shows an error when I run the code.
This is the error
: line 19, in cars = car_tracker.detectMultiScale(black_n_white) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
Here is my code:
import cv2
#These are our images
img_file ='car.jpg'
#This will be the result of the algorithm after it is trained
classifier_file = 'car_detector.xml'
#create opencv image
img = cv2.imread(img_file)
#create a car classifier
car_tracker = cv2.CascadeClassifier(classifier_file)
#convert it to black and white first cuz it makes it 3x faster for the algorithm
black_n_white = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#detect cars
cars = car_tracker.detectMultiScale(black_n_white)
#display the image with car spotted
cv2.imshow('car detector', black_n_white)
#this makes it wait
cv2.waitKey()