def test_face_landmarks_small_model(self): img = api.load_image_file(os.path.join(os.path.dirname(__file__), 'test_images', 'obama.jpg')) face_landmarks = api.face_landmarks(img, model="small") self.assertEqual( set(face_landmarks[0].keys()), set(['nose_tip', 'left_eye', 'right_eye'])) self.assertEqual(face_landmarks[0]['nose_tip'], [(496, 295)])
def test_face_landmarks(self): img = api.load_image_file(os.path.join(os.path.dirname(__file__), 'test_images', 'obama.jpg')) face_landmarks = api.face_landmarks(img) self.assertEqual( set(face_landmarks[0].keys()), set(['chin', 'left_eyebrow', 'right_eyebrow', 'nose_bridge', 'nose_tip', 'left_eye', 'right_eye', 'top_lip', 'bottom_lip'])) self.assertEqual( face_landmarks[0]['chin'], [(369, 220), (372, 254), (378, 289), (384, 322), (395, 353), (414, 382), (437, 407), (464, 424), (495, 428), (527, 420), (552, 399), (576, 372), (594, 344), (604, 314)])
def test_face_landmarks(self): img = api.load_image_file(os.path.join(os.path.dirname(__file__), 'test_images', 'obama.jpg')) face_landmarks = api.face_landmarks(img) self.assertEqual( set(face_landmarks[0].keys()), set(['chin', 'left_eyebrow', 'right_eyebrow', 'nose_bridge', 'nose_tip', 'left_eye', 'right_eye', 'top_lip', 'bottom_lip'])) self.assertEqual( face_landmarks[0]['chin'], [(369, 220), (372, 254), (378, 289), (384, 322), (395, 353), (414, 382), (437, 407), (464, 424), (495, 428), (527, 420), (552, 399), (576, 372), (594, 344), (604, 314), (610, 282), (613, 250), (615, 219)])
def save_keypoints_image(image_path, input_folder, output_folder, model): image = face_recognition.load_image_file(image_path) locations = face_recognition.face_locations(image, model=model) landmarks = face_recognition.face_landmarks(image, face_locations=locations, return_dict=False) num_faces = landmarks.shape[0] if num_faces == 0: return out_path = move_path(image_path, input_folder, output_folder) out_path = out_path.with_suffix('') out_path.mkdir(parents=True, exist_ok=True) for face_idx in range(num_faces): file_path = Path(out_path, F"{face_idx}.npy") landmark_array = landmarks[face_idx] np.save(file_path, landmark_array) print(F"finished image {out_path}")
def test_face_landmarks(self): img = api.load_image_file(os.path.join(os.path.dirname(__file__), "test_images", "obama.jpg")) face_landmarks = api.face_landmarks(img) assert set(face_landmarks[0].keys()) == set(['chin', 'left_eyebrow', 'right_eyebrow', 'nose_bridge', 'nose_tip', 'left_eye', 'right_eye', 'top_lip', 'bottom_lip']) assert face_landmarks[0]['chin'] == [(369, 220), (372, 254), (378, 289), (384, 322), (395, 353), (414, 382), (437, 407), (464, 424), (495, 428), (527, 420), (552, 399), (576, 372), (594, 344), (604, 314)]