I am trying to make an car detector/classifier with cv2
i have a .xml
file i downloaded from github:
https://gist.github.com/199995/37e1e0af2bf8965e8058a9dfa3285bc6 and when ever i run my code i get
Traceback (most recent call last):
File "C:\Users\user1\Downloads\Stuff\Python\cascades\Car_classification.py", line 13, in <module>
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
and my code is:
import cv2
import numpy as np
cap = cv2.VideoCapture('car.jpg')
font = cv2.FONT_HERSHEY_TRIPLEX
harcascade = cv2.CascadeClassifier("cars.xml")
while True:
ret,frames = cap.read()
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
cars = harcascade.detectMultiScale(gray, 1.1 , 2)
for (x,y,w,h) in cars:
cv2.rectangle(frames,(x,y),(x+w,y+h),(255,0,0),2)
cv2.putText(frames,str("Car"),(x,y+h),font,1,255)
cv2.imshow('img',frames)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
My input image:
My output image:
It is a car but i don't think a tire is a car! so what am i doing wrong?