Note this currently only works on Windows (because of the beep)
- Download and extract the .zip: https://github.com/jamesdeluk/Face-Distance-Measurement/archive/refs/heads/main.zip
- Install Python 3.11 (not 3.12 or later): https://www.python.org/downloads/
- Optional: Create and activate a virtual environment:
python -m venv Face-Distance-Measurement-env
thenFace-Distance-Measurement-env\Scripts\activate
- Install requirements:
pip install -r Face-Distance-Measurement-main\requirements.txt
- Edit
calculate_f.py
with a text editor (e.g. Notepad) and change:d = 50
to the distance you want to be from the screen (in cm)W = 6.3
to your pupillary distance (in cm)
- Run
python calculate_f.py
and watch the console to see the number forf
(also, if you want, look at your beautiful face in the pop-up) - Edit
measure_distance.py
with a text editor (e.g. Notepad) and change:f = 700
to the number fromcalculate_f.py
W = 6.3
to your pupillary distance (in cm)limit = 50
to the distance you want to be alerted to if you get too close (in cm)
- Run
python measure_distance.py
You can also use measure_distance_with_face.py
instead (need to make the same Notepad changes) but this will use more power.
In this project, we are going to find the distance between a face and a normal webcam. We will use some basic mathematics along with some AI techniques to achieve decent accuracy. To solidify the concept we will use it in an example project, where the size of the text increases if the person is far away from the screen.