Real Time Face Recognition

A real time face recognition system is capable of identifying or verifying a person from a video frame. To recognize the face in a frame, first you need to detect whether the face is present in the frame. If it is present, mark it as a region of interest (ROI), extract the ROI and process it for facial recognition.

How Face Detection Algorithm Work

Traditional algorithms involving face recognition work by identifying facial features by extracting features, or landmarks, from the image of the face. For example, to extract facial features, an algorithm may analyse the shape and size of the eyes, the size of nose, and its relative position with the eyes

What Is openCV

OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. In simple language it is library used for Image Processing. It is mainly used to do all the operation related to Images.

Import Libraries

library(devtools)
library(opencv)
library(psych)

Find Faces And Eyes In A Picture Using ocv_video Function

ocv_video(ocv_face)

Various Arguments Of ocv_video Funtion

ocv_video(ocv_edges)
ocv_video(ocv_knn)
ocv_video(ocv_facemask)
ocv_video(ocv_mog2)
ocv_video(ocv_stylize)
ocv_video(ocv_sketch)

Overlay Face Filter With A Plot

test <- ocv_picture()
bitmap <- ocv_bitmap(test)
str(bitmap)
width <- dim(bitmap)[2]
height <- dim(bitmap)[3]
png('bg.png',width = width,height = height)
data('iris')
print(pairs.panels(iris[1:4],gap=0,pch=21,bg=c("red","green","blue")[iris$Species]))
ocv_read("bg.png")
ocvVideo <- ocv_video(function(input){
  mask <- ocv_facemask(input)
  ocv_copyto(input,bg,mask)})

Read Picture And Recognize face

pic1 <- ocv_read("faces.jpg")
pic2 <- ocv_read("face1.png")
pic3 <- ocv_read("face2.png")
face1 <- ocv_face(pic1)
face2 <- ocv_face(pic2)
face3 <- ocv_face(pic3)
save1 <- ocv_write(face1,'opcv1.png')
save2 <- ocv_write(face2,'opcv2.png')
save3 <- ocv_write(face3,'opcv3.png')

Get Face Location Data

facemask1 <- ocv_facemask(pic1)
facemask2 <- ocv_facemask(pic2)
m1 <- ocv_write(facemask1,'mask1.jpg')
m2 <- ocv_write(facemask2,'mask2.jpg')
knitr::include_graphics("mask1.jpg")

knitr::include_graphics("mask2.jpg")