import cv2 import sys def extract(face): imagePath = face image = cv2.imread(imagePath) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") faces = faceCascade.detectMultiScale( gray, scaleFactor=1.3, minNeighbors=3, minSize=(30, 30) ) # print("[INFO] Found {0} Faces.".format(len(faces))) for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) roi_color = image[y:y + h, x:x + w] name = str(w)+str(h)+'_faces.jpg' cv2.imwrite(str(w) + str(h) + '_faces.jpg', roi_color) return name # status = cv2.imwrite('faces_detected.jpg', image) # print("[INFO] Image faces_detected.jpg written to filesystem: ", status)