-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Name,Time |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
import numpy as np | ||
import face_recognition | ||
import os | ||
from datetime import datetime | ||
import cv2 | ||
|
||
path = 'ImagesBasic' | ||
images = [] | ||
personName = [] | ||
myList = os.listdir(path) | ||
|
||
for curImg in myList: | ||
currentImage = cv2.imread(f'{path}/{curImg}') | ||
images.append(currentImage) | ||
personName.append(os.path.splitext(curImg)[0]) | ||
print(personName) | ||
|
||
|
||
def faceEncodings(images): | ||
encodeList = [] | ||
for img in images: | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
encode = face_recognition.face_encodings(img)[0] | ||
encodeList.append(encode) | ||
return encodeList | ||
|
||
|
||
def markAttendance(name): | ||
with open('Attendance.csv', 'r+') as f: | ||
myDataList = f.readlines() | ||
nameList = [] | ||
for line in myDataList: | ||
entry = line.split(',') | ||
nameList.append(entry[0]) | ||
if name not in nameList: | ||
now = datetime.now() | ||
dtString = now.strftime('%H:%M:%S') | ||
f.writelines(f'\n{name}, {dtString}') | ||
|
||
|
||
encodeListKnown = faceEncodings(images) | ||
print("Encoding complete") | ||
|
||
cap = cv2.VideoCapture(0) | ||
|
||
while True: | ||
success, img = cap.read() | ||
imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) | ||
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB) | ||
|
||
facesCurrent = face_recognition.face_locations(imgS) | ||
encodeCurrent = face_recognition.face_encodings(imgS, facesCurrent) | ||
|
||
for encodeFace, faceLoc in zip(encodeCurrent, facesCurrent): | ||
matches = face_recognition.compare_faces(encodeListKnown, encodeFace) | ||
faceDistance = face_recognition.face_distance( | ||
encodeListKnown, encodeFace) | ||
# print(faceDistance) | ||
matchIndex = np.argmin(faceDistance) | ||
|
||
if matches[matchIndex]: | ||
name = personName[matchIndex].upper() | ||
# print(name) | ||
y1, x2, y2, x1 = faceLoc | ||
y1, x2, y2, x1 = y1*4, x2*4, y2*4, x1*4 | ||
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) | ||
cv2.rectangle(img, (x1, y2-35), (x2, y2), (0, 255, 0), cv2.FILLED) | ||
cv2.putText(img, name, (x1+6, y2-6), | ||
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) | ||
markAttendance(name) | ||
cv2.imshow('Webcam', img) | ||
cv2.waitKey(1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Unnamed: 0,Unnamed: 0.1,name,roll_number,2021-12-10(1),2021-12-10(2),2021-12-10(3),2021-12-10(4),2021-12-11(1),2021-12-11(2),2021-12-11(3),2021-12-11(4),2021-12-13(1),2021-12-13(2),2021-12-13(3),2021-12-13(4),2021-12-14(1),2021-12-14(2),2021-12-14(3),2021-12-14(4),2021-12-15(1),2021-12-15(2),2021-12-15(3),2021-12-15(4),2021-12-16(1),2021-12-16(2),2021-12-16(3),2021-12-16(4),2021-12-17(1),2021-12-17(2),2021-12-17(3),2021-12-17(4),2021-12-18(1),2021-12-18(2),2021-12-18(3),2021-12-18(4),2021-12-20(1),2021-12-20(2),2021-12-20(3),2021-12-20(4),2021-12-21(1),2021-12-21(2),2021-12-21(3),2021-12-21(4),2021-12-22(1),2021-12-22(2),2021-12-22(3),2021-12-22(4),2021-12-23(1),2021-12-23(2),2021-12-23(3),2021-12-23(4),2021-12-24(1),2021-12-24(2),2021-12-24(3),2021-12-24(4),2021-12-25(1),2021-12-25(2),2021-12-25(3),2021-12-25(4),2021-12-27(1),2021-12-27(2),2021-12-27(3),2021-12-27(4),2021-12-28(1),2021-12-28(2),2021-12-28(3),2021-12-28(4),2021-12-29(1),2021-12-29(2),2021-12-29(3),2021-12-29(4),2021-12-30(1),2021-12-30(2),2021-12-30(3),2021-12-30(4),total_days | ||
0,0,Vincent Samuel,121, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
1,1,Matrix,1285285, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
2,2,fafafafa,fafafafefew, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
3,3,fafafaf232, db27676, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
4,4,faf2d1,31rf31ff, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
5,5,badrinath,fafafafefewaa, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
6,6,gfuafvgjahgfb auhjf,fnjafn aikjfjnakf, , , , , , , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 | ||
7,7,NAVEEN LINGALA,19dadadada, , , , ,p, , , , , , , , , , , ,H,H,H,H,H,H,H,H, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,71 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
,name,roll_number,2021-12-14(1),2021-12-14(2),2021-12-14(3),2021-12-15(1),2021-12-15(2),2021-12-15(3),2021-12-16(1),2021-12-16(2),2021-12-16(3),2021-12-17(1),2021-12-17(2),2021-12-17(3),2021-12-18(1),2021-12-18(2),2021-12-18(3),2021-12-20(1),2021-12-20(2),2021-12-20(3),2021-12-21(1),2021-12-21(2),2021-12-21(3),2021-12-22(1),2021-12-22(2),2021-12-22(3),2021-12-23(1),2021-12-23(2),2021-12-23(3),2021-12-24(1),2021-12-24(2),2021-12-24(3),2021-12-25(1),2021-12-25(2),2021-12-25(3),2021-12-27(1),2021-12-27(2),2021-12-27(3),2021-12-28(1),2021-12-28(2),2021-12-28(3),2021-12-29(1),2021-12-29(2),2021-12-29(3),2021-12-30(1),2021-12-30(2),2021-12-30(3),2021-12-31(1),2021-12-31(2),2021-12-31(3),2022-01-01(1),2022-01-01(2),2022-01-01(3),total_days | ||
0,Vincent Samuel,121, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
1,Matrix,1285285, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
2,fafafafa,fafafafefew, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
3,fafafaf232, db27676, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
4,faf2d1,31rf31ff, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
5,badrinath,fafafafefewaa, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
6,gfuafvgjahgfb auhjf,fnjafn aikjfjnakf, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
7,NAVEEN LINGALA,19dadadada, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 | ||
8,AKHIL,19D01A0540, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,51 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import numpy as np | ||
import face_recognition | ||
import os | ||
from datetime import datetime | ||
import cv2 | ||
import pandas as pd | ||
pd.options.mode.chained_assignment = None | ||
|
||
|
||
def gen_frames_photo(file_name, csv_path, class_no): | ||
#### | ||
path = 'ImagesBasic' | ||
### | ||
images = [] | ||
personName = [] | ||
myList = os.listdir(path) | ||
|
||
for curImg in myList: | ||
currentImage = cv2.imread(f'{path}/{curImg}') | ||
images.append(currentImage) | ||
personName.append(os.path.splitext(curImg)[0]) | ||
print(personName) | ||
|
||
def faceEncodings(images): | ||
encodeList = [] | ||
for img in images: | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
encode = face_recognition.face_encodings(img)[0] | ||
encodeList.append(encode) | ||
return encodeList | ||
|
||
def markAttendance(name, csv_path): | ||
##### | ||
with open(csv_path, 'r+') as f: | ||
myDataList = f.readlines() | ||
nameList = [] | ||
for line in myDataList: | ||
entry = line.split(',') | ||
nameList.append(entry[0]) | ||
if name not in nameList: | ||
now = datetime.now() | ||
dtString = now.strftime('%H:%M:%S') | ||
print(f'\n{name}, {dtString}') | ||
attendance = pd.read_csv(csv_path) | ||
idx = attendance["name"].tolist().index(name) | ||
attendance[f'{datetime.now().date()}({class_no})'][idx] = 'p' | ||
attendance.to_csv(path_or_buf=csv_path, index=False) | ||
|
||
encodeListKnown = faceEncodings(images) | ||
print("Encoding complete") | ||
|
||
img = cv2.imread(file_name) | ||
print(img) | ||
imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) | ||
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB) | ||
|
||
facesCurrent = face_recognition.face_locations(imgS) | ||
encodeCurrent = face_recognition.face_encodings(imgS, facesCurrent) | ||
|
||
for encodeFace, faceLoc in zip(encodeCurrent, facesCurrent): | ||
matches = face_recognition.compare_faces( | ||
encodeListKnown, encodeFace) | ||
faceDistance = face_recognition.face_distance( | ||
encodeListKnown, encodeFace) | ||
# print(faceDistance) | ||
matchIndex = np.argmin(faceDistance) | ||
|
||
if matches[matchIndex]: | ||
name = personName[matchIndex].upper() | ||
# print(name) | ||
y1, x2, y2, x1 = faceLoc | ||
y1, x2, y2, x1 = y1*4, x2*4, y2*4, x1*4 | ||
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) | ||
cv2.rectangle(img, (x1, y2-35), (x2, y2), | ||
(0, 255, 0), cv2.FILLED) | ||
cv2.putText(img, name, (x1+6, y2-6), | ||
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) | ||
markAttendance(name, csv_path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import numpy as np | ||
import face_recognition | ||
import os | ||
from datetime import datetime | ||
import cv2 | ||
import pandas as pd | ||
pd.options.mode.chained_assignment = None | ||
|
||
|
||
def gen_frames_video(vid_name, csv_path, class_no): | ||
#### | ||
path = 'ImagesBasic' | ||
### | ||
images = [] | ||
personName = [] | ||
myList = os.listdir(path) | ||
|
||
for curImg in myList: | ||
currentImage = cv2.imread(f'{path}/{curImg}') | ||
images.append(currentImage) | ||
personName.append(os.path.splitext(curImg)[0]) | ||
print(personName) | ||
|
||
def faceEncodings(images): | ||
encodeList = [] | ||
for img in images: | ||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
encode = face_recognition.face_encodings(img)[0] | ||
encodeList.append(encode) | ||
return encodeList | ||
|
||
def markAttendance(name, csv_path): | ||
##### | ||
with open(csv_path, 'r+') as f: | ||
myDataList = f.readlines() | ||
nameList = [] | ||
for line in myDataList: | ||
entry = line.split(',') | ||
nameList.append(entry[0]) | ||
if name not in nameList: | ||
now = datetime.now() | ||
dtString = now.strftime('%H:%M:%S') | ||
print(f'\n{name}, {dtString}') | ||
attendance = pd.read_csv(csv_path) | ||
idx = attendance["name"].tolist().index(name) | ||
attendance[f'{datetime.now().date()}({class_no})'][idx] = 'p' | ||
attendance.to_csv(path_or_buf=csv_path, index=False) | ||
|
||
encodeListKnown = faceEncodings(images) | ||
print("Encoding complete") | ||
|
||
cap = cv2.VideoCapture(vid_name) | ||
|
||
if (cap.isOpened() == False): | ||
print("Error opening video stream or file") | ||
|
||
while True: | ||
try: | ||
success, img = cap.read() | ||
print(success) | ||
imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) | ||
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB) | ||
|
||
facesCurrent = face_recognition.face_locations(imgS) | ||
encodeCurrent = face_recognition.face_encodings(imgS, facesCurrent) | ||
|
||
for encodeFace, faceLoc in zip(encodeCurrent, facesCurrent): | ||
matches = face_recognition.compare_faces( | ||
encodeListKnown, encodeFace) | ||
faceDistance = face_recognition.face_distance( | ||
encodeListKnown, encodeFace) | ||
# print(faceDistance) | ||
matchIndex = np.argmin(faceDistance) | ||
|
||
if matches[matchIndex]: | ||
name = personName[matchIndex].upper() | ||
# print(name) | ||
y1, x2, y2, x1 = faceLoc | ||
y1, x2, y2, x1 = y1*4, x2*4, y2*4, x1*4 | ||
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) | ||
cv2.rectangle(img, (x1, y2-35), (x2, y2), | ||
(0, 255, 0), cv2.FILLED) | ||
cv2.putText(img, name, (x1+6, y2-6), | ||
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) | ||
markAttendance(name, csv_path) | ||
except: | ||
break |