Skip to content

The Face Find is able to find given face in group of faces

Notifications You must be signed in to change notification settings

aliyevorkhan/FaceFinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Finder

Web based face finding application.

Demo

Demo

Required libraries

To use this application you must own or install these following libraries:

Usage

flask run

Run the app on your machine: 127.0.0.1:5000

When you visit this address you will see output below:

MainPage

You can see two upload buttons for upload images. First button is used for upload searched image. Second is for upload a group images which can include or not include the searched face. Also you can check uploaded image is right image or not from the preview part. When you upload images succcesfully you can click the Find button:

UploadedImages

After process of recognition, application routes you to the Result page.

You can see matched face(s) and their similarity scores on the image. The result page's output is displayed as below:

Results

Additionally you can check previous results from the Previous Results page.

PreviousResults

How it works

Basically this application include face recognition methods. The face_recognition library provides this.

Aplication workflow:

  1. Load searched face image file through load_image_file() method.

  2. Encode face on uploaded image through face_encodings method.

searchedFaceImg = face_recognition.load_image_file(searchedFace)
searchedFaceEncoding = face_recognition.face_encodings(searchedFaceImg)[0]
  1. Load group of faces image file using Pillow, then convert color space From BGR to RGB.
groupFaceImg = Image.open(groupFace)
groupFaceImg = np.array(groupFaceImg)
groupFaceImg = cv2.cvtColor(np.array(groupFaceImg), cv2.COLOR_BGR2RGB)
  1. Find all the faces and face encodings in the current group of faces image.
face_locations = face_recognition.face_locations(groupFaceImg)
face_encodings = face_recognition.face_encodings(groupFaceImg, face_locations)
  1. Get confidence of face using face_distance() method.
faceConfidence = face_recognition.face_distance(face_encodings, searchedFaceEncoding)    
  1. Now we can calculate similarity score for each face easily. For calculate we using this basic formula:
similarityScore = str(int((1-faceConfidence[count])*100))

This process happen in for loop for each face. The count value is temp varible for counting faces. 7. Draw rectangle around of faces and putting the text of similarity score bottom.

cv2.rectangle(groupFaceImg, (left, top), (right, bottom), color, 3)
cv2.rectangle(groupFaceImg, (left, bottom - 40), (right, bottom), color, cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(groupFaceImg, similarityScore + " %", (left + 6, bottom - 6), font, 0.7, (255, 255, 255), 1)
  1. After all processes we write result image to static directory for storage. For get unique results we give name using datetime.
cv2.imwrite("static/result" + datetime.utcnow().strftime('%B%d%Y%H%M%S') +".jpg", groupFaceImg)
  1. Before the final step we encode image again using base64 for show result dynamically on Result Page.
retval, buffer_img= cv2.imencode('.jpg', groupFaceImg)
data = b64encode(buffer_img)
  1. For final step we redirect result page template with given argument.
return render_template("result.html", data=data)

About

The Face Find is able to find given face in group of faces

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published