forked from MrMit007/attendancesystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentify.py
More file actions
92 lines (76 loc) · 2.68 KB
/
identify.py
File metadata and controls
92 lines (76 loc) · 2.68 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import cognitive_face as CF
from global_variables import personGroupId
import os, urllib
import sqlite3
from openpyxl import Workbook, load_workbook
try:
from openpyxl.cell import get_column_letter, column_index_from_string
except ImportError:
from openpyxl.utils import get_column_letter, 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('16CE')
def getDateColumn():
for i in range(1,sheet.get_highest_row() + 1):
col = get_column_letter(i)
if sheet.cell('%s%s' % (col, '1')).value == currentDate:
return col
Key = 'aeac52f65e1a44da90aaeeab84360441'
CF.Key.set(Key)
connect = connect = sqlite3.connect("Face-DataBase")
c = connect.cursor()
attend = [0 for i in range(150)]
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))
imgurl = "C:\Users\Mit Patel\Desktop\New folder\Autoattendance-Cognitive\Cropped_faces\\face1.jpg"
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
for face in res:
if not face['candidates']:
print "Unknown"
else:
personId = face['candidates'][0]['personId']
c.execute("SELECT * FROM Students WHERE personID = ?", (personId,))
print personId
row = c.fetchone()
print row
attend[int(row[0])] += 1
print row[1] + " recognized"
time.sleep(6)
sheet = wb.active
columns = list(sheet)
for row in range(2,len(columns)):
# rn = sheet.cell('A%s' % row).value
print row
rn = columns[row][0].value
if rn is not None:
print rn;
rn = rn[-2:]
print rn;
if attend[int(rn)] != 0:
col = 2
sheet.cell(row=row+1, column=col+1).value = 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