Outils pour utilisateurs

Outils du site


face_detection_reconnaissance_faciale

Ceci est une ancienne révision du document !


Reconnaître des visages dans des flux d'images

Un programme très simple en Python pour faire de la détection de visage

Installer les librairies nécessaires

pip3 install face_recognition cv2

Copier coller dans un fichier le code ci-dessous

webcamface.py
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 27 16:58:43 2019
 
@author: vchan
"""
 
# import libraries
import cv2
import face_recognition
 
# Get a reference to webcam 
video_capture = cv2.VideoCapture(0)
 
# Initialize variables
face_locations = []
 
while True:
    # Grab a single frame of video
    ret, frame = video_capture.read()
 
    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
    rgb_frame = frame[:, :, ::-1]
 
    # Find all the faces in the current frame of video
    face_locations = face_recognition.face_locations(rgb_frame)
 
    # Display the results
    for top, right, bottom, left in face_locations:
        # Draw a box around the face
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
 
    # Display the resulting image
    cv2.imshow('Video', frame)
 
    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
 
# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()

En vous plaçant dans le répertoire où est enregistré le fichier, lancer le programme

python3 webcamface.py 
face_detection_reconnaissance_faciale.1678060702.txt.gz · Dernière modification : 2023/03/05 23:58 de Benjamin Labomedia