Project Report on Face Recognition by Priyam Harsh (ICSS Student)

A Project Report

On

[Find My Face]

Project Report is submitted to Indian Cyber Security Solutions under the guidance of Himalaya Sir.

Submitted By – Priyam Harsh (ICSS Student)

 

 

Project Report

 

 

 

INDEX

 

  1. Introduction

 

  1. Project Ideas

 

  1. Problem Faced

 

  1. Future Scope

 

  1. Reference

 

  1. Conclusion

 

 

INTRODUCTION

Python is a high-level, interpreted and general-purpose dynamic programming language that focuses on code readability. The syntax in Python helps the programmers to do coding in fewer steps as compared to Java or C++. The Python is widely used in bigger organizations because of its multiple programming paradigms. They usually involve imperative and object-oriented functional programming. It has a comprehensive and large standard library that has automatic memory management and dynamic features.

So, today, we are going to see a project created using the Python programming language with an amazing feature of face recognition. Let’s dive right into it.

 

 

PROJECT IDEAS

First of all, there is “register_my_face.py”, which will capture your face using your webcam and saved it in a directory. Second, there is “find_my_face.py”, which will find all the pictures containing your face and will save all those pictures into another directory.

First, I am going to provide you the source code for the “register_my_face.py”. The source code is as follows:

*******************************************************************

import cv2

import os

import face_recognition

import shutil

 

cam = cv2.VideoCapture(0)

 

r = 0

 

print()

print(“********** Register Your Face **********”)

print()

n = input(“Enter your name: “)

print()

print(“Getting the camera ready..”)

 

cv2.namedWindow(“Capture”)

if “Registered” not in os.listdir():

os.mkdir(“Registered”)

 

os.chdir(“Registered”)

 

print()

print(“Press Space whenever ready..”)

print(“Press Esc to cancel the registration..”)

print()

 

while True:

ret, frame = cam.read()

cv2.imshow(“Capture”, frame)

if not ret:

break

k = cv2.waitKey(1)

 

if k%256 == 27:

# ESC pressed

print(“Escape hit, closing…”)

r = 1

break

elif k%256 == 32:

# SPACE pressed

img_name = “{}.jpg”.format(n)

cv2.imwrite(img_name, frame)

print(“{} written!”.format(img_name))

break

 

if r is 0:

picture_of_me = face_recognition.load_image_file((n+”.jpg”))

my_face_encoding = face_recognition.face_encodings(picture_of_me)

if len(my_face_encoding) == 0:

print(“We couldn’t recognize any face !”)

print(“Please try again !!”)

shutil.rmtree(“Registered”)

else:

print(“Registration Successful !!”)

elif r is 1:

print(“Registration Cancelled !!”)

 

cam.release() *******************************************************************

As we can see in the source code, the program will ask your name and after entering your name, it will start up your webcam with instructions to capture your face with “Space Key” or to cancel the process using “Esc key”. After successful capture, the image is stored in “Registered” directory, then, the program will try to find a face in the captured image. If the program doesn’t detect any face, the process is terminated and the captured picture is deleted.

Secondly, the source code of “find_my_face.py” is as follows:

*******************************************************************

import os

import face_recognition

from optparse import OptionParser

import shutil

 

 

print(”  ______ _           _   __  __         ______”)

print(” |  ____(_)         | | |  \/  |       |  ____|”)

print(” | |__   _ _ __   __| | | \  / |_   _  | |__ __ _  ___ ___ “)

print(” |  __| | | ‘_ \ / _` | | |\/| | | | | |  __/ _` |/ __/ _ \ “)

