Documente Academic
Documente Profesional
Documente Cultură
Submitted To-
Prof. Veluraja. k
PHY: 1999Introduction to Innovative Projects
J-Component
School of Computer Science and Engineering
VIT University
Vellore, Tamil Nadu.
Problem Definition
A general statement of face recognition problem can be formulated as follows:
Given still or video images of a scene, identify or verify one or more persons in the
scene using a stored database of faces. Available collateral information maybe as
race , age, gender, facial expression and speech may be used in narrowing the
search (enhancing recognition)The solution of the problem involves segmentation
of faces (face detection) from cluttered scenes,feature extraction from the face
region,recognition or verification. In identification problems ,the input to the
system is an unknown face, and the system reports back the decided identity from a
database of known individuals, whereas in verification problems , the system needs
to confirm or reject the claimed identity of the input face.So we can say that A
facial recognition system is a technology capable of identifying or verifying a
person from a digital image or a video frame from a video source. There are
multiple methods in which facial recognition systems work, but in general, they
work by comparing selected facial features from given image with faces within a
database. Some face recognition algorithms identify facial features by extracting
landmarks, or features, from an image of the subject's face. For example, an
algorithm may analyze the relative position, size, and/or shape of the eyes, nose,
cheekbones, and jaw. These features are then used to search for other images with
matching features.
Other algorithms normalize a gallery of face images and then compress the face
data, only saving the data in the image that is useful for face recognition. A probe
image is then compared with the face data.[14] One of the earliest successful
systems[15] is based on template matching techniques[16] applied to a set of
salient facial features, providing a sort of compressed face representation.
Recognition algorithms can be divided into two main approaches, geometric,
which looks at distinguishing features, or photometric, which is a statistical
approach that distills an image into values and compares the values with templates
to eliminate variances. Some classify these algorithms into two broad categories:
holistic and feature-based models. The former attempts to recognize the face in its
entirety while the feature-based subdivide into components such as according to
features and analyze each as well as its spatial location with respect to other
features.
ABSTRACT
In this face detection we are using different libraries in python like open cv,pickle
and numpy. We can execute this through the command propmpt or pycharm.These
libraries have different functionalities in code written. Open cv in python can be
used for face detection and face recognition.Face detection has attracted immense
attention because it has many applications in computer vision communication,
automatic control system and even in day to day life. Face detection is a method to
detect a face from an image which have several attributes in that image.This
technique also includes saliency prediction. To do the following work we have
used Python. The most used library that is used in this project is OpenCv. The
following libraries were also used in the completion of the project: Numpy, Pillow
and Pickle.
INTRODUCTION
A human face reveals a great deal of information to a perceiver. It can tell about
mood and intention and attentiveness, but it can also serve to identify a person. Of
course, a person can be identified by other means than the face. Voice, body shape,
gait or even clothing may all establish identity in circumstances where facial detail
may not be available. Nevertheless, a face is the most distinctive and widely used
key to a person’s identity, and the loss of ability to recognize faces experienced by
some neurological (prosopagnosic) patients has a profound effect on their lives.
In the past few years, face recognition owned significant consideration and
appreciated as one of the most promising applications in the field of image
analysis. Face detection can consider a substantial part of face recognition
operations. According to its strength to focus computational resources on the
section of an image holding a face. The method of face detection in pictures is
complicated because of variability present across human faces such as pose,
expression, position and orientation, skin colour, the presence of glasses or facial
hair, differences in camera gain, lighting conditions, and image resolution.
Face Detection is the first and essential step for face recognition, and it is used to
detect faces in the images. It is a part of object detection and can use in many areas
such as security, bio-metrics, law enforcement, entertainment, personal safety, etc.
It is used to detect faces in real time for surveillance and tracking of person or
objects. It is widely used in cameras to identify multiple appearances in the frame
Ex- Mobile cameras and DSLR’s. Facebook is also using face detection algorithm
to detect faces in the images and recognise them.
LITERATURE SURVEY
Face detection is a computer technology that determines the location and size of
human face in arbitrary (digital) image. The facial features are detected and any
other objects like trees, buildings and bodies etc are ignored from the digital image.
It can be regarded as a specific case of object-class detection, where the task is
finding the location and sizes of all objects in an image that belong to a given class.
Face detection, can be regarded as a more general case of face localization. In face
localization, the task is to find the locations and sizes of a known number of faces
(usually one). Basically there are two types of approaches to detect facial part in
the given image i.e. feature base and image base approach. Feature base approach
tries to extract features of the image and match it against the knowledge of the face
features. While image base approach tries to get best match between training and
testing images. We are using feature based approach for the detection and
recognition of images.
Knowledge-Based:-
The knowledge-based method depends on the set of rules, and it is based on human
knowledge to detect the faces. Ex- A face must have a nose, eyes, and mouth
within certain distances and positions with each other. The big problem with these
methods is the difficulty in building an appropriate set of rules. There could be
many false positive if the rules were too general or too detailed. This approach
alone is insufficient and unable to find many faces in multiple images.
Feature-Based:-
.Template Matching:-
Appearance-Based:-
METHODOLOGY
Here we basically took steps forward little by little going through how to work
with the opencv and finding the optimum solutions. We have used python to work
out with it and find the code. First we work out with Opencv that requires
Numpy,pickle also. We first try to work with pictures and how to make them
grayscale. Then we tried to draw on the pictures and put text on them. In this
project, we are going to use the haar cascades first to detect the face in the picture.
These haar cascades are already available with the python package as .xml file
extension. Then we made into yml extension file and trained our program to
recognize the faces of the people and then name them accordingly.
HAAR CASCADES
Haar features are similar to these convolution kernels which is used to detect the
presence of certain feature in an image. Each feature will give a single value result
which is calculated by subtracting the sum of the pixels under white rectangle from
that of the pixels under black rectangle. This algorithm uses a 24X24 window as
the base window size to start evaluating these features in any image. If we consider
all the features of haar features like position, scale and type we will end up
calculating 160000+ features in window.
SPEECH RECOGNITION:
Here we are doing speech recognition where we are taking in the audio and
converting to text. We are doing so by using a built in library in python, which
helps us to convert speech into text. Below is the explaanation how things work in
this pyttsx module. An application invokes the pyttsx3.init() factory function to get
a reference to a pyttsx3.Engine instance. During construction, the engine initializes
a pyttsx3.driver.DriverProxy object responsible for loading a speech engine driver
implementation from the pyttsx3.drivers module. After construction, an application
uses the engine object to register and unregister event callbacks; produce and stop
speech; get and set speech engine properties; and start and stop event loops.
INSTALLATIONS
On windows opencv can be installed through the following command---pip
install opencv –python
The required modules will be installed through the above commands.To avoid the
conflicts while installing opencv is to uninstall the manually installed modules in
the root of python’s site packages.We should not install multiple packages in same
environment. If there are multiple packages in same environment,uninstall them
with “pip uninstall” command and reinstall.
LIBRARIES
OPEN CV:
Open source computer vision library.
OpenCV is a library of programming functions mainly aimed at real-time
computervision.
Originally developed by Intel, it was later supported by Willow Garage then
Itseez.
The library is cross-platform and free for use under the open-source BSD
license.
It has C++, Python and Java interfaces and supports Windows, Linux, Mac
OS, iOSand Android.
Open cv supports deep learning frame work, tensor flow torch and
pytorchetc.
Open cv applications include Human computer interaction,Ego
motionestimation,facial recognition system,facial recognition system,mobile
robotics and augmented reality etc.
OpenCV is written in C++ and its primary interface is in C++, but it still
retains a lesscomprehensive though extensive older C interface. There are
bindingsin Python, Java and MATLAB/OCTAVE.
NUMPY LIBRARY
SOFTWARE REQUIREMENTS
Pycharm
Opencv
Pillow
Cx_Oracle
Pyttsx3
Flow Chart
Code
import cv2
import numpy as np
from PIL import Image
import os
import pyttsx3
import time
import mysql.connector
import pytesseract
#from subprocess import call
con=mysql.connector.connect(
user="root",
password="karthikvajja",
host="127.0.0.1",
database="face",
auth_plugin="mysql_native_password"
)
cur = con.cursor()
listdata=list()
cur.execute("select * from comp_vis")
for i in cur:
listdata.append(i)
id=len(listdata)
def mouse():
#os.system(r"cd C:\Users\Intel\AppData\Local\Programs\Python\Python37-32>")
os.system(r"C:\Users\Intel\AppData\Local\Programs\Python\Python37-32\python
C:/Users/Intel/Desktop/mouse.py")
# os.system("python C:/Users/Intel/Desktop/mouse.py")
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Intel\Anaconda3\pkgs\tesseract.exe"
text1 = pytesseract.image_to_string(Image.open(r"C:\Users\Intel\Desktop\thres1.png"))
engine = pyttsx3.init()
engine.say(text1)
engine.runAndWait()
def ocr():
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Intel\Anaconda3\pkgs\tesseract.exe"
engine = pyttsx3.init()
engine.say("Do you want to convert a part of a image")
engine.runAndWait()
print("Do you want to convert a part of a image")
g=speech()
if g=="no":
destdir = 'C:/users/Intel/Desktop/'
files = [ f for f in os.listdir(destdir) if os.path.isfile(os.path.join(destdir,f)) ]
for f in files:
if f.endswith(".jpg"):
print(f)
elif f.endswith(".png"):
print(f)
k=str(input("Enter the name of the file : "))
image = cv2.imread(r'C:/Users/Intel/Desktop/' + k)
text = pytesseract.image_to_string(Image.open(image))
print(text)
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
elif g=="yes":
while True:
mouse()
engine = pyttsx3.init()
engine.say("Do you want to continue ?")
engine.runAndWait()
h=speech()
if h=="no":
break
else:
engine.say("Sorry could not understand you !")
engine.runAndWait()
ocr()
def speech():
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
try:
print("You said: " + r.recognize_google(audio))
return r.recognize_google(audio)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service;
{0}".format(e))
def create_db():
engine = pyttsx3.init()
engine.setProperty("rate",200)
face_cascade = cv2.CascadeClassifier('C:/pro_/face/haarcascade_frontalface_default.xml')
global listdata
cap = cv2.VideoCapture(0)
global id
id=len(listdata)
id+=1
l=[]
l.append(id)
l.append(input('Registration number:'))
sampleN=sampleN+1;
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.waitKey(100)
cv2.imshow('img',img)
cv2.waitKey(1)
break
cap.release()
cv2.destroyAllWindows()
path = 'C:/pro_/faces'
recognizer = cv2.face.LBPHFaceRecognizer_create()
detector = cv2.CascadeClassifier("C:/pro_/face/haarcascade_frontalface_default.xml");
def getImagesAndLabels(path):
PIL_img = Image.open(imagePath).convert('L')
img_numpy = np.array(PIL_img,'uint8')
id = int(os.path.split(imagePath)[-1].split(".")[1])
faces = detector.detectMultiScale(img_numpy)
return faceSamples,ids
def train():
print ("\n [INFO] Training faces. It will take a few seconds. Wait ...")
faces,ids = getImagesAndLabels(path)
recognizer.train(faces, np.array(ids))
recognizer.write('C:/pro_/trash.yml')
print("\n [INFO] {0} faces trained. Exiting Program".format(len(np.unique(ids))))
def see():
global listdata
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('C:/pro_/face/trainer.yml')
cascadePath = "C:/pro_/face/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
font = cv2.FONT_HERSHEY_SIMPLEX
id = 0
cam = cv2.VideoCapture(0)
cam.set(3, 640)
cam.set(4, 480)
minW = 0.1*cam.get(3)
minH = 0.1*cam.get(4)
c=0
c1=0
x1=0
while True:
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor = 1.2,
minNeighbors = 5,
minSize = (int(minW), int(minH)),
)
for(x,y,w,h) in faces:
create_db()
engine = pyttsx3.init()
engine.setProperty("rate",200)
engine.say("Training Data, I am almost ready.")
engine.runAndWait()
train()
listdata =list(cur.execute("select * from comp_vis"))
engine.say("Nice to meet you"+listdata[len(listdata)-1][1])
engine.runAndWait()
c=0
see()
print(str(id))
cv2.putText(img, str(id), (x+5,y-5), font, 1, (255,255,255), 2)
cv2.putText(img, str(confidence), (x+5,y+h-5), font, 1, (255,255,0), 1)
cv2.imshow('camera',img)
print(listdata)
while 1:
see()
Conclusion
Thus we have used python and its libraries successfully for face detection or face
recognition. If a person goes in front of the web cam, the system will read out its
name and if it is not able to detect the person then it will get access of the images
to detect that person. This can be developed in to apps or webpage or can be used
in security systems in public places. This can also be used to monitor the drivers to
reduce the number of accidents and also can be implemented in attendance system.
The second part of our project reads out the name of the file or the image that a
user opens on the system.