Commit 9a5fa5c7 authored by Ajayguru Madu's avatar Ajayguru Madu

Revert "Merge branch 'surya' into 'master'"

This reverts merge request !1
parent 251ca998
Pipeline #20217 failed with stages
in 14 seconds
File added
# Logbook using Face Recognition
import os
import cv2
import numpy as np
from PIL import Image
#recognizer=cv2.createLBPHFaceRecognizer();
recognizer=cv2.face.LBPHFaceRecognizer_create();
path='dataSet'
def getImagesWithID(path):
imagepaths=[os.path.join(path,f) for f in os.listdir(path)]
faces=[]
IDs=[]
for imagepath in imagepaths:
faceImg=Image.open(imagepath).convert('L');
faceNp=np.array(faceImg,'uint8')
ID=int(os.path.split(imagepath)[-1].split('.')[1])
faces.append(faceNp)
IDs.append(ID)
cv2.imshow("training",faceNp)
cv2.waitKey(10)
return np.array(IDs),faces
IDs,faces=getImagesWithID(path)
recognizer.train(faces,IDs)
recognizer.save('recognizer/trainningData.yml')
cv2.destroyAllWindows()
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index(name=None):
return render_template('index.html',name=name)
@app.route('/exec')
def parse(name=None):
import face_recognize
print("done")
return render_template('index.html',name=name)
@app.route('/exec2')
def parse1(name=None):
import create_data
print("done")
return render_template('index.html',name=name)
if __name__ == '__main__':
app.run()
app.debug = True
runtime: python27
api_version: 1
threadsafe: true
\ No newline at end of file
import cv2
import numpy as np
import sqlite3
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
def insertOrUpdate(Id,Name,Age,Gen,CR):
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)
cmd2="UPDATE People SET Age="+str(Age)+"WHERE ID="+str(Id)
cmd3="UPDATE People SET Gender="+str(Gen)+"WHERE ID="+str(Id)
cmd4="UPDATE People SET CR="+str(CR)+"WHERE ID="+str(Id)
else:
cmd="INSERT INTO People(ID,Name,Age,Gender,CR) Values("+str(Id)+","+str(Name)+","+str(Age)+","+str(Gen)+","+str(CR)+")"
cmd2=""
cmd3=""
cmd4=""
conn.execute(cmd)
conn.execute(cmd2)
conn.execute(cmd3)
conn.execute(cmd4)
conn.commit()
conn.close()
Id=raw_input('Enter User Id')
name=raw_input('Enter User Name')
age=raw_input('Enter User Age')
gen=raw_input('Enter User Gender')
cr=raw_input('Enter User Criminal Records')
insertOrUpdate(Id,name,age,gen,cr)
sampleNum=0
while(True):
ret,img=cam.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.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),(0,255,0),2)
cv2.waitKey(100);
cv2.imshow("Face",img);
cv2.waitKey(1);
if(sampleNum>20):
break;
cam.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
import sqlite3
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
def insertOrUpdate(Id,Name,Dept,IDno):
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
#Enter User University ID number 160040717
#Traceback (most recent call last):
# File "database.py", line 32, in m
if(isRecordExist==1):
cmd="UPDATE People SET name="+str(name)+"WHERE ID="+str(Id)
cmd2="UPDATE People SET Dept="+str(Dept)+"WHERE ID="+str(Id)
cmd3="UPDATE People SET IDno="+str(IDno)+"WHERE ID="+str(Id)
else:
cmd="INSERT INTO People(Id,Name,Dept,IDno) Values("+str(Id)+","+str(name)+","+str(Dept)+","+str(IDno)+")"
cmd2=""
cmd3=""
cmd4=""
conn.execute(cmd)
conn.execute(cmd2)
conn.execute(cmd3)
conn.execute(cmd4)
conn.commit()
conn.close()
Id=raw_input('Enter User Id')
name=raw_input('Enter User Name')
Dept=raw_input('Enter User Department')
IDno=raw_input('Enter User University ID number ')
#insertOrUpdate(Id,name,Dept,IDno)
sampleNum=0
while(True):
ret,img=cam.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.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),(0,255,0),2)
cv2.waitKey(100);
cv2.imshow("Face",img);
cv2.waitKey(1);
if(sampleNum>20):
break;
cam.release()
cv2.destroyAllWindows()
This diff is collapsed.
import cognitive_face as CF
from global_variables import personGroupId
import os, urllib
import sqlite3
from openpyxl import Workbook, load_workbook
from openpyxl.cell import get_column_letter, Cell, column_index_from_string
import time
#get current date
currentDate = time.strftime("%d_%m_%y")
wb = load_workbook(filename = "reports.xlsx")
sheet = wb.get_sheet_by_name('Cse15')
def getDateColumn():
for i in range(1, len(sheet.rows[0]) + 1):
col = get_column_letter(i)
if sheet.cell('%s%s'% (col,'1')).value == currentDate:
return col
Key = '222bf86ba9634534a995d3eed09dc857'
CF.Key.set(Key)
connect = connect = sqlite3.connect("Face-DataBase")
c = connect.cursor()
attend = [0 for i in range(60)]
currentDir = os.path.dirname(os.path.abspath(__file__))
directory = os.path.join(currentDir, 'Cropped_faces')
for filename in os.listdir(directory):
if filename.endswith(".jpg"):
imgurl = urllib.pathname2url(os.path.join(directory, filename))
res = CF.face.detect(imgurl)
if len(res) != 1:
print("No face detected.")
continue
faceIds = []
for face in res:
faceIds.append(face['faceId'])
res = CF.face.identify(faceIds, personGroupId)
print(filename)
print(res)
for face in res:
if not face['candidates']:
print("Unknown")
else:
personId = face['candidates'][0]['personId']
c.execute("SELECT * FROM Students WHERE personID = ?", (personId,))
row = c.fetchone()
attend[int(row[0])] += 1
print(row[1] + " recognized")
#print row[1] + " recognized"
time.sleep(6)
for row in range(2, len(sheet.columns[0]) + 1):
rn = sheet.cell('A%s'% row).value
if rn is not None:
rn = rn[-2:]
if attend[int(rn)] != 0:
col = getDateColumn()
sheet['%s%s' % (col, str(row))] = 1
wb.save(filename = "reports.xlsx")
#currentDir = os.path.dirname(os.path.abspath(__file__))
#imgurl = urllib.pathname2url(os.path.join(currentDir, "1.jpg"))
#res = CF.face.detect(imgurl)
#faceIds = []
#for face in res:
# faceIds.append(face['faceId'])
#res = CF.face.identify(faceIds,personGroupId)
# for face in res:
# personName = CF.person.get(personGroupId, face['candidates']['personId'])
# print personName
#print res
File added
import cv2
import numpy as np
import sqlite3
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
#rec=cv2.createLBPHFaceRecognizer();
rec=cv2.face.LBPHFaceRecognizer_create()
#rec.read('recognizer/trainningData.yml')
#face-trainner.yml
rec.read('recognizer/face-trainner.yml')
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_COMPLEX,0.4,1,0,1)
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
while(True):
ret,img=cam.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.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)
id,conf=rec.predict(gray[y:y+h,x:x+w])
profile=getProfile(id)
if(profile!=None):
cv2.cv.PutText(cv2.cv.fromarray(img),"Name : "+str(profile[1]),(x,y+h+20),font,(0,255,0));
cv2.cv.PutText(cv2.cv.fromarray(img),"Dept : "+str(profile[2]),(x,y+h+45),font,(0,255,0));
cv2.cv.PutText(cv2.cv.fromarray(img),"IDno : "+str(profile[3]),(x,y+h+65),font,(0,255,0));
cv2.imshow("Face",img);
if(cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
This diff is collapsed.
from openpyxl import Workbook, load_workbook
from openpyxl.cell import get_column_letter, Cell, column_index_from_string
import time
import os
import sqlite3
#database connection
conn = sqlite3.connect('Face-DataBase')
c = conn.cursor()
#get current date
currentDate = time.strftime("%d_%m_%y")
#create a workbook and add a worksheet
if(os.path.exists('./reports.xlsx')):
wb = load_workbook(filename = "reports.xlsx")
sheet = wb.get_sheet_by_name('Cse15')
# sheet[ord() + '1']
for col_index in range(1, 100):
col = get_column_letter(col_index)
if sheet.cell('%s%s' % (col,1)).value is None:
col2 = get_column_letter(col_index - 1)
# print sheet.cell('%s%s'% (col2, 1)).value
if sheet.cell('%s%s' % (col2,1)).value != currentDate:
sheet['%s%s' % (col,1)] = currentDate
break
#saving the file
wb.save(filename = "reports.xlsx")
else:
wb = Workbook()
dest_filename = 'reports.xlsx'
c.execute("SELECT * FROM Students ORDER BY Roll ASC")
#creating worksheet and giving names to column
ws1 = wb.active
ws1.title = "Cse15"
ws1.append(('Roll Number', 'Name', currentDate))
ws1.append(('', '', ''))
#entering students information from database
while True:
a = c.fetchone()
if a == None:
break
else:
ws1.append((a[2], a[1]))
#saving the file
wb.save(filename = dest_filename)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment