Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
risi1006 committed Sep 24, 2018
0 parents commit da94dac
Show file tree
Hide file tree
Showing 7 changed files with 33,470 additions and 0 deletions.
Binary file added FaceBase.db
Binary file not shown.
19 changes: 19 additions & 0 deletions IntroToPyCV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
import cv2

detector= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(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:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2);

cv2.imshow('frame',img);
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# face-recognition
50 changes: 50 additions & 0 deletions datasetCreator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import cv2
import sqlite3

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

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


Id=raw_input('enter your id : ')
name=raw_input('Enter your name : ')
insertOrUpdate(Id,name)
sampleNum=0
while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

#incrementing sample number
sampleNum=sampleNum+1
#saving the captured face in the dataset folder
cv2.imwrite("dataSet/User."+Id +'.'+ str(sampleNum) + ".jpg", gray[y:y+h,x:x+w])

cv2.imshow('frame',img)
#wait for 100 miliseconds
if cv2.waitKey(100) & 0xFF == ord('q'):
break
# break if the sample number is morethan 20
elif sampleNum>20:
break
cam.release()
cv2.destroyAllWindows()
46 changes: 46 additions & 0 deletions detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import cv2
import numpy as np
from PIL import Image
import pickle
import sqlite3


recognizer = cv2.createLBPHFaceRecognizer()
recognizer.load('trainner/trainner.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
path='dataSet'
def getProfile(id):
conn=sqlite3.connect("FaceBase.db")
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(0)
font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1)
while True:
ret, im =cam.read()
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray, 1.2,5)
for(x,y,w,h) in faces:
cv2.rectangle(im,(x,y),(x+w,y+h),(0,225,0),2)
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
profile=getProfile(id)
if(profile!=None):
cv2.cv.PutText(cv2.cv.fromarray(im),str(profile[1]), (x,y+h+30),font, (0,225,0));
cv2.cv.PutText(cv2.cv.fromarray(im),str(profile[2]), (x,y+h+60),font, (0,225,0));
cv2.cv.PutText(cv2.cv.fromarray(im),str(profile[3]), (x,y+h+90),font, (0,225,0));




cv2.imshow('im',im);
if cv2.waitKey(10) ==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
Loading

0 comments on commit da94dac

Please sign in to comment.