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)
INDEX
- Introduction
- Project Ideas
- Problem Faced
- Future Scope
- Reference
- 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”.
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:
Amazon Web Services Training in Hyderabad
Amazon Web Services Training in Bangalore
Amazon Web Services Training in Bhubaneswar
Summer Training for CSE, IT, BCA & MCA Students
Network Penetration Testing training
Certified Network Penetration Tester
Diploma in Web Application Security
Certified Web Application Penetration Tester
Certified Android Penetration Tester
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
Other Location for Online Courses: