Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataBase Support Added face recognition database isssue #1363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions face_recognition/Database-Connection face recognition/Text
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
I have generated a code for upadting values into data base from cmd into
sqlite while face recognition just first download the sqlite and then form the database file into
into same folder and then connect all required data connection into it your code.



And for displaying everthing images from your database on the images recognition go detector.py
and see the code check it out!!!!!!
63 changes: 63 additions & 0 deletions face_recognition/Database-Connection face recognition/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import cv2
import numpy as np
import sqlite3

# Load the cascade
from Tools.scripts.treesync import raw_input

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# To capture video from webcam.
cap = cv2.VideoCapture(0)
# To use a video file as input
# cap = cv2.VideoCapture('filename.mp4')


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:
cmd="INSERT INTO People(ID,NAME) Values("+str(Id)+","+str(Name)+")"

conn.execute(cmd)
conn.commit()
conn.close()

id = raw_input('enter user id')
name = raw_input('enter your name')
insertOrupdate(id,name)
sampleNum = 0

while True:
# Read the frame
_, img = cap.read()

# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)

# Draw the rectangle around each face
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('img', img)
cv2.waitKey(1)

if (sampleNum>20):
break

# Release the VideoCapture object
cap.release()
cv2.destroyAllWindows()
51 changes: 51 additions & 0 deletions face_recognition/Database-Connection face recognition/detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from sqlite3.dbapi2 import Cursor
import cv2
import numpy as np
from PIL import Image
import pickle
import sqlite3


recognizer= cv2.createLBPHFaceRecognizer()
recognizer.load('trainner/trainner.yml')
cascadePath="Classifiers/face.xml"
faceCascade=cv2.CascadeClassifier(cascadePath)
path='dataset'



def getProfile(id):
conn=sqlite3.connect("faceBase.py")
cmd="SELECT * FROM People WHERE ID="+str(id)
cursor=conn.execute(cmd)
profile=None
for row in cursor:
profile=row
conn.close()
return profile


cam=cv2.VideoCapture(1)
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1,0, 1, 1)

while(True):
ret,img=cam.read()
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5, minSize=(100,100), flags=cv2.CASCADE_SCALE_IMAGE)
for (x,y,w,h) in faces:
sampleNum=sampleNum+1
cv2.imwrite("dataset/user."+id+'.'+str(sampleNum)+"jpg",gray[y:y+h,x:x+w])
cv2.rectangle(im , (x-50,y-50), (x+w+50,y+h+50),(225,0,0),2)

cv2.imshow('im',im)
cv2.waitKey(100)
if sampleNum>20:
cam.realease()
cv2.destroyAllWindows()
break