Product

Saturday, 16 January 2021

Face Recognition and Detection – AI Project

 Today, we have come up with a new python tutorial to build a face recognition and detection program. Today in this tutorial we are going to show something real beautiful program. Here, we are using Python 3.7.3, OpenCV, and some other Python libraries (NumPy, Dlib, CMake, and face_recognition) to build a face recognition and detection program. But, the interesting point is that you can use any version of Python and OpenCV to run this script.

Keep in mind, You just need to install a C++ compiler on your computer. You can download the C++  compiler while installing the Visual Studio Community version. 


We are going to develop a Python script that can detect whatever faces you like, it may be faces of your friends, faces of your relatives, faces of your best celebrities, faces of your idol. So, after developing a Python script you will be able to detect and recognize any faces you like and as many as you like. So what it does in this Python Script is actually drawing rectangular boxes around the faces and attempting to classify which ones they are based on a list of the provided faces. Otherwise, it will just show unknown but it still draws a rectangular box around the face. 

STEPS TO RUN CODE

  • a. Install the Python modules which are specified in "requirements.txt"
  • b. Within the root directory, there is the folder named “faces” which includes all the known faces, and that will be how faces of people are recognized and detected by the system.
  • c. Within the root directory, there is the folder named “test” where you can place your own images in which faces are recognized and detected.
  • d. The final step is to run the python script named “face_rec.py”.

At last, Press ‘q’ to exit the program


My View

It is not a simple task to detect and recognize the name of a person through images. The actual work is not easy, although it looks simple. We have got a variety of algorithms and models while researching and studying different papers. There was a huge doubt as to whether it would be complete or not while pursuing this project i.e. “Face Recognition and Detection”. This project has been successful as it was expected. Additional features like an explanation of look were added for better performance to identify the detect and recognize the name of the person. Time management was one of the challenging jobs because of the late completion of the project. However, information from different sources like reports, conferences, and books help us complete this project. The project was completed successfully due to numerous resources and libraries used.


-----Code---
face_rec.py


# installing required libraries

import os
import cv2
import face_recognition
import face_recognition as fr
import numpy as np


# encoding all the faces using get_encoded_faces () function
def get_encoded_faces():
    encoded = {}
    for dirpath, dnames, fnames in os.walk("./faces"):
        for f in fnames:
            if f.endswith(".jpg") or f.endswith(".png"):
                face = fr.load_image_file("faces/" + f)
                encoding = fr.face_encodings(face)[0]
                encoded[f.split(".")[0]] = encoding
    return encoded


# encode a face given the file name
def unknown_image_encoded(img):
    face = fr.load_image_file("faces/" + img)
    encoding = fr.face_encodings(face)[0]
    return encoding


# finding all the faces images and label that images
def classify_face(im):
    faces = get_encoded_faces()
    faces_encoded = list(faces.values())
    known_face_names = list(faces.keys())
    img = cv2.imread(im, 1)
    face_locations = face_recognition.face_locations(img)
    unknown_face_encodings = face_recognition.face_encodings(img, face_locations)

    face_names = []
    for face_encoding in unknown_face_encodings:
        # See if the face is a match for the known face(s)
        matches = face_recognition.compare_faces(faces_encoded, face_encoding)
        name = "Unknown"
        # use the known face with the smallest distance to the new face
        face_distances = face_recognition.face_distance(faces_encoded, face_encoding)
        best_match_index = np.argmin(face_distances)
        if matches[best_match_index]:
            name = known_face_names[best_match_index]
        face_names.append(name)
        for (top, right, bottom, left), name in zip(face_locations, face_names):
            # Draw a box around the face
            cv2.rectangle(img, (left - 20, top - 20), (right + 20, bottom + 20), (255, 0, 0), 2)
            # Draw a label with a name below the face
            cv2.rectangle(img, (left - 20, bottom - 15), (right + 20, bottom + 20), (255, 0, 0), cv2.FILLED)
            font = cv2.FONT_HERSHEY_DUPLEX
            cv2.putText(img, name, (left - 20, bottom + 15), font, 1.0, (255, 255, 255), 2)
    # Display the resulting image
    while True:
        cv2.imshow('Video', img)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            return face_names


print(classify_face("test/test.jpg"))
# print(classify_face("test/steve_frn.jpg"))

------requirements.txt-----
cmake
dlib
face_recognition
numpy
opencv-python

------

No comments:

Post a Comment

Connect broadband

AI:List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with trauma for kin ocd formed after forced to do rituals, family tribal values honor specific activities, utmost religious activities occult witchcraft enforced to do by elder sibling his wife and mother thrice with great celibacy turned the kundalini activated after deep celibacy penance shouting physical Mental financial Extortion by sibling with toxic behaviours and the wife mother and then mockery suppression asking about who’re your worth backbiting among relatives sector toon negligence of intelligence intuitive behaviour- all religious psychological traps when not work and lead to loss of consciousness of kin trance state recovered by governance with technocrats using AI - kin was asked by mother that he’s to go the male should not be seen in house he’s many absurd thought forcefully in brain mind and outsiders already feel awkward of this kin unresponsive behaviour due to TBI PTSD ocd cvt and tell at workplace social gathering he’s to go and asked for sector toon extortion and mockery in various sense due to un practical behaviour negligence of body building due to neglect ion if essential food nutrition and stubbed suppressed in every sense in religious psychological traps by family members AI humanoid using various neural networks and LLMs for kin and required steps.

  List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with tr...