-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathface_rec.py
More file actions
35 lines (21 loc) · 872 Bytes
/
face_rec.py
File metadata and controls
35 lines (21 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from PIL import Image
import face_recognition
import numpy as np
import argparse
import cv2
# fetching the arguments and save in dictionary
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Enter path to the image")
args = vars(ap.parse_args())
# loading and converting the image into numpy array
image = cv2.imread(args["image"])
#find all the faces in the image
face_loc = face_recognition.face_locations(image)
#printing the nimber of itens in the array
print("I have found {} faces in this photo".format(len(face_loc)))
for face_loc in face_loc:
top, right, bot, left = face_loc
print("A face is located at pixel location Top:{}, Left:{}, Bottom:{}, Right:{}".format(top,left,right,bot))
face_image = image[top:bot, left:right]
pil_image = Image.fromarray(face_image)
pil_image.show()