I created my own Haar Cascade Classifier for detecting cows. The code works perfectly fine for the available OpenCv xml files but shows the following error when I run it using the xml file that I created.
Traceback (most recent call last):
File "C:........\Haar Cascade\cow_detect_image.py", line 11, in < module >cows = cow_cascade.detectMultiScale(gray, 1.3, 5)
TypeError: Incorrect type of self (must be 'CascadeClassifier' or its derivative)
Here's the code:
import numpy as np
import cv2
cow_cascade = cv2.CascadeClassifier('cow.xml')
img = cv2.imread('Cow3.bmp')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cows = cow_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in cows:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
What is wrong and how can I fix this?