import cv2
import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread(“Train/Jamie_Before.jpg”)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faced= cv2.CascadeClassifier(cv2.data.haarcascades +r’D:\oc\data science\9snapchat_filters\haarcascade_frontalface_alt.xml’)
eyed= cv2.CascadeClassifier(cv2.data.haarcascades +r’D:\oc\data science\9snapchat_filters\frontalEyes35x16XML.xml’)
#nosed= cv2.CascadeClassifier("./Nose18x15.xml")
faces = faced.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
eyes = eyed.detectMultiScale(gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
k = cv2.waitKey(0)
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord(‘s’): # wait for ‘s’ key to save and exit
cv2.imwrite(‘messigray.png’,img)
cv2.destroyAllWindows()
getting folllowing error
File “snap.py”, line 11, in
faces = faced.detectMultiScale(gray)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\objdetect\src\cascad
edetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClas
sifier::detectMultiScale’
