From f30cfe7e0b1752b7c6b0f3206d06d8c741b8e7e1 Mon Sep 17 00:00:00 2001 From: AmeyaChaudhary2003 <115422536+AmeyaChaudhary2003@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:08:21 +0530 Subject: [PATCH 1/5] Update Readme.txt Readme file added --- Tic-Tac-Toe/ticreadme.txt | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Tic-Tac-Toe/ticreadme.txt diff --git a/Tic-Tac-Toe/ticreadme.txt b/Tic-Tac-Toe/ticreadme.txt new file mode 100644 index 00000000..9a9c7a38 --- /dev/null +++ b/Tic-Tac-Toe/ticreadme.txt @@ -0,0 +1,48 @@ +# Tic-Tac-Toe + +This is a simple command-line Tic-Tac-Toe game built using Python. It allows two players to take turns and play the classic Tic-Tac-Toe game. + +## Table of Contents +- [Features](#features) +- [Installation](#installation) +- [How to Play](#how-to-play) +- [Game Rules](#game-rules) +- [Example](#example) +- [Contributing](#contributing) +- [License](#license) + +## Features +- Command-line interface +- Supports two players (Player X and Player O) +- Simple and intuitive gameplay +- Detects win conditions and tie games +- Displays the game board after each move + +## Installation + +1. **Clone the repository**: + ```bash + git clone https://github.com/your-username/tictactoe.git + cd tictactoe + +nsure Python is installed: This game is written in Python, so you need to have Python installed. You can check by running: + + +python --version + +Run the game: You can directly run the tictactoe.py file: + +python tictactoe.py + +How to Play +Player 1 (X) starts by choosing a position on the grid numbered 1 to 9. +Player 2 (O) takes the next turn by choosing an empty position. +The game continues until a player wins by placing three marks in a row (horizontal, vertical, or diagonal) or the game results in a tie. +Game Rules +The game is played on a 3x3 grid. +Players take turns choosing a spot (1-9) to place their mark (X or O). +The first player to get 3 of their marks in a row (either horizontally, vertically, or diagonally) wins. +If all 9 spaces are filled and no player has 3 marks in a row, the game ends in a draw. + +License +This project is open-source and available under the MIT License. \ No newline at end of file From f0aab32323199ec816738b7ec21b243b8d94dab5 Mon Sep 17 00:00:00 2001 From: AmeyaChaudhary2003 <115422536+AmeyaChaudhary2003@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:09:12 +0530 Subject: [PATCH 2/5] Added webcam checking functionality Added code to check if the webcam was properly accessed or not and return an error message if it is not accessed. --- AI_Attendence_Program/Main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AI_Attendence_Program/Main.py b/AI_Attendence_Program/Main.py index cd0f8960..a72a99de 100644 --- a/AI_Attendence_Program/Main.py +++ b/AI_Attendence_Program/Main.py @@ -46,6 +46,11 @@ def attendance(name): cap = cv2.VideoCapture(0) +# Check if the webcam is opened successfully +if not cap.isOpened(): + print("Error: Could not access the camera.") + exit() + while True: ret, frame = cap.read() faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25) From 7792441481c6e67d2712043f193398d36d76a806 Mon Sep 17 00:00:00 2001 From: AmeyaChaudhary2003 <115422536+AmeyaChaudhary2003@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:15:52 +0530 Subject: [PATCH 3/5] Solved issue added code to check if the webcam was properly accessed or not and return an error message if it is not accessed. From a0f54177a65754b63c898dfadbcdb6953f38686c Mon Sep 17 00:00:00 2001 From: AmeyaChaudhary2003 <115422536+AmeyaChaudhary2003@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:43:37 +0530 Subject: [PATCH 4/5] Add files via upload --- SNAKE/Main.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 SNAKE/Main.py diff --git a/SNAKE/Main.py b/SNAKE/Main.py new file mode 100644 index 00000000..a72a99de --- /dev/null +++ b/SNAKE/Main.py @@ -0,0 +1,81 @@ +import cv2 +import numpy as np +import face_recognition +import os +from datetime import datetime + +path = 'Images' +Images = [] +PersonName = [] +mylist = os.listdir(path) +print(mylist) +# 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: + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + encode = face_recognition.face_encodings(img)[0] + encodelist.append(encode) + return encodelist + + +encode_list_Known = encodings(Images) +print("ALL ENCODING FOUND!!!") + + +def attendance(name): + with open('Attendence.csv', 'r+') as f: + myDataList = f.readlines() + nameList = [] + for line in myDataList: + entry = line.split(',') + nameList.append(entry[0]) + if name not in nameList: + time_now = datetime.now() + tStr = time_now.strftime('%H:%M:%S') + dStr = time_now.strftime('%d/%m/%Y') + f.writelines(f'\n{name},{tStr},{dStr}') + + +cap = cv2.VideoCapture(0) + +# Check if the webcam is opened successfully +if not cap.isOpened(): + print("Error: Could not access the camera.") + exit() + +while True: + ret, frame = cap.read() + faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25) + faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + + faces_currentframe = face_recognition.face_locations(faces) + encode_currentframe = face_recognition.face_encodings(faces, faces_currentframe) + + for encodeFace, faceLoc in zip(encode_currentframe, faces_currentframe): + matches = face_recognition.compare_faces(encode_list_Known, encodeFace) + faceDistance = face_recognition.face_distance(encode_list_Known, encodeFace) + + matchIndex = np.argmin(faceDistance) + + 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) + attendance(name) + + cv2.imshow("camera", frame) + if cv2.waitKey(10) == 13: + break +cap.release() +cv2.destroyAllWindows() From f73a478fbecd727901e0f7157e9c4533997eca58 Mon Sep 17 00:00:00 2001 From: AmeyaChaudhary2003 <115422536+AmeyaChaudhary2003@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:57:31 +0530 Subject: [PATCH 5/5] Verifying if web cam is accessible This script captures live video from a webcam and performs real-time face recognition using pre-encoded images. It verifies if the webcam is accessible before processing, and if a face is recognized, it logs the person's name along with the date and time in a CSV file for attendance tracking. --- AI_Attendence_Program/Main (1).py | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 AI_Attendence_Program/Main (1).py diff --git a/AI_Attendence_Program/Main (1).py b/AI_Attendence_Program/Main (1).py new file mode 100644 index 00000000..cd7faad9 --- /dev/null +++ b/AI_Attendence_Program/Main (1).py @@ -0,0 +1,86 @@ +import cv2 +import numpy as np +import face_recognition +import os +from datetime import datetime + +path = 'Images' +Images = [] +PersonName = [] +mylist = os.listdir(path) +print(mylist) + +# 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: + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + encode = face_recognition.face_encodings(img)[0] + encodelist.append(encode) + return encodelist + +encode_list_Known = encodings(Images) +print("ALL ENCODING FOUND!!!") + +def attendance(name): + with open('Attendence.csv', 'r+') as f: + myDataList = f.readlines() + nameList = [] + for line in myDataList: + entry = line.split(',') + nameList.append(entry[0]) + if name not in nameList: + time_now = datetime.now() + tStr = time_now.strftime('%H:%M:%S') + dStr = time_now.strftime('%d/%m/%Y') + f.writelines(f'\n{name},{tStr},{dStr}') + +def check_camera_access(cap): + if not cap.isOpened(): + print("Error: Unable to access the webcam.") + return False + return True + +cap = cv2.VideoCapture(0) + +if not check_camera_access(cap): + exit() # Exit if the camera is not accessible + +while True: + ret, frame = cap.read() + if not ret: + print("Error: Unable to read from the webcam.") + break + + faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25) + faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + + faces_currentframe = face_recognition.face_locations(faces) + encode_currentframe = face_recognition.face_encodings(faces, faces_currentframe) + + for encodeFace, faceLoc in zip(encode_currentframe, faces_currentframe): + matches = face_recognition.compare_faces(encode_list_Known, encodeFace) + faceDistance = face_recognition.face_distance(encode_list_Known, encodeFace) + + matchIndex = np.argmin(faceDistance) + + if matches[matchIndex]: + name = PersonName[matchIndex].upper() + y1, x2, y2, x1 = faceLoc + 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) + attendance(name) + + cv2.imshow("camera", frame) + if cv2.waitKey(10) == 13: + break + +cap.release() +cv2.destroyAllWindows()