Snapchat filter

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’

Hey @jhashantanu52, this is probably due to ther reason that later versions of opencv doesn’t support the haarcascade file or the path you specified is incorrect.

If path specified by you is correct, than write this command in terminal,
pip install opencv-python==4.0.1.23

Hope this resolved your doubt. :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.