Skip to main content

Face Library is an open source package for accurate and real-time face detection and recognition

Project description

Face Library

Downloads

Face Library is a 100% python open source package for accurate and real-time face detection and recognition. The package is built over OpenCV and using famous models and algorithms for face detection and recognition tasks. Make face detection and recognition with only one line of code. The Library doesn't use heavy frameworks like TensorFlow, Keras and PyTorch so it makes it perfect for production.

Patch 1.1.3

BlazeFace model used in face detection now instead of Haar Cascade, decreasing the inference time x10 times and detect frontal and profile face more accurate

Please Upgrade to latest version if you already have Face Library.

Table of contents

Installation

pip install face-library

Upgrade

pip install face-library -U

Usage

Importing

from face_lib import face_lib
FL = face_lib()

The model is built over OpenCV, so it expects cv2 input (i.e. BGR image), it will support PIL in the next version for RGB inputs. At the end there is a piece of code to make PIL image like cv2 image.

Face detection

import cv2

img = cv2.imread(path_to_image)
faces = FL.get_faces(img) #return list of RGB faces image

If you want to get faces locations (coordinates) instead of the faces from the image you can use

no_of_faces, faces_coors = FL.faces_locations(face_img)

You can change the maximum number of faces could be detcted as follows

no_of_faces, faces_coors = FL.faces_locations(face_img, max_no_faces = 10) #default number of max_no_faces is 2

You can change face detection thresholds (score threshold, iou threshold) -if needed-, by using the following function

FL.set_detection_params(scoreThreshold=0.82, iouThreshold=0.24) # default paramters are scoreThreshold=0.7, iouThreshold=0.3

Face verfication

The verfication process is compossed of two models, a face detection model detect faces in the image and a verfication model verfiy those face.

img_to_verfiy = cv2.imread(path_to_image_to_verify) #image that contain face you want verify
gt_img = cv2.imread(path_to_image_to_compare) #image of the face to compare with

face_exist, no_faces_detected = FL.recognition_pipeline(img_to_verfiy, gt_image)

You can change the threshold of verfication with the best for your usage or dataset like this :

face_exist, no_faces_detected = FL.recognition_pipeline(img_to_verfiy, gt_image, threshold = 1.1) #default number is 0.92

also if you know that gt_img has only one face and the image is zoomed to that face (minimum 65%-75% of image is face) like this :

You can save computing time and the make the model more faster by using

face_exist, no_faces_detected = FL.recognition_pipeline(img_to_verfiy, gt_image, only_face_gt = True)

Note: if you needed to change detection parameters before the recognition pipeline you can call set_detection_params function as mentioned in Face detection section.

Extracting face embeddings

I you want represent the face with vector from face only image, you can use

face_embeddings = FL.face_embeddings(face_only_image)

For PIL images

import cv2
import numpy
from PIL import Image

PIL_img = Image.open(path_to_image)

cv2_img = cv2.cvtColor(numpy.array(PIL_img), cv2.COLOR_RGB2BGR) #now you can use this to be input for face_lib functions

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Support

There are many ways to support a project - starring⭐️ the GitHub repo is just one.

Licence

Face library is licensed under the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

face-library-1.1.3.tar.gz (601.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

face_library-1.1.3-py3-none-any.whl (604.4 kB view details)

Uploaded Python 3

File details

Details for the file face-library-1.1.3.tar.gz.

File metadata

  • Download URL: face-library-1.1.3.tar.gz
  • Upload date:
  • Size: 601.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for face-library-1.1.3.tar.gz
Algorithm Hash digest
SHA256 c6e6d03ccd3e7b96311832945e2f1d2f2b3900b9c812bc7d7af67f20c669e1b0
MD5 cec0e0a0d02ba44f8d99fceb507057c4
BLAKE2b-256 a8acf7126f3000ad3c892eb3fece6113cd9a347d8ab43c1b95326db0820a7347

See more details on using hashes here.

File details

Details for the file face_library-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: face_library-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 604.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for face_library-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2cce4f27039ddc7202ea8f2ab31b6f719c403881ddceb1a1431f40ef4a0a11d4
MD5 f62173e964f4fb5ad74bdbf0b4a87030
BLAKE2b-256 fb69d21a14c99c6d56c445768207eb004dbfb2e1a8ad067c5d7304ed7bda505a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page