-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
909fab5
commit 7e70c46
Showing
11 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
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,3 @@ | ||
/dataset | ||
/harcascade | ||
/trainedModel |
Binary file not shown.
Binary file not shown.
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,7 @@ | ||
,Unnamed: 0,Unnamed: 0.1,Unnamed: 0.1.1,Unnamed: 0.1.1.1,Unnamed: 0.1.1.1.1,Sl no.,roll no.,Name,16/2/2020,16/2/2020.1,16/2/2020.1.1,16/2/2020.1.1.1,16/2/2020.1.1.1.1,16/2/2020 | ||
0,0,0,0,0,0,1,32,Nadeem Akhter,A,A,A,A,A,A | ||
1,1,1,1,1,1,2,35,Atiab Kalam,A,A,A,A,A,A | ||
2,2,2,2,2,2,3,37,Madhurima Maji,A,A,A,A,A,A | ||
3,3,3,3,3,3,4,51,Avisek Shaw,A,A,A,A,A,A | ||
4,4,4,4,4,4,5,60,Agnibesh Mukherjee,A,A,A,A,A,A | ||
5,5,5,5,5,5,6,64,Abhishek Charan,A,A,A,A,A,A |
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,7 @@ | ||
,Unnamed: 0,Unnamed: 0.1,Unnamed: 0.1.1,Unnamed: 0.1.1.1,Unnamed: 0.1.1.1.1,Sl no.,roll no.,Name,16/2/2020,16/2/2020.1,16/2/2020.1.1,16/2/2020.1.1.1,16/2/2020.1.1.1.1 | ||
0,0,0,0,0,0,1,32,Nadeem Akhter,A,A,A,A,A | ||
1,1,1,1,1,1,2,35,Atiab Kalam,A,A,A,A,A | ||
2,2,2,2,2,2,3,37,Madhurima Maji,A,A,A,A,A | ||
3,3,3,3,3,3,4,51,Avisek Shaw,A,A,A,A,A | ||
4,4,4,4,4,4,5,60,Agnibesh Mukherjee,A,A,A,A,A | ||
5,5,5,5,5,5,6,64,Abhishek Charan,A,A,A,A,A |
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,63 @@ | ||
import cv2 | ||
import os | ||
import numpy as np | ||
|
||
def faceDetection(test_img): | ||
gray_img = cv2.cvtColor(test_img,cv2.COLOR_BGR2GRAY) | ||
face_haar_cascade = cv2.CascadeClassifier("harcascade/haarcascade_frontalface_default.xml") | ||
faces = face_haar_cascade.detectMultiScale(gray_img , scaleFactor=1.32 , minNeighbors=5) | ||
|
||
return faces,gray_img | ||
|
||
|
||
def labels_for_training_data(directory): | ||
faces = [] | ||
face_id = [] | ||
|
||
for root,sub_directory,filenames in os.walk(directory): | ||
for filename in filenames: | ||
if filename.startswith("."): | ||
print("Skipping this file.....\n") | ||
continue | ||
|
||
id = os.path.basename(root) | ||
img_path = os.path.join(root,filename) | ||
print(f"img_path = {img_path}") | ||
print(f"id : {id}") | ||
test_img = cv2.imread(img_path) | ||
|
||
if test_img is None: | ||
print("Image not loaded properly ") | ||
continue | ||
|
||
faces_rect,gray_img = faceDetection(test_img) | ||
if(len(faces_rect)!=1): | ||
continue | ||
|
||
(x,y,w,h) = faces_rect[0] | ||
roi_gray = gray_img[y:y+w,x:x+h] | ||
faces.append(roi_gray) | ||
print(id) | ||
try: | ||
face_id.append(int(id)) | ||
except: | ||
print("Invalid id") | ||
continue | ||
|
||
return faces , face_id | ||
|
||
|
||
def train_classifier(faces,face_id): | ||
face_recoznizer = cv2.face.LBPHFaceRecognizer_create() | ||
face_recoznizer.train(faces,np.array(face_id)) | ||
return face_recoznizer | ||
|
||
def draw_rect(test_img,face): | ||
(x,y,w,h) = face | ||
cv2.rectangle(test_img,(x,y),(x+w,y+h),(255,0,0),thickness=2) | ||
|
||
def put_text(test_img,text,x,y): | ||
cv2.putText(test_img,text,(x,y),cv2.FONT_HERSHEY_SIMPLEX , 0.4,(255,0,0),2) | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,157 @@ | ||
import cv2 | ||
import numpy as np | ||
import os | ||
import faceRecognition as fr | ||
import openpyxl as op | ||
import datetime as dt | ||
from csv import reader , writer | ||
import pandas as pd | ||
|
||
|
||
#cap = cv2.VideoCapture(0) | ||
|
||
camera = cv2.VideoCapture(0) | ||
camera_height = 750 | ||
camera_width = 700 | ||
raw_frames = [] | ||
|
||
|
||
while(True): | ||
|
||
_, frame = camera.read() | ||
|
||
frame = cv2.flip(frame, 1) | ||
|
||
aspect = frame.shape[1] / float(frame.shape[0]) | ||
res = int(aspect * camera_height) | ||
frame = cv2.resize(frame, (res, camera_height)) | ||
|
||
|
||
cv2.rectangle(frame, (3, 3), (800, 650), (0, 255, 0), 2) | ||
|
||
|
||
cv2.imshow("Capturing frames", frame) | ||
|
||
key = cv2.waitKey(1) | ||
|
||
|
||
if key & 0xFF == ord("q"): | ||
# save the frame | ||
raw_frames.append(frame) | ||
print('1 key pressed - saved TYPE_1 frame') | ||
break | ||
#elif key & 0xFF == ord("1"): | ||
|
||
|
||
camera.release() | ||
cv2.destroyAllWindows() | ||
|
||
for i, frame in enumerate(raw_frames): | ||
|
||
roi = frame[3+2:800-2, 3+2:650-2] | ||
|
||
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB) | ||
|
||
roi = cv2.resize(roi, (224, 224)) | ||
|
||
path = 'images/{}.png'.format(i) | ||
|
||
cv2.imwrite(path , cv2.cvtColor(roi,cv2.COLOR_BGR2RGB)) | ||
|
||
|
||
label1 = [] | ||
confidence1 = [] | ||
count = 0 | ||
|
||
|
||
test_img = cv2.imread("/home/avisek/Desktop/FaceRecognition/images/0.png") | ||
|
||
faces_detected,gray_img = fr.faceDetection(test_img) | ||
print(f"faces_detected : {faces_detected}") | ||
|
||
|
||
|
||
# faces,face_id = fr.labels_for_training_data("/home/avisek/Desktop/FaceRecognition/dataset/training/Batch-2018-2019") | ||
# face_recognizer = fr.train_classifier(faces,face_id) | ||
# face_recognizer.save("trainedModel/Batch-2018-2019.yml") | ||
|
||
face_recognizer = cv2.face.LBPHFaceRecognizer_create() | ||
face_recognizer.read("/home/avisek/Desktop/FaceRecognition/trainedModel/Batch-2018-2019.yml") | ||
|
||
# face_recognizer = fr.train_classifier(faces,face_id) | ||
# face_recognizer.save("trainedModel/Batch-2018-2019.yml") | ||
# faces,face_id = fr.labels_for_training_data("/home/avisek/Desktop/FaceRecognition/dataset/training/Batch-2018-2019") | ||
|
||
name = {35:"Atiab kalam", | ||
51:"Avisek shaw", | ||
60:"Agnibesh Mukherjee", | ||
64:"Abhishek Charan", | ||
37:"Madhurima Maji", | ||
32:"Arnab kumar Pati"} | ||
|
||
for face in faces_detected: | ||
(x,y,w,h) = face | ||
roi_gray = gray_img[y:y+h,x:x+h] | ||
label,confidence = face_recognizer.predict(roi_gray) | ||
print(f"confidence : {confidence}") | ||
print(f"label : {label}") | ||
if confidence>150: | ||
fr.draw_rect(test_img,face) | ||
fr.put_text(test_img,"Not Registered",x,y) | ||
else: | ||
|
||
label1.append(int(label)) | ||
#confidence1.append(confidence) | ||
fr.draw_rect(test_img,face) | ||
predicted_name = name[label] | ||
fr.put_text(test_img,predicted_name,x,y) | ||
|
||
|
||
resized_imag = cv2.resize(test_img,(1000,700)) | ||
cv2.imshow("face detection",resized_imag) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows | ||
|
||
|
||
|
||
|
||
print(f"label : {label1}") | ||
|
||
|
||
|
||
|
||
df = pd.read_excel("attendanceSheet/cse-2018-2019-maths.xlsx",index=False) | ||
df.to_csv('./current.csv') | ||
|
||
|
||
|
||
with open('current.csv', 'r') as read_obj, \ | ||
open('cse-2018-2019-maths.csv', 'w', newline='') as write_obj: | ||
|
||
csv_reader = reader(read_obj) | ||
|
||
csv_writer = writer(write_obj) | ||
|
||
|
||
Date = dt.datetime.now() | ||
todaysDate = f"{Date.day}/{Date.month}/{Date.year}" | ||
for row in csv_reader: | ||
|
||
if (count==0): | ||
row.append(todaysDate) | ||
else: | ||
if (int(row[2]) not in label1): | ||
print("absent") | ||
status = "A" | ||
else: | ||
status = "P" | ||
print("present") | ||
row.append(status) | ||
# Add the updated row / list to the output file | ||
count = count + 1 | ||
print(f"row[2] : {row[2]}") | ||
csv_writer.writerow(row) | ||
|
||
|
||
read_file = pd.read_csv (r'cse-2018-2019-maths.csv') | ||
read_file.to_excel (r'attendanceSheet/cse-2018-2019-maths.xlsx', index = None, header=True) |
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 @@ | ||
""" | ||
copyright Avisek shaw | ||
""" | ||
import numpy as np | ||
import cv2 | ||
|
||
|
||
camera = cv2.VideoCapture(0) | ||
camera_height = 600 | ||
raw_frames = [] | ||
|
||
|
||
while(True): | ||
|
||
_, frame = camera.read() | ||
|
||
frame = cv2.flip(frame, 1) | ||
|
||
aspect = frame.shape[1] / float(frame.shape[0]) | ||
res = int(aspect * camera_height) | ||
frame = cv2.resize(frame, (res, camera_height)) | ||
|
||
|
||
cv2.rectangle(frame, (51, 37), (725, 555), (0, 255, 0), 2) | ||
|
||
|
||
cv2.imshow("Capturing frames", frame) | ||
|
||
key = cv2.waitKey(1) | ||
|
||
|
||
if key & 0xFF == ord("q"): | ||
break | ||
elif key & 0xFF == ord("1"): | ||
# save the frame | ||
raw_frames.append(frame) | ||
print('1 key pressed - saved TYPE_1 frame') | ||
|
||
camera.release() | ||
cv2.destroyAllWindows() | ||
|
||
for i, frame in enumerate(raw_frames): | ||
|
||
roi = frame[37+2:555-2, 51+2:650-2] | ||
|
||
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB) | ||
|
||
roi = cv2.resize(roi, (224, 224)) | ||
|
||
cv2.imwrite('images/{}.png'.format(i), cv2.cvtColor(roi,cv2.COLOR_BGR2RGB)) |
Oops, something went wrong.