kandi background
Explore Kits

face_recognition | simplest facial recognition api for Python | Computer Vision library

 by   ageitgey Python Version: v1.2.2 License: MIT

 by   ageitgey Python Version: v1.2.2 License: MIT

Download this library from

kandi X-RAY | face_recognition Summary

face_recognition is a Python library typically used in Artificial Intelligence, Computer Vision applications. face_recognition has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install face_recognition' or download it from GitHub, PyPI.
The world's simplest facial recognition api for Python and the command line
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • face_recognition has a medium active ecosystem.
  • It has 41296 star(s) with 11514 fork(s). There are 1604 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 617 open issues and 548 have been closed. On average issues are closed in 72 days. There are 24 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of face_recognition is v1.2.2
face_recognition Support
Best in #Computer Vision
Average in #Computer Vision
face_recognition Support
Best in #Computer Vision
Average in #Computer Vision

quality kandi Quality

  • face_recognition has 0 bugs and 0 code smells.
face_recognition Quality
Best in #Computer Vision
Average in #Computer Vision
face_recognition Quality
Best in #Computer Vision
Average in #Computer Vision

securitySecurity

  • face_recognition has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • face_recognition code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
face_recognition Security
Best in #Computer Vision
Average in #Computer Vision
face_recognition Security
Best in #Computer Vision
Average in #Computer Vision

license License

  • face_recognition is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
face_recognition License
Best in #Computer Vision
Average in #Computer Vision
face_recognition License
Best in #Computer Vision
Average in #Computer Vision

buildReuse

  • face_recognition releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • face_recognition saves you 458 person hours of effort in developing the same functionality from scratch.
  • It has 1081 lines of code, 61 functions and 24 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
face_recognition Reuse
Best in #Computer Vision
Average in #Computer Vision
face_recognition Reuse
Best in #Computer Vision
Average in #Computer Vision
Top functions reviewed by kandi - BETA

kandi has reviewed face_recognition and discovered the below as its top functions. This is intended to give you an instant insight into face_recognition implemented functionality, and help decide if they suit your requirements.

  • Train training data .
  • Processes a single frame .
  • Detect face encoding .
  • Show predictions on the frame
  • Predict the predictions from an example frame .
  • Returns the landmark for the specified face image .
  • Display an image .
  • Test an image .
  • Processes the images in the process .
  • capture a single frame

face_recognition Key Features

Find all the faces that appear in a picture:. Get the locations and outlines of each person's eyes, nose, mouth and chin.

Features

copy iconCopydownload iconDownload
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)

Installation Options:

copy iconCopydownload iconDownload
pip3 install face_recognition

Command-Line Interface

copy iconCopydownload iconDownload
$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/

/unknown_pictures/unknown.jpg,Barack Obama
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person

cannot append results to lists on multiprocessing

copy iconCopydownload iconDownload
manager = Manager()
knownEncodings = manager.list()
knownNames = manager.list()
no_faces = manager.list()
error_in_image = manager.list()   

"ERROR: CMake must be installed to build dlib" when installing face_recognition

copy iconCopydownload iconDownload
ERROR: CMake must be installed to build dlib

The called python file won't show again

copy iconCopydownload iconDownload
# online.py (module):
def online():
    ...  # code to be run

# Registers.py (main script):
import online  # at start of file
...  # some code
...  # get rid of the onreg() function, it is not necessary
btn1 = tk.Button(..., command=online.online)  # Line where button is created
...  # rest of code
# online.py (module) stays the same

# Registers.py (main script):
import importlib  # at start of file
online_module = None  # at start of file, just after imports, call this variable whatever you want
...  # some code
def onreg():  # redo this function
    global online_module
    try:
        importlib.reload(online_module)
    except TypeError:
        import online_module
...  # rest of code stays the same
-----------------------
# online.py (module):
def online():
    ...  # code to be run

# Registers.py (main script):
import online  # at start of file
...  # some code
...  # get rid of the onreg() function, it is not necessary
btn1 = tk.Button(..., command=online.online)  # Line where button is created
...  # rest of code
# online.py (module) stays the same

