Face recognization using Open cv python with SQLite Database
Hey whats up guys ;) I know that you are very exited for deep learning :D
Details about Face recognization and SQLite Database
Thanks to OpenCV, coding facial recognition is now easier than ever. There are three easy steps to computer coding facial recognition, which are similar to the steps that our brains use for recognizing faces.
These steps are:
01:Data Gathering: Gather face data (face images in this case) of the persons you want to identify.
02:Train the Recognizer: Feed that face data and respective names of each face to the recognizer so that it can learn.
03:Recognition: Feed new faces of that people and see if the face recognizer you just trained recognizes them.
First Download SQLite Studio For python: https://sqlitestudio.pl/index.rvt?act=download
After download you may goto download folder and extract the tools and click SQLiteStudio
Then create database and create column of the table and set all attribute whatver you want.
Follow this step now:
import numpy as np
import cv2
import sqlite3
cap = cv2.VideoCapture(0)
detector= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def insertOrUpdate(Id,Name):
conn=sqlite3.connect("FaceBase.db")
cmd="SELECT * FROM People WHERE ID="+str(Id)
cursor=conn.execute(cmd)
isRecordExist=0
for row in cursor:
isRecordExist=1
if(isRecordExist==1):
cmd="UPDATE people SET Name=' "+str(name)+" ' WHERE ID="+str(Id)
else:<br>
cmd="INSERT INTO people(ID,Name) Values("+str(Id)+",' "+str(name)+" ' )"<br>
conn.execute(cmd)<br>
conn.commit()<br>
conn.close()<br>
id=raw_input('enter user id')
name=raw_input('enter your name')
insertOrUpdate(id,name)
sampleNum=0;
while(True):
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
sampleNum=sampleNum+1;
cv2.imwrite("dataSet/User."+str(id)+"."+str(sampleNum)+".jpg",gray[y:y+h,x:x+w])
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.waitKey(100);
cv2.imshow('Face',img)<br>
cv2.waitKey(1);<br>
if(sampleNum>20):<br>
break<br>
cap.release()
cv2.destroyAllWindows()