Skip to content

MaherDissem/Pupillary-Distance-Measurement-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pupillary Distance Measurement App

What is the PD (Pupillary Distance)?

It is the distance between the centers of your pupils, measured in millimeters.

It ensures that the optical center of each lens aligns correctly with your eyes. If PD is incorrect, glasses can cause eye strain, headaches, or blurred vision.

Although PD is usually measured during eye exams, it is often not included on prescriptions, making it hard to order glasses online without visiting an optician.

This app allows you to measure your own PD using a simple selfie.

How to Use the App

  1. Place an ArUco marker just above and between your eyes, facing the camera and parallel to your face. This acts as a reference object with a known size, allowing the app to convert distances in pixels into real-world measurements accurately.
  2. Take a clear photo showing your eyes while looking directly at the camera (see example below).
  3. Upload the photo to the app. The backend automatically:
    • Detects the center of each iris and computes the distance between them in pixels.
    • Detects the ArUco marker and uses it as a scale reference to convert pixel distances into real-world measurements.
    • Calculates and returns your Pupillary Distance (PD) in millimeters.
  4. The app will display the detected iris centers on the image and show your computed PD, allowing you to visually verify accuracy before using the measurement.
  5. It is recommended to run the app multiple times with different images and take the average result for more accurate PD measurement.

You can generate a marker here: ArUco Marker Generator.

Example: person holding an ArUco marker on their face and taking a selfie

App Preview

Screenshot of the app

Setup

Precompiled Binary

  • Check the Releases tab for a provided precompiled Windows executable.
  • Note: An antivirus may trigger a false-positive warning.

Manual Installation

Alternatively follow these steps to manually run or build this app.

Install uv and create a Python 3.11 virtual environment:

pip install uv
uv venv --python 3.11 .venv
source .venv/Scripts/activate

Install the backend

Option A (recommended): Use the existing lock file:
uv pip sync uv.lock
Option B: Manually install dependencies
uv pip install -e backend
# optionally generate a lock file
uv pip compile ./backend/pyproject.toml -o uv.lock 

Run code

This command will start the FastAPI backend and serve your frontend automatically. It also opens your default browser to the app interface.

python run.py

Build from source

To create a standalone binary executable:

uv pip install pyinstaller
pyinstaller --onefile --add-data "frontend;frontend" --collect-data mediapipe run.py

Disclaimer

This app is provided for personal use only.
Use it at your own responsibility. We provide no guarantees, warranties, or medical advice.

About

Measures Pupillary Distance from a selfie using automatic iris detection and an ArUco marker for real-world scaling.

Topics

Resources

License

Stars

Watchers

Forks