-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit da94dac
Showing
7 changed files
with
33,470 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# face-recognition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.