Package: face-library
Face LibraryFace 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.3BlazeFacemodel used in face detection now instead of Haar Cascade, decreasing the inference time x10 times and detect frontal and profile face more accuratePlease Upgrade to latest version if you already have Face Library.Table of contentsInstallationUsageImportingFace detectionFace verficationExtracting face embeddingsFor PIL imagesContributingSupportLicenceInstallationpipinstallface-libraryUpgradepipinstallface-library-UUsageImportingfromface_libimportface_libFL=face_lib()The model is built over OpenCV, so it expects cv2 input (i.e. BGR image), it will supportPILin the next version for RGB inputs. At the end there is a piece of code to makePILimage like cv2 image.Face detectionimportcv2img=cv2.imread(path_to_image)faces=FL.get_faces(img)#return list of RGB faces imageIf you want to get faces locations (coordinates) instead of the faces from the image you can useno_of_faces,faces_coors=FL.faces_locations(face_img)You can change the maximum number of faces could be detcted as followsno_of_faces,faces_coors=FL.faces_locations(face_img,max_no_faces=10)#default number of max_no_faces is 2You can change face detection thresholds(score threshold, iou threshold)-if needed-, by using the following functionFL.set_detection_params(scoreThreshold=0.82,iouThreshold=0.24)# default paramters are scoreThreshold=0.7, iouThreshold=0.3Face verficationThe 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 verifygt_img=cv2.imread(path_to_image_to_compare)#image of the face to compare withface_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.92also if you know thatgt_imghas 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 usingface_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 callset_detection_paramsfunction as mentioned inFace detectionsection.Extracting face embeddingsI you want represent the face with vector from face only image, you can useface_embeddings=FL.face_embeddings(face_only_image)For PIL imagesimportcv2importnumpyfromPILimportImagePIL_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 functionsContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.SupportThere are many ways to support a project - starring⭐️ the GitHub repo is just one.LicenceFace library is licensed under the MIT License