This repository contains code that allows you to run this facial recognition script locally, or from a client-server model.
If you are on Mac or Linux you can skip this step...
- Install Microsoft C++ Build Tools
dlib can be challenging to install on Windows. If you are having trouble try looking through this Stack Overflow Issue
Refer to this guide for help installing dlib on Mac/Linux:
Start by cloning this repository: git clone <repo-url>
then cd <repo-directory>
To install the required packages ensure you are using Python 3.7+ and run the command:
pip install -r requirements.txt
(Windows) orpip3 install -r requirements.txt
(Mac/Linux)
Assuming all of the packages are installed correctly you should be able to run the code locally.
- Change directories into the
/tutorial
folder:cd tutorial
- Execute the python script
face_rec.py
:python face_rec.py
orpython3 face_rec.py
- Wait, and press
q
to quit the window!
If you'd like to change the image the faces are being predicted for simply download a new image and set the path on line 55 from face_rec.py
:
print(classify_face("test-image.jpg"))
Running the code from the client/server model is slightly more complicated.
-
Start by running the flask backend server.
-
Change directories to
/server
:cd server
-
Start the API server:
python main.py
orpython3 main.py
(take note of the port it is running on, default is5000
) -
Now that the server is running you can change to the
/client
directory:cd ../client
-
If necessary adjust the URL on line 13 of
client.py
to specify the correct port. -
From the client directory run
client.py
:python client.py
orpython3 client.py
If you'd like to change the image the faces are being predicted for simply download a new image and set the path on line 14 from client.py
:
my_img = {'image': open('test-image.jpg', 'rb')} # feel free to change the image path here
To add more faces to be detected simply add a labelled .jpg
or .png
file to the /faces
directory. If you were to add an image of Tim (me!) you would simply save the image as tim.png
(or tim.jpg
).
If you're intersted in deploying the flask server have a look at this Repository and this YouTube Video