Loading external haarcascade file OpenCV 4

asked 2020-05-06 23:19:51 -0500

I have OpenCV 4.2, and I'm trying to load a haarcascade file that I created.

The first code I tried was this:

fire_cascade = cv2.CascadeClassifier.load('fire_detection.xml')

Which gave me the following error:

fire_cascade = cv2.CascadeClassifier.load('fire_detection.xml') TypeError: descriptor 'load' requires a 'cv2.CascadeClassifier' object but received a 'str'

Then I tried this:

fire_cascade = cv2.CascadeClassifier('fire_detection.xml')

which gave me this error:

fire_cascade = cv2.CascadeClassifier('fire_detection.xml') SystemError: returned a result with an error set

And finally I tried this:

classifier = cv2.CascadeClassifier.empty()

fire_cascade = classifier.load("fire_detection.xml")

which gave me this error:

classifier = cv2.CascadeClassifier.empty() TypeError: descriptor 'empty' of 'cv2.CascadeClassifier' object needs an argument

How do I load this haarcascade file?

edit retag flag offensive close merge delete


Is your file in current directory?

supra56 gravatar imagesupra56 ( 2020-05-07 03:35:12 -0500 )edit

Try this:

fire_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'fire_detection.xml')
supra56 gravatar imagesupra56 ( 2020-05-07 03:52:16 -0500 )edit