Reconocer y manipular caras desde Python o desde la línea de comandos con la biblioteca de reconocimiento facial más simple del mundo.
Creamos un entorno nuevo con python 3.8
conda create --name face_recognition python=3.8
Activamos el entorno
conda activate face_recognition
Para instalar la dependencia face_recognition es necesario tener instalado CMake En ubuntu:
sudo apt install -y build-essential
sudo apt install -y cmake
En ubuntu:
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build; cd build; cmake ..; cmake --build .
cd ..
python setup.py install
Ejecutamos el pip install...
pip install -r requirements.txt
Necesitamos la estructura de "img/known/*.jpg" con las imagenes conocidas (etiquetadas por su nombre) Necesitamos la estructura de "out/" donde se guarda la imagen resultante Obtenemos los resultados en el diccionario faces imprimido al final
python test_api.py
Ejemplo del resultado faces:
[{'id': 0, 'name': 'Steve Jobs', 'known': True, 'bbox': [76, 135, 166, 46]}, {'id': 0, 'name': 'Desconocido', 'known': False, 'bbox': [60, 304, 103, 261]}]
Levantar el api con uvicorn
uvicorn app.main:app --reload
Acceder al swagger para probar
http://127.0.0.1:8000/docs#/
sudo docker-compose build
sudo docker-compose up -d
If you want to create a soft link of img_known volume on working dir
sudo docker inspect face-recognition | grep img_known | grep Source
sudo ln -s /dockers_servicios/volumes/face_recognition_img_known/_data ./img_known
Important all requests must include {user_id} in the path request, and must exists a dir with {user_id} name under img_known volume, with the known faces images properly named with the person name and surname. Like: "img_known/-N0MJI_cWfK3EVTybR59/Alvaro Hernandez.jpg" Example of curl request:
curl -X 'POST' \
'http://127.0.0.1:8000/face/identify/-N0MJI_cWfK3EVTybR59' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/jpeg'