Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Camera Access Check to AI Attendance Program #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions AI_Attendence_Program/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
PersonName = []
mylist = os.listdir(path)
print(mylist)
# for separating the name from their extensions

# For separating the name from their extensions
for cu_img in mylist:
current_Img = cv2.imread(f'{path}/{cu_img}')
Images.append(current_Img)
PersonName.append(os.path.splitext(cu_img)[0])
print(PersonName)


def encodings(images):
encodelist = []
for img in images:
Expand All @@ -25,13 +25,11 @@ def encodings(images):
encodelist.append(encode)
return encodelist


encode_list_Known = encodings(Images)
print("ALL ENCODING FOUND!!!")


def attendance(name):
with open('Attendence.csv', 'r+') as f:
with open('Attendance.csv', 'r+') as f:
myDataList = f.readlines()
nameList = []
for line in myDataList:
Expand All @@ -43,11 +41,19 @@ def attendance(name):
dStr = time_now.strftime('%d/%m/%Y')
f.writelines(f'\n{name},{tStr},{dStr}')


cap = cv2.VideoCapture(0)

# Check if the webcam was opened successfully
if not cap.isOpened():
print("Error: Could not access the webcam.")
exit()

while True:
ret, frame = cap.read()
if not ret:
print("Error: Failed to read from the webcam.")
break

faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25)
faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

Expand All @@ -63,7 +69,6 @@ def attendance(name):
if matches[matchIndex]:
name = PersonName[matchIndex].upper()
y1, x2, y2, x1 = faceLoc
#y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
cv2.rectangle(frame, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
cv2.putText(frame, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
Expand All @@ -72,5 +77,6 @@ def attendance(name):
cv2.imshow("camera", frame)
if cv2.waitKey(10) == 13:
break

cap.release()
cv2.destroyAllWindows()