# Registers.py (main script):
import importlib  # at start of file
online_module = None  # at start of file, just after imports, call this variable whatever you want
...  # some code
def onreg():  # redo this function
    global online_module
    try:
        importlib.reload(online_module)
    except TypeError:
        import online_module
...  # rest of code stays the same
-----------------------
# For Face_recognition
from logging import disable
import tkinter
from tkinter.font import BOLD
from cv2 import data
import numpy as np
import face_recognition as fr
import cv2

# SQL-CONNECTOR
import mysql.connector
from mysql.connector import IntegrityError

# For Trainer
import PIL.Image
import os
from tkinter import ttk

# GUI
from tkinter import *
import tkinter as tk
from tkinter import messagebox


def create_window():
    # USER INTERFACE
    window = tk.Tk()
    window.title("FACEREGISTRATION SYSTEM")
    window.resizable(0,0)
    # bgs = PhotoImage(file = "C://Users//So_Low//Desktop//final_recog//online_reg_img/edited2.png")
    # labels1 = Label(window, image = bgs)
    # labels1.place(x = 0, y = 0, relwidth= 1, relheight= 1)
    
    
    
    # UPPER DESIGN
    l1 = tk.Label(window, text= "N O R M I",  font=("Exton Free Trial",35), fg='green')
    l1.grid(column = 2, row= 1)
    
    
    
    # TEXT BOXES
    l1 = tk.Label(window, text= "Name",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=3)
    on1 = tk.Entry(window, width=40, bd=3)
    on1.grid(column=2, row=3)
    
    l1 = tk.Label(window, text= "Parent/Visitor",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=5)
    on2 = tk.Entry(window, width=40, bd=3)
    on2.grid(column= 2, row=5)
    
    l1 = tk.Label(window, text= "Relationship",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=6)
    on3 = tk.Entry(window, width=40, bd=3)
    on3.grid(column= 2, row=6)
    
    l1 = tk.Label(window, text= "ID",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=7)
    on4 = tk.Entry(window, width=19, bd=3, bg="light blue")
    on4.grid(column=2, row=7)
    
    l1 = tk.Label(window, text= "Address",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=8)
    on5 = tk.Entry(window, width=40, bd=3)
    on5.grid(column= 2, row=8)
    
    l1 = tk.Label(window, text= "Contact #",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=9)
    on6 = tk.Entry(window, width=20, bd=3, bg = "light blue")
    on6.grid(column= 2, row=9)
    
    def onregister():
        if (on1.get()==""  or on2.get()=="" or on3.get()=="" or on4.get()=="" or on5.get()=="" or on6.get()==""):
            messagebox.showinfo("Result","Please Complete the Provided Details!")
        else:
            databases = mysql.connector.connect(
            host ="localhost",
            user = "userdata",
            password = "",
            database = "facerecog"
            )
    
            cursors = databases.cursor()
            cursors.execute("SELECT * from record")
            result = cursors.fetchall()
    
    
            id= on4.get()
            id = int(id)+1
            id
            sql = "INSERT INTO record(ids, names,course_year,positions,addresses,contact) values(%s ,%s ,%s , %s, %s, %s)"
            val = (id, on1.get(), on2.get(), on3.get(), on5.get(), on6.get())
            try:
                cursors.execute(sql,val)
                databases.commit()
            except IntegrityError:
                messagebox.showinfo("Error","ID Is Already Exist")
                return onregister
            finally:
                cursors.close()
                databases.close()
    
            on2.delete(0,END)
            on3.delete(0,END)
            on4.delete(0,END)
            on5.delete(0,END)
            on6.delete(0,END)
    
            DirPath = "C:/Users/So_Low/Desktop/final_recog/online_reg_img/"
            Files = os.listdir(DirPath)
    
            for File in Files:
                imgPath = os.path.join(DirPath, File)
                image = cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE)
                cv2.imwrite("C:/Users/So_Low/Desktop/final_recog/img/"+str (on1.get())+"." +str(id)+".jpg",image)
                
    btns1 = tk.Button(window,text= "Save To Database", font=("Bahnschrift",15),bg="light blue",fg="black",command=onregister)
    btns1.grid(column=2,row=40)
    l1 = tk.Label(window, text= " ",  font=("Bahnschrift",15))
    l1.grid(column = 2, row=35)
    
    window.geometry("500x400")
    window.mainloop()
