OpenCV-Python Error (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
Those files being in the same folder means nothing.
Relative paths are resolved relative to the current working directory, not the directory the script resides in.
Further, your code uses cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
which is likely an absolute path.
You should check if a file exists at that location.
Then... always error-check.
You are missing several error checks.
- Right after
classifier = cv2.CascadeClassifier...
you must check if that succeeded:
assert not classifier.empty()
That is likely the issue here. The violated assertion (error message) checked for this condition.
- Right after
vid = cv2.VideoCapture...
you must check if that succeeded:
assert vid.isOpened()
- After reading each frame (
ret, frame = vid.read()
), you must check if that succeeded:
if not ret: break
How to solve. error: (-215) !empty() in function detectMultiScale
That's because there is no such file in cv2.data.haarcascades as it can be seen here.
You should download the "haarcascade_hand.xml" from this project or any other repo that you have in mind, then provide the full path for this to work.
it should look like this
cascade_path = "fullpath_to_hand_cascade/haarcascade_hand.xml"
hand_cascade = cv2.CascadeClassifier(cascade_path)
Related Topics
Is Shared Readonly Data Copied to Different Processes for Multiprocessing
How to Automatically Install Required Packages from a Python Script as Necessary
How to Build 32Bit Python 2.6 on 64Bit Linux
Run a Linux System Command as a Superuser, Using a Python Script
Priority of the Logical Operators Not, And, or in Python
Negative Integer Division Surprising Result
Case Insensitive Regular Expression Without Re.Compile
How to Construct a Timedelta Object from a Simple String
How to Append a New Row to an Old CSV File in Python
How to Change Backends in Matplotlib/Python
Some Unix Commands Fail with "<Command> Not Found", When Executed Using Python Paramiko Exec_Command
How to Get Current Available Gpus in Tensorflow
Skip Rows During CSV Import Pandas
Python Operator Precedence of in and Comparison