print(” | |    | | | | | (_| | | |  | | |_| | | | | (_| | (_|  __/ “)

print(” |_|    |_|_| |_|\__,_| |_|  |_|\__, | |_|  \__,_|\___\___| “)

print(”                                 __/ |”)

print(”                                |___/”)

print()

print(“Author: Priyam Harsh”)

print()

 

parser = OptionParser(usage=”Usage: %prog path”,version=”%prog 1.0″)

(options, args) = parser.parse_args()

 

if len(args) != 1:

parser.error(“Please enter the path to the pictures”)

 

results = []

cdir = os.getcwd()

 

if “Registered” in os.listdir():

os.chdir(“Registered”)

regface = (os.listdir())[0]

picture_of_me = face_recognition.load_image_file(regface)

my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]

my_pics = []

print(“Make sure that your registered face is clear”)

print(“Otherwise the program may not work very accurately”)

print()

print(“Please Wait while we process all your pics”)

else:

print(“No registered face found !!”)

print(“Register your face first.”)

exit()

 

plist = os.listdir(args[0])

os.chdir(args[0])

print()

for i in plist:

ext = (i.split(“.”))[1]

if ext == “jpg” or ext == “jpeg” or ext == “png”:

print(“Processing -“,i)

unknown_picture = face_recognition.load_image_file(i)

unknown_face_encoding = face_recognition.face_encodings(unknown_picture)

for en in unknown_face_encoding:

results.append(face_recognition.compare_faces([my_face_encoding], en, tolerance=0.25))

for ch in results:

if True in ch:

print(“|”)

print(“|—–> Your face found in this picture !!”)

my_pics.append(i)

results = []

 

if “my_pictures” in os.listdir():

passs

else:

os.mkdir(“my_pictures”)

 

for i in my_pics:

shutil.copy(i,”my_pictures”)

 

os.chdir(cdir)

shutil.rmtree(“Registered”) *******************************************************************

This program will require a path to the directory containing the pictures which need to be processed. The image containing the previously registered face is opened inside the program and the face encoding is stored. Now, each and every image in the provided directory is opened one by one and the face encoding is checked with the encodings in the image. If the image contains your face, that image will be copied inside another folder named “my_pictures”.

 

 

Python Project

 

 

HOW TO USE THIS PROGRAM?

Firstly, as I said before, we will open the “register_my_face.py”. The process of registration is quite simple and user-friendly.

Then, run “find_my_face.py” ending with the complete path to the directory containing the pictures.

(Eg. find_my_face  .py “G:\Pictures\Road Trip”)

Now, just sit back and relax. The program will do its job.

It will create a folder “my_pictures” containing all the pictures that contains your face, i.e., “G:\Pictures\Road Trip\my_pictures”.

 

Find My Face

import os
import face_recognition
from optparse import OptionParser
import shutil

print()
print(” ______ _ _ __ __ ______”)
print(” | ____(_) | | | \/ | | ____|”)
print(” | |__ _ _ __ __| | | \ / |_ _ | |__ __ _ ___ ___ “)
print(” | __| | | ‘_ \ / _` | | |\/| | | | | | __/ _` |/ __/ _ \ “)
print(” | | | | | | | (_| | | | | | |_| | | | | (_| | (_| __/ “)
print(” |_| |_|_| |_|\__,_| |_| |_|\__, | |_| \__,_|\___\___| “)
print(” __/ |”)
print(” |___/”)
print()
print(“Author: Priyam Harsh”)
print()

parser = OptionParser(usage=”Usage: %prog path”,version=”%prog 1.0″)
(options, args) = parser.parse_args()

if len(args) != 1:
parser.error(“Please enter the path to the pictures”)

results = []
cdir = os.getcwd()

if “Registered” in os.listdir():
os.chdir(“Registered”)
regface = (os.listdir())[0]
picture_of_me = face_recognition.load_image_file(regface)
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
my_pics = []
print(“Make sure that your registered face is clear”)
print(“Otherwise the program may not work very accurately”)
print()
print(“Please Wait while we process all your pics”)
else:
print(“No registered face found !!”)
print(“Register your face first.”)
exit()

plist = os.listdir(args[0])
os.chdir(args[0])
print()
for i in plist:
ext = (i.split(“.”))[1]
if ext == “jpg” or ext == “jpeg” or ext == “png”:
print(“Processing -“,i)
unknown_picture = face_recognition.load_image_file(i)
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)
for en in unknown_face_encoding:
results.append(face_recognition.compare_faces([my_face_encoding], en, tolerance=0.45))
for ch in results:
if True in ch:
print(“|”)
print(“|—–> Your face found in this picture !!”)
my_pics.append(i)
results = []

if “my_pictures” in os.listdir():
passs
else:
os.mkdir(“my_pictures”)

for i in my_pics:
shutil.copy(i,”my_pictures”)

os.chdir(cdir)
shutil.rmtree(“Registered”)

 

Register My Face

import cv2
import os
import face_recognition
import shutil

cam = cv2.VideoCapture(0)

r = 0

print()
print(“********** Register Your Face **********”)
print()
n = input(“Enter your name: “)
print()
print(“Getting the camera ready..”)

cv2.namedWindow(“Capture”)
if “Registered” not in os.listdir():
os.mkdir(“Registered”)

os.chdir(“Registered”)

print()
print(“Press Space whenever ready..”)
print(“Press Esc to cancel the registration..”)
print()

while True:
ret, frame = cam.read()
cv2.imshow(“Capture”, frame)
if not ret:
break
k = cv2.waitKey(1)

if k%256 == 27:
# ESC pressed
print(“Escape hit, closing…”)
r = 1
break
elif k%256 == 32:
# SPACE pressed
img_name = “{}.jpg”.format(n)
cv2.imwrite(img_name, frame)
print(“{} written!”.format(img_name))
break

if r is 0:
picture_of_me = face_recognition.load_image_file((n+”.jpg”))
my_face_encoding = face_recognition.face_encodings(picture_of_me)
if len(my_face_encoding) == 0:
print(“We couldn’t recognize any face !”)
print(“Please try again !!”)
shutil.rmtree(“Registered”)
else:
print(“Registration Successful !!”)
elif r is 1:
print(“Registration Cancelled !!”)

cam.release()

 

Requirements

cmake
dlib
face_recognition
opencv-python

 

Watch the full video of the Project:

 

 

 

PROBLEM FACED

While developing this project, I faced some minor problems. I had to do a lot of research on various Python modules such as, face_recognition, os, shutil, cv2. The “cv2” module was required to capture the face using the webcam. The “os” and “shutil” modules were required for handling files and folders. The “face_recognition” module was required for the main job, i.e., recognizing the faces. The quality of captured image matters a lot. Hence, a good-quality webcam is recommended for registering a face.

No matter what minor problems I faced. I enjoyed creating this piece of Python Project and I am more than happy with my creation.

 

 

FUTURE SCOPE

In my opinion, this piece of the program can be developed more and with a lower tolerance value and a good GPU, the program can be used to find any face in an image with a high accurate result and faster processing speed. This piece of code can be used in Crime Investigation, to find face of any culprit in any kind of image. This program will help many people in various ways and it will also save time and money.

 

 

CONCLUSION

In the conclusion, I would like to say that Python is a fun and easy programming language and while creating a project like this, it has not just been a good experience but it also helped in the development of my creativity and logical thinking. I would be more than happy to work on other projects in Python because it’s just amazing to work with Python. The program is working and I hope, it’s also bug-free.

 

Thank you for your attention.

 

 

Highest Selling Technical Courses of Indian Cyber Security Solutions:

Certified Ethical Hacker Training in Bhubaneswar

Ethical Hacking Training in Bhubaneswar

Certified Ethical Hacker Training in Bangalore

Ethical Hacking Training in Bangalore

Certified Ethical Hacker Training in Hyderabad

Ethical Hacking Training in Hyderabad

Python Training in Bangalore

Python Training in Hyderabad

Python Training in Bhubaneswar

Microsoft Azure Training in Hyderabad

Microsoft Azure Training in Bangalore

Microsoft Azure Training in Bhubaneswar

Networking Training in Bangalore

Networking Training in Hyderabad

Networking Training in Bhubaneswar

Advance Python Training in Hyderabad

Advance Python Training in Bangalore

Advance Python Training in Bhubaneswar

Amazon Web Services Training in Hyderabad

Amazon Web Services Training in Bangalore

Amazon Web Services Training in Bhubaneswar

Certified Ethical Hacker Certification – C | EH v10

Computer Forensic Training in Kolkata

Summer Training for CSE, IT, BCA & MCA Students 

Network Penetration Testing training

Ethical Hacking  training

Internet Of Things Training

Data Analysis

Internet Of Things Training Hyderabad

Internet Of Things Training in Bhubaneswar

Internet Of Things Training in Bangalore

Embedded System Training

Digital Marketing Training

Machine Learning Training

Python Programming training

Android Training in Bangalore

Android Training in Hyderabad

Android Training in Bhubaneswar

Diploma in Network Security Training

Android Development  training

Secured Coding in Java

Certified Network Penetration Tester 

Diploma in Web Application Security 

Certified Web Application Penetration Tester 

Certified Android Penetration Tester 

Certified Python Programming 

Advance Python Training 

Reverse Engineering Training  

Amazon Web Services Training  

VMware Training 

 

Cybersecurity services that can protect your company:

Web Security | Web Penetration Testing

Web Penetration Testing Company in Bangalore

Network Penetration Testing – NPT

Network Penetration Testing Service in Bangalore

Android App Penetration Testing

Source Web Development

Source Code Review

Android App Development

Digital Marketing Consultancy

Data Recovery

 

Other Location for Online Courses:

Bhubaneswar

Bangalore

Hyderabad

 

 

 

 

 

 


Show Buttons
Hide Buttons