Environment Setup
face_recognition is a robust open-source facial recognition libray with comprehensive documentation. Although primarily designed for Linux systems, it can be installed on Windows with additional dependencies.
Prerequisites
- Operating System: Windows 11
- Development Environment: PyCharm
- Python Version: 3.12
Installing Dependencies
CMake Installation
First, install CMake using pip:
pip install cmake
Visual Studio Build Tools
Install the following components from Visual Studio:
- MSVC v143 - VS 2022 C++ x64/x86 build tools
- Windows 11 SDK
Installing dlib
After instalilng the prerequisites, install dlib:
pip install dlib
Installing face_recognition
Install the main package:
pip install face_recognition
Additional Models
Install the required models from GitHub:
pip install git+https://github.com/ageitgey/face_recognition_models
Setuptools
Install setuptools if not already present:
pip install setuptools
Verification Demo
Test the installation with a simple face detection script:
import face_recognition
from PIL import Image
# Load and process image
input_image = face_recognition.load_image_file("test_image.jpg")
detected_faces = face_recognition.face_locations(input_image)
print(f"Detected {len(detected_faces)} face(s)")
for face in detected_faces:
top, right, bottom, left = face
print(f"Face coordinates - Top: {top}, Left: {left}, Bottom: {bottom}, Right: {right}")
# Extract and display face
face_region = input_image[top:bottom, left:right]
pil_face = Image.fromarray(face_region)
pil_face.show()