import cv2 cascPath=r"C:\\Users\86138\\anaconda3\\envs\\jupy\\Lib\site-packages\\cv2\data\\haarcascade_frontalface_alt2.xml" faceCascade=cv2.CascadeClassifier(cascPath) cap=cv2.VideoCapture(0) while(True): ret,img=cap.read() faces=faceCascade.detectMultiScale(img,1.2,2,cv2.CASCADE_SCALE_IMAGE,(20,20)) for (x,y,w,h) in faces: img=cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) cv2.imshow(u"Detect faces",img) key=cv2.waitKey(1) if key&0xFF==ord('q') or key==27: break cv2.destroyAllWindows() cap.release()