Image Facial Recognition using Open-CV Python

0
37

OpenCV-Python is a library of Python language which includes various bindings designed to solve computer vision problems. OpenCV is an open source C++ library used for image processing and computer vision applications. However, it is not mandatory for your OpenCV applications to be open or free. Open-CV is meant to be a library of many inbuilt functions mainly aimed at real time image processing.

The abbreviated form of Open-CV is:

Open Source Computer Vision

The list of activities which can be achieved using OpenCV are mentioned follows:
1. Read and write images
2. Detection of faces with its features
3. Detection of various shapes such as Circle, rectangle and many more.
4. Modification of image quality and colors.
5. Development of augmented reality applications.

The various languages supported by Open-CV are mentioned below:
1. C++
2. Java
3. Android
4. Python

OpenCV also includes some key points which are considered as plus points which is given below:

1. Easy to learn and read (includes lots of tutorials)
2. Works with all popular languages
3. Free to use

In this article, we will focus on using OpenCV in python language and for that it is mandatory to get it installed with proper command which is mentioned below:

pip install opencv-python

The output of installation is as follows:

C:\Users\DELL\Desktop\Eduonix\Image-Processing-with-OpenCV\Face-Recognition>pip install opencv-python

Collecting opencv-python

Using cached https://files.pythonhosted.org/packages/6f/88/a75685d7293b321f1a4b20029fd8db0f620c546a88938ffea31e8a7d2df7/opencv_python-3.4.3.18-cp34-cp34m-win_amd64.whl

Requirement already satisfied: numpy>=1.11.1 in c:\python34\lib\site-packages (from opencv-python) (1.14.2)

Installing collected packages: opencv-python

Successfully installed opencv-python-3.4.3.18

Now, we will focus on creating a demonstration of image and facial recognition using OpenCV. The major pre-requisite for this module is an XML file called “haarcascade_frontalface_default.xml”.

A Haar Cascade is peculiar classifier which is used to detect objects from the source. The haarcascade_frontalface_default.xml which will be used in project is a haar cascade designed by OpenCV to detect the frontal face. This cascade works by training the cascade on thousands of negative images with the positive image superimposed on it. The haar cascade can detect features from the source. The contents of this XML file is as follows:

We will import the OpenCV module for creating a face recognition module. In this assignment, we will be creating a face recognition module which captures the images in “Datasets” folder.

Step 1: Import the necessary modules

import cv2

import os

Step 2: Start capturing video and detect object in video stream using Haarcascade Frontal Face. Detect frames of different sizes, list of faces rectangles inside the defined functions.

Step 3: Start looping the face recognition and load it in datasets folder.

Step 4: After loading all the images in dataset, we need to stop video for recording facial recognitions and close all windows.

The output opens the web camera and captures all images which is given below:

images in dataset

The images stored in datasets folder as mentioned below:

stored in datasets

The training of data is analysed in following code:

Conclusion:

When you run this code mentioned in this article, you will see that face values are stored in the mentioned folder called datasets. The algorithm designed is context-aware. To find similar images Convolutional Neural network is being used. We can access all patterns of images with this facial recognition module which helps in maintaining security of devices. OpenCV always proves beneficial in face recognition and eye detection module.

LEAVE A REPLY

Please enter your comment!
Please enter your name here