cut out faces from photos in dir python

Solutions on MaxInterview for cut out faces from photos in dir python by the best coders in the world

showing results for - "cut out faces from photos in dir python"
Reginald
30 Apr 2019
1import cv2
2import sys
3
4imagePath = sys.argv[1]
5
6image = cv2.imread(imagePath)
7gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
8
9faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
10faces = faceCascade.detectMultiScale(
11    gray,
12    scaleFactor=1.3,
13    minNeighbors=3,
14    minSize=(30, 30)
15)
16
17print("[INFO] Found {0} Faces!".format(len(faces)))
18
19for (x, y, w, h) in faces:
20    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
21
22status = cv2.imwrite('faces_detected.jpg', image)
23print("[INFO] Image faces_detected.jpg written to filesystem: ", status)