Face Recognition

This project is used on the IoT and places of security that are important for identifying people.

This project was built as the final deliverable for our Embedded System course.

Introduction

In this project we are using OpenCv in Raspberry Pi. Get the image from the Raspberry Pi camera and face detection from non-face by the “Haar Casecade Classifier” and detect familiar faces and distinguish them from unfamiliar faces (face recognition).

The first thing to do is install OpenCV.

Attach the Raspberry Pi Camera Module. Go to Raspi-config from the terminal and switch camera interface on.

The installation steps for python OpenCv3 on Raspberry Pi:

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot
sudo apt-get install \ libjpeg-dev \ libtiff5-dev \ libjasper-dev \ libpng12-dev \ libavcodec-dev \ libavformat-dev \ libswscale-dev \ libeigen3-dev \ libxvidcore-dev libx264-dev \ libgtk2.0-dev 
sudo apt-get install libatlas-base-dev gfortran

Face detection

First, the Raspberry Pi camera is activated, and then the faces of the people who are in front of the camera are identified. Using the “Haar Cascade Classifier” identifies the human face. By a rectangle drawn around the face.

Face recognition

To identify familiar from unfamiliar people, we need a database of photographs of the people we introduce, and then using the identifier we give the person, the person is identified and the person's name displayed.

Use Telegram-Bot

We create a Telegram-Bot and inset the “token” and the “chat_id” to the program.

And write the code to send the photo when a face is detected, send an image to the Telegram-Bot.

Code

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import telegram
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(320, 240))
face_cascade = cv2.CascadeClassifier(‘/home/pi/opencv-3.2.0/data/haarcascades/haarcascade_frontalface_default.xml')
rec = cv2.face.createLBPHFaceRecognizer()
id = 0
font = cv2.FONT_HERSHEY_SIMPLEX
time.sleep(0.1)

for frame in camera.capture_continuous(rawCapture, format=”bgr”, use_video_port=True):
image = frame.array
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)

for(x, y, w, h) in faces:
    image = cv2.rectangle(image,(x, y), (x+w, y+h), (255, 0, 0), 2)
    id, conf = rec.predict(gray[y:y+h, x:x+w])
    if(id == 1):
        id = "negar"

    elif(id == 2):
        id = "professoraerabi"

    cv2.putText(image, str(id), (x,y+h), font, 2, (255,255,255), 3)
          n()




cv2.imshow("Frame", image)
key = cv2.waitKey(100) & 0xFF
rawCapture.truncate(0)
if key == ord("q"):
     break

Source: Face Recognition


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top