# This won't run anything anymore. It'll just define the function `create_window`.
import online

# We also don't need the function `onreg`. We can use `online.create_window` directly instead.
button1 = tk.Button(window, text="Online Register", font=("Bahnschrift",15), bg="light blue", fg="black", command=online.create_window)
button1.grid(column=1, row=35)
-----------------------
# For Face_recognition
from logging import disable
import tkinter
from tkinter.font import BOLD
from cv2 import data
import numpy as np
import face_recognition as fr
import cv2

# SQL-CONNECTOR
import mysql.connector
from mysql.connector import IntegrityError

# For Trainer
import PIL.Image
import os
from tkinter import ttk

# GUI
from tkinter import *
import tkinter as tk
from tkinter import messagebox


def create_window():
    # USER INTERFACE
    window = tk.Tk()
    window.title("FACEREGISTRATION SYSTEM")
    window.resizable(0,0)
    # bgs = PhotoImage(file = "C://Users//So_Low//Desktop//final_recog//online_reg_img/edited2.png")
    # labels1 = Label(window, image = bgs)
    # labels1.place(x = 0, y = 0, relwidth= 1, relheight= 1)
    
    
    
    # UPPER DESIGN
    l1 = tk.Label(window, text= "N O R M I",  font=("Exton Free Trial",35), fg='green')
    l1.grid(column = 2, row= 1)
    
    
    
    # TEXT BOXES
    l1 = tk.Label(window, text= "Name",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=3)
    on1 = tk.Entry(window, width=40, bd=3)
    on1.grid(column=2, row=3)
    
    l1 = tk.Label(window, text= "Parent/Visitor",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=5)
    on2 = tk.Entry(window, width=40, bd=3)
    on2.grid(column= 2, row=5)
    
    l1 = tk.Label(window, text= "Relationship",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=6)
    on3 = tk.Entry(window, width=40, bd=3)
    on3.grid(column= 2, row=6)
    
    l1 = tk.Label(window, text= "ID",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=7)
    on4 = tk.Entry(window, width=19, bd=3, bg="light blue")
    on4.grid(column=2, row=7)
    
    l1 = tk.Label(window, text= "Address",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=8)
    on5 = tk.Entry(window, width=40, bd=3)
    on5.grid(column= 2, row=8)
    
    l1 = tk.Label(window, text= "Contact #",  font=("Bahnschrift",15))
    l1.grid(column = 1, row=9)
    on6 = tk.Entry(window, width=20, bd=3, bg = "light blue")
    on6.grid(column= 2, row=9)
    
    def onregister():
        if (on1.get()==""  or on2.get()=="" or on3.get()=="" or on4.get()=="" or on5.get()=="" or on6.get()==""):
            messagebox.showinfo("Result","Please Complete the Provided Details!")
        else:
            databases = mysql.connector.connect(
            host ="localhost",
            user = "userdata",
            password = "",
            database = "facerecog"
            )
    
            cursors = databases.cursor()
            cursors.execute("SELECT * from record")
            result = cursors.fetchall()
    
    
            id= on4.get()
            id = int(id)+1
            id
            sql = "INSERT INTO record(ids, names,course_year,positions,addresses,contact) values(%s ,%s ,%s , %s, %s, %s)"
            val = (id, on1.get(), on2.get(), on3.get(), on5.get(), on6.get())
            try:
                cursors.execute(sql,val)
                databases.commit()
            except IntegrityError:
                messagebox.showinfo("Error","ID Is Already Exist")
                return onregister
            finally:
                cursors.close()
                databases.close()
    
            on2.delete(0,END)
            on3.delete(0,END)
            on4.delete(0,END)
            on5.delete(0,END)
            on6.delete(0,END)
    
            DirPath = "C:/Users/So_Low/Desktop/final_recog/online_reg_img/"
            Files = os.listdir(DirPath)
    
            for File in Files:
                imgPath = os.path.join(DirPath, File)
                image = cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE)
                cv2.imwrite("C:/Users/So_Low/Desktop/final_recog/img/"+str (on1.get())+"." +str(id)+".jpg",image)
                
    btns1 = tk.Button(window,text= "Save To Database", font=("Bahnschrift",15),bg="light blue",fg="black",command=onregister)
    btns1.grid(column=2,row=40)
    l1 = tk.Label(window, text= " ",  font=("Bahnschrift",15))
    l1.grid(column = 2, row=35)
    
    window.geometry("500x400")
    window.mainloop()
