From 55f533e692ebaf8db98780bd4cd5be8e94d58ae4 Mon Sep 17 00:00:00 2001 From: Soham Shetye <97377449+Sohams03@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:02:30 +0530 Subject: [PATCH 1/2] Update main.py --- SchduledMessageWhatsApp/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SchduledMessageWhatsApp/main.py b/SchduledMessageWhatsApp/main.py index bc501d8f..a3aa0bb2 100644 --- a/SchduledMessageWhatsApp/main.py +++ b/SchduledMessageWhatsApp/main.py @@ -1,5 +1,5 @@ import pywhatkit -import datetime + num = input("Enter WhatsApp Number of Sender (without Country Code) : ") msg = input("Enter Your Message : ") From 7841edcd2da5f9919c157d2dfa11c3e1d56da638 Mon Sep 17 00:00:00 2001 From: Soham Shetye <97377449+Sohams03@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:50:14 +0530 Subject: [PATCH 2/2] Update Main.py Camera Access Check: Added a check using cap.isOpened() to ensure the camera is accessible. If not, the program will exit with an error message. Frame Reading Validation: The program now checks if the frame is successfully read using if not ret and exits if it fails. This ensures that the program handles situations where the camera might not be accessible. --- AI_Attendence_Program/Main.py | 37 ++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/AI_Attendence_Program/Main.py b/AI_Attendence_Program/Main.py index cd0f8960..95c62dcf 100644 --- a/AI_Attendence_Program/Main.py +++ b/AI_Attendence_Program/Main.py @@ -4,19 +4,23 @@ import os from datetime import datetime +# Path to the images path = 'Images' + +# Initialize lists for images and names Images = [] PersonName = [] mylist = os.listdir(path) print(mylist) -# for separating the name from their extensions + +# Load images and extract names 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) - +# Function to encode faces def encodings(images): encodelist = [] for img in images: @@ -25,11 +29,11 @@ def encodings(images): encodelist.append(encode) return encodelist - +# Get encodings of all known faces encode_list_Known = encodings(Images) print("ALL ENCODING FOUND!!!") - +# Function to record attendance def attendance(name): with open('Attendence.csv', 'r+') as f: myDataList = f.readlines() @@ -43,14 +47,28 @@ def attendance(name): dStr = time_now.strftime('%d/%m/%Y') f.writelines(f'\n{name},{tStr},{dStr}') - +# Access the webcam cap = cv2.VideoCapture(0) +# Check if the webcam is accessible +if not cap.isOpened(): + print("Error: Camera not accessible") + exit() + +# Loop to capture frames and detect faces while True: ret, frame = cap.read() + + # If frame is read correctly, ret will be True + if not ret: + print("Failed to grab frame") + break + + # Resize and convert frame for faster processing faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25) - faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + faces = cv2.cvtColor(faces, cv2.COLOR_BGR2RGB) + # Get face locations and encodings in the current frame faces_currentframe = face_recognition.face_locations(faces) encode_currentframe = face_recognition.face_encodings(faces, faces_currentframe) @@ -69,8 +87,13 @@ def attendance(name): cv2.putText(frame, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) attendance(name) + # Display the frame with the rectangle and name cv2.imshow("camera", frame) - if cv2.waitKey(10) == 13: + + # Break the loop if the Enter key is pressed + if cv2.waitKey(10) == 13: # ASCII code for Enter key break + +# Release the camera and close windows cap.release() cv2.destroyAllWindows()