Professional Documents
Culture Documents
TECHNOLOGY USED-
Introduction of Python: Python is an interpreted high-level general-purpose
programming language. Its design philosophy emphasizes code
readability with its use of significant indentation. Its language constructs as
well as its object-oriented approach aim to help programmers write clear,
logical code for small and large-scale projects. 4 Python is dynamically-
typed and garbage-collected. It supports multiple programming
paradigms, including structured (procedural), object-oriented and
functional programming. It is often described as a "batteries included"
language due to its comprehensive standard library. Guido van Rossum
began working on Python in the late 1980s, as a successor to the ABC
programming language, and first released it in 1991 as Python 0.9.0. Python
2.0 was released in 2000 and introduced new features, such as list
comprehensions and a cycle-detecting garbage collection system (in
addition to reference counting). Python 3.0 was released in 2008 and was a
major revision of the language that is not completely backward -
compatible. Python 2 was discontinued with version 2.7.18 in 2020. Python
consistently ranks as one of the most popular programming languages.
The objective of Python is to increase the productivity of programmers
rather than focusing on the code they write. Currently, the uses of Python
are for websites and web development, desktop GUI applications
development, automation scripts, complex calculation systems, life
support management systems, Games, Robotics, Scientific Computing,
Natural Learning Language and many more. It is designed with features to
facilitate data analysis and visualization. It is and can be used in any kind
of industry such as social media, IT, education, Finance & Accounts, etc.
The top 8 companies that encourage and widely use Python are Google,
Facebook, Instagram, Spotify, Quora, Netflix, Dropbox and Reddit. Python is
meant to be an easily readable language. Its formatting is visually
uncluttered, and it often uses English keywords where other languages use
punctuation. Unlike many other languages, it does not use curly brackets
to delimit blocks, and semicolons after statements are allowed but are
rarely, if ever, used. It has fewer syntactic exceptions and special cases
than C or Pascal. Below are some facts about Python Programming
Language:•Python is currently the most widely used multipurpose, high-
level programming language. Python allows programming in Object-
Oriented and Procedural paradigms.
INSTALLATION-
Installation of Python on various operating systems.
Step - 2: Click on the Install Now Double-click the executable file, which is
downloaded; the following window will open. Select Customize installation
and proceed. Click on the Add Path check box, it will set the Python path
automatically. We can also click on the customize installation to choose
desired location and features. Another important thing is installed launcher
for the all user must be checked.
Software Requirements:
Let’s tackle this problem one step at a time. For each step,
we’ll learn about a different machine learning algorithm. I’m
not going to explain every single algorithm completely to
keep this from turning into a book, but you’ll learn the main
ideas behind each one and you’ll learn how you can build
your own facial recognition system in Python
using OpenFace and dlib.
Looking at just this one pixel and the pixels touching it, the image is getting darker
towards the upper right.
If you repeat that process for every single pixel in the image,
you end up with every pixel being replaced by an arrow.
These arrows are called gradients and they show the flow
from light to dark across the entire image:
But saving the gradient for every single pixel gives us way
too much detail. We end up missing the forest for the trees. It
would be better if we could just see the basic flow of
lightness/darkness at a higher level so we could see the
basic pattern of the image.
Now that we know were the eyes and mouth are, we’ll simply
rotate, scale and shear the image so that the eyes and
mouth are centered as best as possible. We won’t do any
fancy 3d warps because that would introduce distortions
into the image. We are only going to use basic image
transformations like rotation and scale that preserve
parallel lines (called affine transformations):
Now no matter how the face is turned, we are able to center
the eyes and mouth are in roughly the same position in the
image. This will make our next step a lot more accurate.
If you want to try this step out yourself using Python and dlib,
here’s the code for finding face landmarks and here’s
the code for transforming the image using those landmarks.
So let’s try out our system. First, I trained a classifier with the
embeddings of about 20 pictures each of Will Ferrell, Chad
Smith and Jimmy Falon:
Pro-tip: If you are using Docker on OSX, you can make your OSX /Users/
folder visible inside a docker image like this:
Step 1
Make a folder called
.
/training-images/ inside the openface folder.
mkdir training-images
Step 2
Make a subfolder for each person you want to recognize. For example:
mkdir ./training-images/will-ferrell/
mkdir ./training-images/chad-smith/
mkdir ./training-images/jimmy-fallon/
Step 3
Copy all your images of each person into the correct sub-folders. Make
sure only one face appears in each image. There's no need to crop the
image around the face. OpenFace will do that automatically.
Step 4
Run the openface scripts from inside the openface root directory:
• If you get bad results, try adding a few more pictures of each person
in Step 3 (especially picures in different poses).
• This script will always make a prediction even if the face isn't one it
knows. In a real application, you would look at the confidence score
and throw away predictions with a low confidence since they are
most likely wrong.
SOURCE CODE:
Python
1 import cv2
2 import numpy as np
3 import face_recognition
4 import os
5 from datetime import datetime
6 # from PIL import ImageGrab
7
8 path = 'ImagesAttendance'
9 images = []
10classNames = []
11myList = os.listdir(path)
12print(myList)
13for cl in myList:
14curImg = cv2.imread(f'{path}/{cl}')
15images.append(curImg)
16classNames.append(os.path.splitext(cl)[0])
17print(classNames)
18
19def findEncodings(images):
20encodeList = []
21for img in images:
22img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
23encode = face_recognition.face_encodings(img)[0]
24encodeList.append(encode)
25return encodeList
26
27def markAttendance(name):
28with open('Attendance.csv','r+') as f:
29myDataList = f.readlines()
30nameList = []
31for line in myDataList:
32entry = line.split(',')
33nameList.append(entry[0])
34if name not in nameList:
35now = datetime.now()
36dtString = now.strftime('%H:%M:%S')
37f.writelines(f'n{name},{dtString}')
38
39#### FOR CAPTURING SCREEN RATHER THAN WEBCAM
40# def captureScreen(bbox=(300,300,690+300,530+300)):
41# capScr = np.array(ImageGrab.grab(bbox))
42# capScr = cv2.cvtColor(capScr, cv2.COLOR_RGB2BGR)
43# return capScr
44
45encodeListKnown = findEncodings(images)
46print('Encoding Complete')
47
48cap = cv2.VideoCapture(0)
49
50while True:
51success, img = cap.read()
52#img = captureScreen()
53imgS = cv2.resize(img,(0,0),None,0.25,0.25)
54imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
55
56facesCurFrame = face_recognition.face_locations(imgS)
57encodesCurFrame = face_recognition.face_encodings(imgS,facesCurFrame)
58
59for encodeFace,faceLoc in zip(encodesCurFrame,facesCurFrame):
60matches = face_recognition.compare_faces(encodeListKnown,encodeFace)
61faceDis = face_recognition.face_distance(encodeListKnown,encodeFace)
62#print(faceDis)
63matchIndex = np.argmin(faceDis)
64
65if matches[matchIndex]:
66name = classNames[matchIndex].upper()
67#print(name)
68y1,x2,y2,x1 = faceLoc
69y1, x2, y2, x1 = y1*4,x2*4,y2*4,x1*4
70cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
71cv2.rectangle(img,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
72cv2.putText(img,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2)
73markAttendance(name)
74
75cv2.imshow('Webcam',img)
76cv2.waitKey(1)
Output-
CONCLUSION –