You are on page 1of 18

Automatic Facebook

login with Face


recognition

Presented By
C J Saikiran
Outline

• About project
• Introduction
• Flow chart
• Libraries and classifier used
• Training the model
• Face detection
• Face recognition
• Facebook login
• Source code
About project

This project is about Face recognition system using


machine learning Python.
Here we trained a model by providing a set of images
and its labels.
Now the model predicts the label of the given image
and display the output.
If it finds the correct user then it waits for the user
command and automatically login to user's Facebook
account.
Introduction

Face is an important part of who we are and how people


identify us. It is arguably a person's most unique physical
characteristic. While humans have had the innate ability
to recognize and distinguish different faces for millions of
years, computers are just now catching up.
Face recognition is probably one of the most non-
intrusive and user-friendly biometric authentication
methods currently available; a screensaver equipped with
face recognition technology can automatically unlock the
screen whenever the authorized user approaches the
computer.
Flow chart

Importing libraries Reading the images

Face detection Training the model

Face recognition
and output Facebook login
prediction
Import libraries

For face recognition we used opencv,numpy,os libraries and for Facebook


login we used selenium library.
#code:
import cv2
import selenium
Libraries
import numpy as np
from os import listdir
from os.path import join
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Training the model:

Initially we saved all the training data in a file.


File location:"C:/Users/hp/PycharmProjects/images/"
Now we train the model by providing location of training data.
#code:
training=[]
label=[]
for i in listdir(data_path):
x=join(data_path,i)
for j in listdir(x):
image_path=join(x,j)
image=cv2.imread(image_path,cv2.IMREAD_GRAYSCALE)
training.append(np.asarray(image,dtype=np.uint8))
label.append(int(i))
Face detection:

For face detection


opencv cascade
Classifier is used.
Size of each frame is
resized to 512*512.
When face is detected a
rectangular block is
displayed.
Face recognition:

Classifier used:LBPHFaceRecognizer
By using this Classifier model is trained.
This classifier returns the label and confidence
value.The accuracy of output depends on confidence
value.
#code:
model=cv2.face.LBPHFaceRecognizer_create()
model.train(training,np.asarray(label))
Facebook login:

Webdriver used: Chrome()


Executable path:"C:\Users\hp\PycharmProjects\untitled\venv\Lib\
site-packages\chromedriver_win32\chromedriver.exe"
Website:"https://www.facebook.com"
#code:
driver = webdriver.Chrome()
driver.get("https://www.facebook.com")
element = driver.find_element_by_id('email')
element.send_keys("XXXXXX")
element = driver.find_element_by_id('pass')
element.send_keys("XXXXXX")
Source code:

import cv2
import selenium
import numpy as np
from os import listdir
from os.path import join
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
as EC
def face_detect(img):
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray=cv2.resize(gray,(512,512))
faces=face_recog.detectMultiScale(gray,1.1,4)
if len(faces)==0:
return img,[],100,200,0,0
for x,y,w,h in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),1)
roi=img[y:y+h,x:x+w]
roi=cv2.resize(roi,(512,512))
return img,roi,x,y,w,h
def detect(photo):
try:
photo=cv2.cvtColor(photo,cv2.COLOR_BGR2GRAY)
result=model.predict(photo)
if result[1]<500:
con=100*(1-(result[1]/300))
if con>80:
output=d[result[0]]
else:
output="unknown"
except:
output="face not found"
finally:
return output
def facebook():
driver = webdriver.Chrome(
executable_path=r"C:\Users\hp\PycharmProjects\
untitled\venv\Lib\site-packages\chromedriver_win32\
chromedriver.exe")
driver.get("https://www.facebook.com")
element = driver.find_element_by_id('email')
element.send_keys("XXXXXX")
element = driver.find_element_by_id('pass')
element.send_keys("XXXXXX")
element.send_keys(Keys.RETURN)
data_path=r"C:/Users/hp/PycharmProjects/images/"
d={0:'saikiran',1:'gopi',2:'varun',3:'sravya'}
training=[]
label=[]
for i in listdir(data_path):
x=join(data_path,i)
for j in listdir(x):
image_path=join(x,j)
image=cv2.imread(image_path,cv2.IMREAD_GRAYSCALE)
training.append(np.asarray(image,dtype=np.uint8))
label.append(int(i))
training=np.asarray(training)
label=np.asarray(label)
model=cv2.face.LBPHFaceRecognizer_create()
model.train(training,np.asarray(label))
cap=cv2.VideoCapture(0)
com=1
face_recog=cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
while(1):
ret,frame=cap.read()
frame=cv2.resize(frame,(512,512))
image,face,x,y,w,h=face_detect(frame)
font=cv2.FONT_HERSHEY_COMPLEX
text=detect(face)
cv2.putText(frame,text,(x,y),font,2,(0,255,255),1)
cv2.imshow('image',frame)
if text=="saikiran" and com==0:
txt="Do you want to login FB??"
cv2.putText(frame, txt, (0,100), font, 0.5, (0, 255, 255), 1)
cv2.imshow('image',frame)
key=cv2.waitKey(5000)
if key==ord('f'):
facebook()
com=1
else:
com=1
k=cv2.waitKey(1)
if k==27:
break
elif k==ord('a'):
com=0
cap.release()
cv2.destroyAllWindows()
Thank You

You might also like