# This won't run anything anymore. It'll just define the function `create_window`.
import online

# We also don't need the function `onreg`. We can use `online.create_window` directly instead.
button1 = tk.Button(window, text="Online Register", font=("Bahnschrift",15), bg="light blue", fg="black", command=online.create_window)
button1.grid(column=1, row=35)

Sorting a tensor list in ascending order

copy iconCopydownload iconDownload
namestodistance = [('Alice', .1), ('Bob', .3), ('Carrie', .2)]
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
namestodistance = list(map(lambda x: (x[0], x[1].item()), namestodistance)
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
-----------------------
namestodistance = [('Alice', .1), ('Bob', .3), ('Carrie', .2)]
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])
namestodistance = list(map(lambda x: (x[0], x[1].item()), namestodistance)
names_top = sorted(namestodistance, key=lambda x: x[1])
print(names_top[:2])

is possible to face recognition with mediapipe in python

copy iconCopydownload iconDownload
locations = face_recognition.face_locations(frame, model="hog")
-----------------------
face_recognition.api.compare_faces(known_face_encodings,face_encoding_to_check, tolerance=0.5)

"No CMAKE_CXX_COMPILER could be found" errror while deploying flask app on gcloud

copy iconCopydownload iconDownload
FROM debian:buster
RUN apt update && apt install -y gcc clang clang-tools cmake python3

I am trying to load and split my data however i get TypeError: 'only integer scalar arrays can be converted to a scalar index'

copy iconCopydownload iconDownload
from sklearn.datasets import fetch_olivetti_faces

data = fetch_olivetti_faces()
Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, data.target, test_size=0.3, random_state=0)

How to list lowest values in numpy array

copy iconCopydownload iconDownload
names = known_face_names[top_3_matches]
face_names.append(names)
print(names)
name = known_face_names[best_match_index]
face_names.append(name)
print(name)
-----------------------
names = known_face_names[top_3_matches]
face_names.append(names)
print(names)
name = known_face_names[best_match_index]
face_names.append(name)
print(name)
-----------------------
def classify_face(im):
    faces = encoding
    faces_encoded = list(faces.values())
    known_face_names = list(faces.keys())
    #make lists into numpy arrays
    n_faces_encoded = np.array(faces_encoded)
    n_known_face_names = np.array(known_face_names)
n_face_distances = face_recognition.face_distance(n_faces_encoded, face_encoding)
top_3_matches = np.argsort(n_face_distances)[:3]
other_matches = n_known_face_names[top_3_matches]
print(other_matches)
-----------------------
def classify_face(im):
    faces = encoding
    faces_encoded = list(faces.values())
    known_face_names = list(faces.keys())
    #make lists into numpy arrays
    n_faces_encoded = np.array(faces_encoded)
    n_known_face_names = np.array(known_face_names)
n_face_distances = face_recognition.face_distance(n_faces_encoded, face_encoding)
top_3_matches = np.argsort(n_face_distances)[:3]
other_matches = n_known_face_names[top_3_matches]
print(other_matches)
-----------------------
def classify_face(im):
    faces = encoding
    faces_encoded = list(faces.values())
    known_face_names = list(faces.keys())
    #make lists into numpy arrays
    n_faces_encoded = np.array(faces_encoded)
    n_known_face_names = np.array(known_face_names)
n_face_distances = face_recognition.face_distance(n_faces_encoded, face_encoding)
top_3_matches = np.argsort(n_face_distances)[:3]
other_matches = n_known_face_names[top_3_matches]
print(other_matches)

list/numpy array out of range

copy iconCopydownload iconDownload
try:
    face = face_recognition.load_image_file("datasets/" + f)
    encoding = face_recognition.face_encodings(face, model="cnn")[0]
    encoded[f.split(".")[0]] = encoding
    print("Encoding image", f)
except Exception:
    pass

Module not imported running python script at startup

