SystemError: <class 'cv2.CascadeClassifier'> returned a result with an exception set

Viewed 20

I am new to OpenCV want to run simple code for face detection but facing the below issue.

this is my code:


import cv2

Create a CascadeClassifier object

face_cascade = cv2.CascadeClassifier('img/me.jpeg')

Reading the image as it is

img = cv2.imread('img/me.jpeg')

Reading the image as gray scale image

gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Search the co-ordinates of the image

faces = face_cascade.detectMultiScale(gray_img, scaleFactor=1.05, minNeighbors=5)

print(type(faces))
print(faces)

for x, y, w, h in faces:
    img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 3)

resized = cv2.resize(img, (int(img.shape[1]/2), int(img.shape[0])))

cv2.imshow("Gray", img)

cv2.waitKey(0)

cv2.destroyAllWindows()

this is the error:

cv2.error: OpenCV(4.6.0) /Users/xperience/actions-runner/_work/opencv-python/opencv-python/opencv/modules/core/src/persistence.cpp:692: error: (-5:Bad argument) Input file is invalid in function 'open'


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/----/face_detection.py", line 4, in <module>
    face_cascade = cv2.CascadeClassifier('img/me.jpeg')
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an exception set
0 Answers
Related