示例#1
0
    def grab_photos(image_dir: str):
        photos_names = []
        photos_encodings = []
        for root, dirs, files in os.walk(image_dir):
            for file in files:
                if file.endswith('png') or file.endswith('jpg'):
                    name_for_photo = root.split("\\")[1]
                    path = os.path.join(root, file)

                    image = face_recognition.load_image_file(path)
                    photos_encoding = face_recognition.face_encodings(image)[0]

                    photos_encodings.append(photos_encoding)
                    photos_names.append(name_for_photo)

        return photos_names, photos_encodings
from draft import face_recognition
import cv2
import numpy as np

# This is a super simple (but slow) example of running face recognition on live video from your webcam.
# There's a second example that's a little more complicated but runs faster.

# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.

# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(0)

# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file(
    "../trainer_images/obama/obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]

# Load a second sample picture and learn how to recognize it.
biden_image = face_recognition.load_image_file(
    "../trainer_images/biden/biden.jpg")
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]

# Load a second sample picture and learn how to recognize it.
chernysh_image = face_recognition.load_image_file(
    "../trainer_images/roman/roman.jpg")
chernysh_face_encoding = face_recognition.face_encodings(chernysh_image)[0]

# Load a second sample picture and learn how to recognize it.
dashka_image = face_recognition.load_image_file(
    "../trainer_images/dashka/dashka.jpg")