opencv
configuration_error
ai_generated
true
cv2.error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
ID: opencv/cascade-classifier-empty
92%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 4 | active | — | — | — |
Root Cause
CascadeClassifier is empty because XML model file was not loaded. Wrong file path.
genericWorkarounds
-
95% success Use cv2.data.haarcascades for bundled cascades
cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
Sources: https://docs.opencv.org/4.x/
-
90% success Check if cascade loaded before using
if face_cascade.empty(): raise FileNotFoundError('Cascade not found') -
85% success Use absolute path via __file__
os.path.join(os.path.dirname(__file__), 'models', 'my_cascade.xml')
Dead Ends
Common approaches that don't work:
-
Download XML from random GitHub repo
72% fail
Third-party files may be incompatible. Use official OpenCV data files.
-
Use relative path assuming cwd is script location
80% fail
Python cwd is where you ran the command, not where the script lives