copy iconCopydownload iconDownload
[Unit]
Description=Start Bling

[Service]
User=pi
Environment=DISPLAY=:0
WorkingDirectory=/home/pi/facial_recognition
Environment=XAUTHORITY=/home/pi/.Xauthority
Environment="prog_path"=/home/pi/facial_recognition
ExecStart=/usr/bin/python /home/pi/facial_recognition/run_on_start.py
Restart=always
RestartSec=10s
KillMode=process
TimeoutSec=infinity

[Install]
WantedBy=graphical.target

Community Discussions

Trending Discussions on face_recognition
  • cannot append results to lists on multiprocessing
  • "ERROR: CMake must be installed to build dlib" when installing face_recognition
  • The called python file won't show again
  • PyInstaller: How to call "shape_predictor_68_face_landmarks.dat" file with dlib.shape_predictor, while imported it with 'binaries'?
  • Sorting a tensor list in ascending order
  • problem in Installing (python Library) face_recognition on windows 10/11
  • Celery/redis tasks don't always complete - not sure why or how to fit it
  • is possible to face recognition with mediapipe in python
  • "No CMAKE_CXX_COMPILER could be found" errror while deploying flask app on gcloud
  • I am trying to load and split my data however i get TypeError: 'only integer scalar arrays can be converted to a scalar index'
Trending Discussions on face_recognition

QUESTION

cannot append results to lists on multiprocessing

Asked 2022-Mar-18 at 11:30

This below code will generate face encodings using multiprocessing , i can able to print the encoding but the problem is the knownEncodings ,knownNames ,no_faces ,error_in_image all are empty after the execution. I know its due to multiprocessing , but not sure how to mitigate this.

import face_recognition
from imutils import paths
from multiprocessing import Pool
import pickle
import cv2
import os,sys,time

print("[INFO] quantifying faces...")

img_folder_path=sys.argv[1]

image_paths = list(paths.list_images(img_folder_path))

knownEncodings = []
knownNames = []
no_faces = []
error_in_image =[]

def create_encoding(imagePath):
    print("[INFO] processing image...")
    name = imagePath.split(os.path.sep)[-1]
    image = cv2.imread(imagePath)
    if image is None:
        return
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # detect the (x, y)-coordinates of the bounding boxes
    # corresponding to each face in the input image
    boxes = face_recognition.face_locations(rgb)

    # compute the facial embedding for the face
    if len(boxes) != 0:
        boxes = list(boxes[0])
        encodings = face_recognition.face_encodings(image, [boxes])
        for encoding in encodings:  
            knownEncodings.append(encoding)
            knownNames.append(name)
        
    else:
        print("no face found" ,image_paths )
        no_faces.append(image_paths )



# loop over the image paths with multiprocessing
start_time = time.time()

with Pool(8) as pool:
    pool.map(create_encoding, image_paths )


end_time = time.time()
print(end_time - start_time)

# dump the facial encodings + names to disk
print("[INFO] serializing encodings...")
data = {"encodings": knownEncodings, "names": knownNames, "no_faces":no_faces,"error_in_image":error_in_image}

f_name = img_folder_path.replace("/","-")
print(f_name)
f = open(f"encodings_{f_name}.pickle", "wb")
f.write(pickle.dumps(data))
f.close()

ANSWER

Answered 2022-Mar-18 at 10:46

You should not use list cross several processes. You can use multiprocessing.Queue or other Process safe models. How to use multiprocessing queue in Python?

Source https://stackoverflow.com/questions/71525117

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install face_recognition

First, make sure you have dlib already installed with Python bindings:.
How to install dlib from source on macOS or Ubuntu
Jetson Nano installation instructions Please follow the instructions in the article carefully. There is current a bug in the CUDA libraries on the Jetson Nano that will cause this library to fail silently if you don't follow the instructions in the article to comment out a line in dlib and recompile it.
Raspberry Pi 2+ installation instructions
@masoudr's Windows 10 installation guide (dlib + face_recognition)
Download the pre-configured VM image (for VMware Player or VirtualBox).

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Computer Vision Libraries with Highest Support
Compare Computer Vision Libraries with Highest Security
Compare Computer Vision Libraries with Permissive License
Compare Computer Vision Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.