Skip to content

Instantly share code, notes, and snippets.

@iamatulsingh
Last active December 23, 2019 11:43
Show Gist options
  • Save iamatulsingh/94d18ff80d73fa599443f2ef1c1d4e97 to your computer and use it in GitHub Desktop.
Save iamatulsingh/94d18ff80d73fa599443f2ef1c1d4e97 to your computer and use it in GitHub Desktop.
face recognition model
def crop_face(filename, required_size=(224, 224)):
img = cv2.imread(filename)
detector = MTCNN()
results = detector.detect_faces(img)
x, y, width, height = results[0]['box']
face = img[y:y+height, x:x+width]
image = Image.fromarray(face)
image = image.resize(required_size)
face_array = np.asarray(image)
return face_array, face
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment