├── README.md ├── Training_images ├── Sudhanshu.jpg └── Krish Naik.jpg ├── requirements.txt └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # One_Shot_Learning 2 | 3 | ## Please refer the document attached to this repo 4 | -------------------------------------------------------------------------------- /Training_images/Sudhanshu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/Face-Recognition-Attendance-Projects/HEAD/Training_images/Sudhanshu.jpg -------------------------------------------------------------------------------- /Training_images/Krish Naik.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krishnaik06/Face-Recognition-Attendance-Projects/HEAD/Training_images/Krish Naik.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2020.6.20 2 | chardet==3.0.4 3 | click==7.1.2 4 | cmake==3.18.2.post1 5 | decorator==4.4.2 6 | dlib==19.18.0 7 | face-recognition==1.3.0 8 | face-recognition-models==0.3.0 9 | idna==2.10 10 | imageio==2.9.0 11 | imageio-ffmpeg==0.4.2 12 | moviepy==1.0.3 13 | numpy==1.18.4 14 | opencv-python==4.4.0.46 15 | Pillow==8.0.1 16 | proglog==0.1.9 17 | requests==2.24.0 18 | tqdm==4.51.0 19 | urllib3==1.25.11 20 | wincertstore==0.2 21 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import face_recognition 4 | import os 5 | from datetime import datetime 6 | 7 | # from PIL import ImageGrab 8 | 9 | path = 'Training_images' 10 | images = [] 11 | classNames = [] 12 | myList = os.listdir(path) 13 | print(myList) 14 | for cl in myList: 15 | curImg = cv2.imread(f'{path}/{cl}') 16 | images.append(curImg) 17 | classNames.append(os.path.splitext(cl)[0]) 18 | print(classNames) 19 | 20 | 21 | def findEncodings(images): 22 | encodeList = [] 23 | 24 | 25 | for img in images: 26 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 27 | encode = face_recognition.face_encodings(img)[0] 28 | encodeList.append(encode) 29 | return encodeList 30 | 31 | 32 | def markAttendance(name): 33 | with open('Attendance.csv', 'r+') as f: 34 | myDataList = f.readlines() 35 | 36 | 37 | nameList = [] 38 | for line in myDataList: 39 | entry = line.split(',') 40 | nameList.append(entry[0]) 41 | if name not in nameList: 42 | now = datetime.now() 43 | dtString = now.strftime('%H:%M:%S') 44 | f.writelines(f'\n{name},{dtString}') 45 | 46 | #### FOR CAPTURING SCREEN RATHER THAN WEBCAM 47 | # def captureScreen(bbox=(300,300,690+300,530+300)): 48 | # capScr = np.array(ImageGrab.grab(bbox)) 49 | # capScr = cv2.cvtColor(capScr, cv2.COLOR_RGB2BGR) 50 | # return capScr 51 | 52 | encodeListKnown = findEncodings(images) 53 | print('Encoding Complete') 54 | 55 | cap = cv2.VideoCapture(0) 56 | 57 | while True: 58 | success, img = cap.read() 59 | # img = captureScreen() 60 | imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) 61 | imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB) 62 | 63 | facesCurFrame = face_recognition.face_locations(imgS) 64 | encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame) 65 | 66 | for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame): 67 | matches = face_recognition.compare_faces(encodeListKnown, encodeFace) 68 | faceDis = face_recognition.face_distance(encodeListKnown, encodeFace) 69 | # print(faceDis) 70 | matchIndex = np.argmin(faceDis) 71 | 72 | if matches[matchIndex]: 73 | name = classNames[matchIndex].upper() 74 | # print(name) 75 | y1, x2, y2, x1 = faceLoc 76 | y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4 77 | cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) 78 | cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED) 79 | cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) 80 | markAttendance(name) 81 | 82 | cv2.imshow('Webcam', img) 83 | cv2.waitKey(1) --------------------------------------------------------------------------------