forked from malharsk27/Autoattendance-Cognitive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identify.py
77 lines (65 loc) · 2.11 KB
/
identify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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"
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