You are on page 1of 4

Assignment no: 1

Face recognition

Name: KESAV.V
Reg.no: 22617501
Department: B. Tech - IT
Face recogni on
Algorithm:
Step - 1: Install visual studio code with python compiler.

Step - 2: And then import necessary Libraries like Import face_recogni on and cv2 (OpenCV)
libraries.

Step - 3: Try to open webcam to stream live video.

Step - 4: Then save photo in .jpg format in desire loca on and compare using photo vs webcam.

Step - 5: To verify the face. Print name in any where of the screen. If not verified print unknown
person.

Step - 6: A er comple ng the verifica on. Try to draw a square outside of the face from live
webcam.

Step - 7: A er crea ng square print name of the person in top le corner of the square.

Step - 6: Finally check whether the face recogni on is working (or) not by checking the face from the
data base.

Python programming
Main.py
import cv2

from simple_facerec import SimpleFacerec

# Encode faces from a folder

sfr = SimpleFacerec()

sfr.load_encoding_images("images/")

# Load Camera

cap = cv2.VideoCapture(0)

while True:
ret, frame = cap.read()

# Detect Faces

face_loca ons, face_names = sfr.detect_known_faces(frame)

for face_loc, name in zip(face_loca ons, face_names):

y1, x2, y2, x1 = face_loc[0], face_loc[1], face_loc[2], face_loc[3]

cv2.putText(frame, name,(x1, y1 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 200), 2)

cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 200), 4)

cv2.imshow("Frame", frame)

key = cv2.waitKey(1)

if key == 27:

break

cap.release()

cv2.destroyAllWindows()

image_comparison.py
import cv2

from simple_facerec import SimpleFacerec

# Encode faces from a folder

sfr = SimpleFacerec()

sfr.load_encoding_images("images/")

# Load Camera

cap = cv2.VideoCapture(0)

while True:

ret, frame = cap.read()

# Detect Faces

face_locaƟons, face_names = sfr.detect_known_faces(frame)

for face_loc, name in zip(face_locaƟons, face_names):

y1, x2, y2, x1 = face_loc[0], face_loc[1], face_loc[2], face_loc[3]

cv2.putText(frame, name,(x1, y1 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 200), 2)

cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 200), 4)

cv2.imshow("Frame", frame)
key = cv2.waitKey(1)

if key == 27:

break

cap.release()

cv2.destroyAllWindows()

You might also like