This project is to automatically measure the facial Width-To-Height Ratio and get facial analysis results provided by Microsoft Azure Cognitive Services. Used in
- The face of risk: CEO facial masculinity and firm risk by Shinichi Kamiya, Y. Han (Andy) Kim, Soohyun Park (Me)
- "부자, 관상, 기술" written by Y. Han (Andy) Kim
You can get some estimatations of below (per image):
-
Facial Width-To-Height Ratio
-
X, y coordinates for 68 facial landmarks
-
If you use Microsoft Face APIs:
- Age
- Gender
- Emotions
- fear, sadness, disgust, contempt, neutral, happiness, anger
- Glasses / no glasses
- Moustache
- Beard
- Sideburns
- Bald
Since June 11th, 2020, Microsoft Azure Face recognition services are strictly prohibited for use by or for US police departments. Read this announcement
- Python 3.6
- Dlib
- Opencv
- Flask
- python version 3.6 with Anaconda distribution (no guarantee for other versions)
- You can download Anaconda Individual Edition in here
- Check your anaconda installation by
conda -V
- Create a virtual environment by
conda create -n [name] python=3.6
and activate the venv byconda activate [name]
- Clone this repo
git clone https://github.com/haileypark-kr/fwhr-calc-website.git
- Move to the project root directory.
cd fwhr-calc-website
- Microsoft Azure Face Api Key
- Create an Azure account and a Cognitive Service Face API resource in Azure Portal. Read this documentation.
- Generate keys to access your API. (Resource Management > Keys and Endpoint)
- Make a file named
azure_faceapi_key.conf
and paste the first key in the file. (you can change the file name if you want, but make sure you also change.gitignore
andconfig.py
) Do not upload this file to GitHub. - Replace the variable
FACE_API_ENDPOINT
inconfig.py
with your endpoint.# config.py FACE_API_ENDPOINT = "https://eastasia.api.cognitive.microsoft.com"
Install python libraries in this project's root directory.
pip install -r requirements.txt
conda install -y -c conda-forge dlib
- Some libraries (e.g. dlib) cannot be installed by pip - should be installed using
conda
.
- Some libraries (e.g. dlib) cannot be installed by pip - should be installed using
There are two ways to run this application.
- Running a flask web server: If you want to analyze a few facial images with GUI.
- Running fWHR calcaculating script: If you want to analyze thousands of images.
- Command:
python app.py
- Open a Chrome browser and enter
127.0.0.1:5001
- Select some images and press Submit button.
- Wait and do not reload the browser.
- Anlysis result will be downloaded shortly. (in xlsx format)
- Command:
python fWHR_main.py --dataroot [path to the image directory]
- Wait
- Go to
data/output
direcetory and get the analysis result file.
You can change configuration values configured in config.py
.
-
directory path configs
- UPLOAD_FOLDER: directory to save uploaded images via flask web server
- OUTPUT_FOLDER: directory to save output images
- ERROR_DATA_FOLDER: directory to save images where this application couldn't find any faces
- PRETRAINED_MODEL_PATH: path to pretrained model. Either a relative path from this project root directory or an absolute path.
-
image configs
- ALLOWED_EXTENSIONS: set of allowed image extensions. case insensitive.
-
Microsoft Azure configs
- USE_MS_FACE_API: boolean value whether to use Microsoft Face API or not. (False / True)
- FACE_API_KEY_CONFIG_FILE: name of the config file storing Microsoft Face API key. You can get this value in Azure portal.
- FACE_API_ENDPOINT: endpoint of Microsoft Face API. You can get this value in Azure portal.
- FACE_API_URL: full url for Microsoft Face API. Do not edit this value unless the API's url path is changed.