Leox
Leox

Reputation: 370

How to fix the openCV error with cv2.CascadeClassifier?

I am creating a car recognition program.

import cv2

import numpy as np 

car_cascade = cv2.CascadeClassifier('cars.xml')

This error is being thrown:

cv2.error: OpenCV(4.0.0) C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\persistence.cpp:722: error: (-49:Unknown error code -49) Input file is empty in function 'cv::FileStorage::Impl::open'

Traceback (most recent call last):
  File "C:\Users\OneDrive\Python\test.py", line 2, in <module>
    face_cascade = cv2.CascadeClassifier('cars.xml')
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set

I have cars.xml in the working directory so that shouldn't be an issue

Upvotes: 2

Views: 2888

Answers (1)

DrewEdgette
DrewEdgette

Reputation: 56

This is happening because the .xml file exists, but the contents are corrupt. I just spent way too long trying to figure this out only to realize that I didn't download the xml file properly. If you are 100% sure the file is correct, god help you.

Upvotes: 4

Related Questions