Created
December 11, 2020 13:26
-
-
Save l4rz/c2ced9ebdc7e281d5488c04128071bc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mtcnn import MTCNN | |
detector = MTCNN() | |
data = detector.detect_faces(cv.cvtColor(imq, cv.COLOR_BGR2RGB)) | |
box = data[0]['box'] | |
keypoints = data[0]['keypoints'] | |
# first of all, eyes Y must be within certain % of face height | |
f_height = int(box[3] / 0.3 ) # height in px | |
eye1_y = int(keypoints['left_eye'][1] / 0.3) | |
eye2_y = int(keypoints['right_eye'][1] / 0.3 ) | |
eyes_y_delta = abs(eye1_y - eye2_y) | |
eyes_v_delta_percent = int( (eyes_y_delta / f_height) * 100) | |
# then, eyes X must be centerline-symmetric | |
eye1_x = int(keypoints['left_eye'][0] / 0.3) | |
eye2_x = int(keypoints['right_eye'][0] / 0.3 ) | |
centerline_x = int(box[0] / 0.3 ) + int ( int(box[2] / 0.3 ) /2) | |
eye1_offset = centerline_x - eye1_x | |
eye2_offset = eye2_x - centerline_x | |
delta_offset = int(abs(eye1_offset - eye2_offset) / ((eye1_offset + eye2_offset) / 2) * 100) | |
if eyes_v_delta_percent < 10 and delta_offset < 90: | |
# save image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment