diff --git a/teamTechTitans/facial-landmarks-recognition b/teamTechTitans/facial-landmarks-recognition new file mode 160000 index 0000000..d37b6a7 --- /dev/null +++ b/teamTechTitans/facial-landmarks-recognition @@ -0,0 +1 @@ +Subproject commit d37b6a7426e98094e28fa99254e270a3e9b6d591 diff --git a/teamTechTitans/techtitans/db.sqlite3 b/teamTechTitans/techtitans/db.sqlite3 new file mode 100644 index 0000000..5178b7a Binary files /dev/null and b/teamTechTitans/techtitans/db.sqlite3 differ diff --git a/teamTechTitans/techtitans/manage.py b/teamTechTitans/techtitans/manage.py new file mode 100644 index 0000000..80363c5 --- /dev/null +++ b/teamTechTitans/techtitans/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'techtitans.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/teamTechTitans/techtitans/techapp/__init__.py b/teamTechTitans/techtitans/techapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/teamTechTitans/techtitans/techapp/__pycache__/__init__.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..1c46a10 Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/__init__.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/admin.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..d874a70 Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/admin.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/apps.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..382cf31 Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/apps.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/models.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..06ffeaf Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/models.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/urls.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..c68451a Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/urls.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/views.cpython-312.pyc b/teamTechTitans/techtitans/techapp/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..eb24e8d Binary files /dev/null and b/teamTechTitans/techtitans/techapp/__pycache__/views.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/__pycache__/views.py b/teamTechTitans/techtitans/techapp/__pycache__/views.py new file mode 100644 index 0000000..8d4c0e3 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/__pycache__/views.py @@ -0,0 +1,31 @@ +from django.shortcuts import render + +# yourappname/views.py + +# yourappname/views.py + +from django.http import JsonResponse +from subprocess import Popen, PIPE +from django.views.decorators.csrf import csrf_exempt +import os + +@csrf_exempt +def execute_script(request): + if request.method == 'POST': + try: + # Specify the path to your main.py script + script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'hackathon', 'newMain.py') + + # Execute the script + process = Popen(['python', script_path], stdout=PIPE, stderr=PIPE) + stdout, stderr = process.communicate() + + # Check the result + if process.returncode == 0: + return JsonResponse({'success': True, 'message': 'Script executed successfully', 'output': stdout.decode()}) + else: + return JsonResponse({'success': False, 'message': 'Error executing script', 'error': stderr.decode()}, status=500) + except Exception as e: + return JsonResponse({'success': False, 'message': str(e)}, status=500) + else: + return JsonResponse({'success': False, 'message': 'Invalid request method'}, status=400) diff --git a/teamTechTitans/techtitans/techapp/admin.py b/teamTechTitans/techtitans/techapp/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/teamTechTitans/techtitans/techapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/teamTechTitans/techtitans/techapp/apps.py b/teamTechTitans/techtitans/techapp/apps.py new file mode 100644 index 0000000..3f8fdbf --- /dev/null +++ b/teamTechTitans/techtitans/techapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TechappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'techapp' diff --git a/teamTechTitans/techtitans/techapp/migrations/__init__.py b/teamTechTitans/techtitans/techapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/teamTechTitans/techtitans/techapp/migrations/__pycache__/__init__.cpython-312.pyc b/teamTechTitans/techtitans/techapp/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..5f9f73b Binary files /dev/null and b/teamTechTitans/techtitans/techapp/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techapp/models.py b/teamTechTitans/techtitans/techapp/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/teamTechTitans/techtitans/techapp/newMain2.py b/teamTechTitans/techtitans/techapp/newMain2.py new file mode 100644 index 0000000..efb25c2 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/newMain2.py @@ -0,0 +1,183 @@ + + + +import cv2 +import numpy as np +import dlib +from imutils import face_utils + + +# Initialize dlib's face detector and facial landmark predictor +def mainfunction(): + p = "shape_predictor_68_face_landmarks.dat" + detector = dlib.get_frontal_face_detector() + predictor = dlib.shape_predictor(p) + + # Initialize variables + sleep, drowsy, active = 0, 0, 0 + status, color = "", (0, 0, 0) + + def compute(ptA, ptB): + return np.linalg.norm(ptA - ptB) + + def blinked(a, b, c, d, e, f): + up = compute(b, d) + compute(c, e) + down = compute(a, f) + ratio = up / (2.0 * down) + + if ratio > 0.25: + return 2 + elif 0.21 < ratio <= 0.25: + return 1 + else: + return 0 + + # Open a video capture object + cap = cv2.VideoCapture(0) + + # Check if the video capture is opened successfully + if not cap.isOpened(): + print("Error: Could not open camera.") + exit() + + while True: + _, frame = cap.read() + if frame is None: + print("Error: Could not read frame.") + break + + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + # Detect faces in the grayscale image + faces = detector(gray, 0) + + for face in faces: + x1, y1, x2, y2 = face.left(), face.top(), face.right(), face.bottom() + + face_frame = frame.copy() + cv2.rectangle(face_frame, (x1, y1), (x2, y2), (0, 255, 0), 2) + + landmarks = predictor(gray, face) + landmarks = face_utils.shape_to_np(landmarks) + + left_blink = blinked(landmarks[36], landmarks[37], landmarks[38], landmarks[41], landmarks[40], landmarks[39]) + right_blink = blinked(landmarks[42], landmarks[43], landmarks[44], landmarks[47], landmarks[46], landmarks[45]) + + if left_blink == 0 or right_blink == 0: + sleep += 1 + drowsy, active = 0, 0 + if sleep > 6: + status, color = "SLEEPING !!!", (255, 0, 0) + elif 0 < left_blink == 1 or right_blink == 1: + drowsy += 1 + sleep, active = 0, 0 + if drowsy > 6: + status, color = "Drowsy !", (0, 0, 255) + else: + active += 1 + sleep, drowsy = 0, 0 + if active > 6: + status, color = "Active :)", (0, 255, 0) + + cv2.putText(frame, status, (100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1.2, color, 3) + + for (x, y) in landmarks: + cv2.circle(face_frame, (x, y), 1, (255, 255, 255), -1) + + cv2.imshow("Frame", frame) + cv2.imshow("Result of detector", face_frame) + + key = cv2.waitKey(1) + if key == 27: + break + + # Release the video capture object and close all OpenCV windows + cap.release() + cv2.destroyAllWindows() + + +# p = "shape_predictor_68_face_landmarks.dat" +# detector = dlib.get_frontal_face_detector() +# predictor = dlib.shape_predictor(p) + +# # Initialize variables +# sleep, drowsy, active = 0, 0, 0 +# status, color = "", (0, 0, 0) + +# def compute(ptA, ptB): +# return np.linalg.norm(ptA - ptB) + +# def blinked(a, b, c, d, e, f): +# up = compute(b, d) + compute(c, e) +# down = compute(a, f) +# ratio = up / (2.0 * down) + +# if ratio > 0.25: +# return 2 +# elif 0.21 < ratio <= 0.25: +# return 1 +# else: +# return 0 + +# # Open a video capture object +# cap = cv2.VideoCapture(0) + +# # Check if the video capture is opened successfully +# if not cap.isOpened(): +# print("Error: Could not open camera.") +# exit() + +# while True: +# _, frame = cap.read() +# if frame is None: +# print("Error: Could not read frame.") +# break + +# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + +# # Detect faces in the grayscale image +# faces = detector(gray, 0) + +# for face in faces: +# x1, y1, x2, y2 = face.left(), face.top(), face.right(), face.bottom() + +# face_frame = frame.copy() +# cv2.rectangle(face_frame, (x1, y1), (x2, y2), (0, 255, 0), 2) + +# landmarks = predictor(gray, face) +# landmarks = face_utils.shape_to_np(landmarks) + +# left_blink = blinked(landmarks[36], landmarks[37], landmarks[38], landmarks[41], landmarks[40], landmarks[39]) +# right_blink = blinked(landmarks[42], landmarks[43], landmarks[44], landmarks[47], landmarks[46], landmarks[45]) + +# if left_blink == 0 or right_blink == 0: +# sleep += 1 +# drowsy, active = 0, 0 +# if sleep > 6: +# status, color = "SLEEPING !!!", (255, 0, 0) +# elif 0 < left_blink == 1 or right_blink == 1: +# drowsy += 1 +# sleep, active = 0, 0 +# if drowsy > 6: +# status, color = "Drowsy !", (0, 0, 255) +# else: +# active += 1 +# sleep, drowsy = 0, 0 +# if active > 6: +# status, color = "Active :)", (0, 255, 0) + +# cv2.putText(frame, status, (100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1.2, color, 3) + +# for (x, y) in landmarks: +# cv2.circle(face_frame, (x, y), 1, (255, 255, 255), -1) + +# cv2.imshow("Frame", frame) +# cv2.imshow("Result of detector", face_frame) + +# key = cv2.waitKey(1) +# if key == 27: +# break + +# # Release the video capture object and close all OpenCV windows +# cap.release() +# cv2.destroyAllWindows() diff --git a/teamTechTitans/techtitans/techapp/templates/project.html b/teamTechTitans/techtitans/techapp/templates/project.html new file mode 100644 index 0000000..c4ba376 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/templates/project.html @@ -0,0 +1,153 @@ + + + + + + + + + + Tech Titans + + + + + + + + + +
+ + + +
+ + + + +
+
+

Face detection model

+
+ +

+
+
+

Solution description

+
+

+

Creating an effective online learning environment involves not only delivering + content but + also ensuring active student engagement. To enhance this interaction, incorporating head movement + tracking + into the web camera becomes a valuable tool. By leveraging computer vision technologies, we can detect + and + monitor students' presence during online classes in real-time. This feature not only helps educators + ensure + that students are actively participating but also provides insights into their level of engagement. + + content covered in previous classes. This serves as a reinforcement mechanism, promoting the retention + of + information and encouraging students to stay mentally active during the entire session.
+
+ Image 2
+
+ + In essence, the integration of head movement tracking and the incorporation of spontaneous MCQs + contribute + to the creation of a dynamic and engaging virtual classroom. These features not only serve the practical + purpose of ensuring student presence but also enhance the overall educational experience by promoting + active + participation and reinforcing learning outcomes. As technology continues to evolve, such innovative + approaches play a pivotal role in shaping the future of online education, making it more interactive, + personalized.

+ + + +

+ +

+
+

+
+ + +
+
+ +
+ {% csrf_token %} + +
+ + + + +
+ {% if result %} +

Script Output:

+
{{ result }}
+ {% endif %} +
+ +
+ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/teamTechTitans/techtitans/techapp/templates/static/active.jpg b/teamTechTitans/techtitans/techapp/templates/static/active.jpg new file mode 100644 index 0000000..e7023fd Binary files /dev/null and b/teamTechTitans/techtitans/techapp/templates/static/active.jpg differ diff --git a/teamTechTitans/techtitans/techapp/templates/static/lead.avif b/teamTechTitans/techtitans/techapp/templates/static/lead.avif new file mode 100644 index 0000000..214a852 Binary files /dev/null and b/teamTechTitans/techtitans/techapp/templates/static/lead.avif differ diff --git a/teamTechTitans/techtitans/techapp/templates/static/project.css b/teamTechTitans/techtitans/techapp/templates/static/project.css new file mode 100644 index 0000000..265a879 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/templates/static/project.css @@ -0,0 +1,266 @@ +*{ + text-align: center; +} +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f4f4f4; +} + +header { + background-color: #333; + color:white; + padding: 10px; + text-align: center; + margin-top: -1px; +} + +section { + padding: 20px; + margin: 20px; +} + +button { + padding: 10px 20px; + font-size: 16px; + cursor: pointer; + margin-top: 20px; + background-color: #4CAF50; + color: white; + border: none; + border-radius: 5px; +} +button:hover { + background-color: #2a662d; /* Change the color on hover */ +} +#execute-button{ + margin-top: 10px; +} +footer { + background-color: #333; + color: white; + text-align: center; + padding: 10px; + /* position: fixed; */ + bottom: 0; + width: 100%; + + + } + +#team-name{ + color: green; + font-size: 20px; + margin-left: 20px; +} + + +#team-section { + margin: 20px; +} + +#team-members { + font-weight: bold; + margin-bottom: 10px; + color: purple; + font-size: 20px; +} +ul{ + font-size: 34px; +} + +#project-section { + margin: 20px; + +} + +#project-info { + + color: #333; + border-bottom: 2px solid #333; + padding-bottom: 5px; +} +.techi{font-size: 20px; + justify-content: space-evenly; + color:rgba(245, 245,220,0.8); +}; + + + +.problem-statement{ + margin-bottom: 10px; + color:purple; + font-size: 30px; +} +#project-info{ + color: #af6faf ; +font-size: 60px; +margin-left: -680px; +} +#Description{ + font-size: 20px; +} +#team-leader { + font-size: 46px; + color: purple; +} +#saharsh { + margin-left: 15px; + font-size: 45px; + margin-top: 47px; +} +#leaderr{ + display: flex; +} +.prodesc{ + font-size: 25px; + color: #333; + text-decoration: solid; +} +.images { + margin-top: 29px; + margin-bottom: 20px; + height: 301px; + margin-left: 90px; +} +.image{ + align-items: center; + /* background-color: #333; */ +} +#copyright{ + height: 8px; +} +.centerwork{ + width: 70%; + margin-left:14%; + padding: 30px; + border: 2px solid #333; +} +/* project.css */ + +body { + background-image: url('lead.avif'); /* Replace 'your-background-image.jpg' with the actual path or URL of your image */ + background-size: cover; /* Ensures the background image covers the entire viewport */ + background-position: center; /* Centers the background image */ + background-repeat: no-repeat; /* Prevents the background image from repeating */ + margin: 0; /* Removes default body margin */ + padding: 0; /* Removes default body padding */ +} + + +/* Your additional styling goes here */ +#projectinfo{ + + border-radius: 10px; +} +.header{ + /* background-color: grey; */ + margin-top: -21px; +} +#problem-statement{ + font-size: 30px; +} +#desp{ font-size: larger; + color: #cf595f; +} +.header{ + + height:100px; +} +#project-info{ + color: #cf595f; + margin-left: -650px; +} +.problem-statement{ + color: #cf595f; +} +.prodesc{ + color: rgba(245, 245,220,0.8); +} +h1{ + color: antiquewhite; + padding: 27px; + font-size: 40px; + font-style: normal; + margin-top: 10px; +} +nav { + margin-top: 25px; + background-color: #333; + overflow: hidden; +} + +nav a { + float: left; + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +nav a:hover { + background-color: #ddd; + color: black; +} +section{ + margin-top:-92px; +} +#project-section{ + margin-top:-90px; +} +#project-info{ + color: #cf595f; + +} +#desp{ + color: #cf595f; + +} +#execute-button{ + padding-top: 10px; +} +button{ + margin-top: 10px; +} +.slider-container { + width: 300px; + overflow: hidden; + position: relative; +} + +.image-slider { + display: flex; + width: fit-content; + animation: mover 0.5s ; + transition: transform 0.5s ease-in-out; +} +@keyframes mover { + 0%{ + transform: translateX(0); + } + 50%{ + transform: translateX(100%); + } + 100%{ + transform: translateX(0); + } +} +.slider-item { + width: 300px; + flex: 0 0 auto; +} + +.slider-item img { + width: 100%; + height: auto; +} +#image-container{ + box-shadow: 0 4px 8px rgba(182, 177, 177, 0.1); + border-radius: 20px; +} +.images{ + border-radius: 10px; + margin-left: 29px; +} diff --git a/teamTechTitans/techtitans/techapp/tests.py b/teamTechTitans/techtitans/techapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/teamTechTitans/techtitans/techapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/teamTechTitans/techtitans/techapp/urls.py b/teamTechTitans/techtitans/techapp/urls.py new file mode 100644 index 0000000..c8b06bb --- /dev/null +++ b/teamTechTitans/techtitans/techapp/urls.py @@ -0,0 +1,12 @@ +# yourappname/urls.py + +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.home, name='home'), + path('execute_on_click/',views.execute_on_click.as_view(),name='execute_on_click') +] + + + diff --git a/teamTechTitans/techtitans/techapp/views.py b/teamTechTitans/techtitans/techapp/views.py new file mode 100644 index 0000000..a328492 --- /dev/null +++ b/teamTechTitans/techtitans/techapp/views.py @@ -0,0 +1,188 @@ +# from django.shortcuts import render, HttpResponse + +# # yourappname/views.py + +# # yourappname/views.py + +# from django.http import JsonResponse +# from subprocess import Popen, PIPE +# from django.views.decorators.csrf import csrf_exempt +# import os + +# @csrf_exempt +# def execute_script(request): +# if request.method == 'POST': +# try: +# # Specify the path to your main.py script +# script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'hackathon', 'newMain.py') + +# # Execute the script +# process = Popen(['python', script_path], stdout=PIPE, stderr=PIPE) +# stdout, stderr = process.communicate() + +# # Check the result +# if process.returncode == 0: +# return JsonResponse({'success': True, 'message': 'Script executed successfully', 'output': stdout.decode()}) +# else: +# return JsonResponse({'success': False, 'message': 'Error executing script', 'error': stderr.decode()}, status=500) +# except Exception as e: +# return JsonResponse({'success': False, 'message': str(e)}, status=500) +# else: +# return JsonResponse({'success': False, 'message': 'Invalid request method'}, status=400) + + + +# yourappname/views.py + +from django.http import JsonResponse +from subprocess import Popen, PIPE +from django.views.decorators.csrf import csrf_exempt +import os +from rest_framework.views import APIView +from django.shortcuts import render, redirect + +def home(request): + return render(request,'project.html') + +# class execute_script(APIView): +# def get(self,request): +# if request.method == 'POST': +# try: +# # Specify the path to your newMain.py script +# script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'facial-landmarks-recognition', 'newMain.py') +# # script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.join"D:\\hackathon\\facial-landmarks-recognition", "shape_predictor_68_face_landmarks.dat") +# # Execute the script +# process = Popen(['python', script_path], stdout=PIPE, stderr=PIPE) +# stdout, stderr = process.communicate() + +# # Check the result +# if process.returncode == 0: +# return JsonResponse({'success': True, 'message': 'Script executed successfully', 'output': stdout.decode()}) +# else: +# return JsonResponse({'success': False, 'message': 'Error executing script', 'error': stderr.decode()}, status=500) +# except Exception as e: +# return JsonResponse({'success': False, 'message': str(e)}, status=500) +# else: +# return JsonResponse({'success': False, 'message': 'Invalid request method'}, status=400) + +# @csrf_exempt +# def execute_script(request): +# if request.method == 'POST': +# try: +# # Specify the path to your newMain.py script +# script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'facial-landmarks-recognition', 'newMain.py') +# # script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.join"D:\\hackathon\\facial-landmarks-recognition", "shape_predictor_68_face_landmarks.dat") +# # Execute the script +# process = Popen(['python', script_path], stdout=PIPE, stderr=PIPE) +# stdout, stderr = process.communicate() + +# # Check the result +# if process.returncode == 0: +# return JsonResponse({'success': True, 'message': 'Script executed successfully', 'output': stdout.decode()}) +# else: +# return JsonResponse({'success': False, 'message': 'Error executing script', 'error': stderr.decode()}, status=500) +# except Exception as e: +# return JsonResponse({'success': False, 'message': str(e)}, status=500) +# else: +# return JsonResponse({'success': False, 'message': 'Invalid request method'}, status=400) + +# from newMain2 import mainfunction + +class execute_on_click(APIView): + def get(self,request): + p = "shape_predictor_68_face_landmarks.dat" + detector = dlib.get_frontal_face_detector() + predictor = dlib.shape_predictor(p) + + # Initialize variables + sleep, drowsy, active = 0, 0, 0 + status, color = "", (0, 0, 0) + + def compute(ptA, ptB): + return np.linalg.norm(ptA - ptB) + + def blinked(a, b, c, d, e, f): + up = compute(b, d) + compute(c, e) + down = compute(a, f) + ratio = up / (2.0 * down) + + if ratio > 0.25: + return 2 + elif 0.21 < ratio <= 0.25: + return 1 + else: + return 0 + + # Open a video capture object + cap = cv2.VideoCapture(0) + + # Check if the video capture is opened successfully + if not cap.isOpened(): + print("Error: Could not open camera.") + exit() + + while True: + _, frame = cap.read() + if frame is None: + print("Error: Could not read frame.") + break + + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + # Detect faces in the grayscale image + faces = detector(gray, 0) + + for face in faces: + x1, y1, x2, y2 = face.left(), face.top(), face.right(), face.bottom() + + face_frame = frame.copy() + cv2.rectangle(face_frame, (x1, y1), (x2, y2), (0, 255, 0), 2) + + landmarks = predictor(gray, face) + landmarks = face_utils.shape_to_np(landmarks) + + left_blink = blinked(landmarks[36], landmarks[37], landmarks[38], landmarks[41], landmarks[40], landmarks[39]) + right_blink = blinked(landmarks[42], landmarks[43], landmarks[44], landmarks[47], landmarks[46], landmarks[45]) + + if left_blink == 0 or right_blink == 0: + sleep += 1 + drowsy, active = 0, 0 + if sleep > 6: + status, color = "SLEEPING !!!", (255, 0, 0) + elif 0 < left_blink == 1 or right_blink == 1: + drowsy += 1 + sleep, active = 0, 0 + if drowsy > 6: + status, color = "Drowsy !", (0, 0, 255) + else: + active += 1 + sleep, drowsy = 0, 0 + if active > 6: + status, color = "Active :)", (0, 255, 0) + + cv2.putText(frame, status, (100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1.2, color, 3) + + for (x, y) in landmarks: + cv2.circle(face_frame, (x, y), 1, (255, 255, 255), -1) + + cv2.imshow("Frame", frame) + cv2.imshow("Result of detector", face_frame) + + key = cv2.waitKey(1) + if key == 27: + break + + # Release the video capture object and close all OpenCV windows + cap.release() + cv2.destroyAllWindows() + + +# @csrf_exempt +# def execute_on_click(request): +# if request.method == 'GET': +# try: +# return JsonResponse({'success': True, 'message': 'Button click functionality executed'}) +# except Exception as e: +# return JsonResponse({'success': False, 'message': str(e)}, status=500) +# else: +# return JsonResponse({'success': False, 'message': 'Invalid request method'}, status=400) diff --git a/teamTechTitans/techtitans/techtitans/__init__.py b/teamTechTitans/techtitans/techtitans/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/teamTechTitans/techtitans/techtitans/__pycache__/__init__.cpython-312.pyc b/teamTechTitans/techtitans/techtitans/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..2e0b342 Binary files /dev/null and b/teamTechTitans/techtitans/techtitans/__pycache__/__init__.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techtitans/__pycache__/settings.cpython-312.pyc b/teamTechTitans/techtitans/techtitans/__pycache__/settings.cpython-312.pyc new file mode 100644 index 0000000..d30412c Binary files /dev/null and b/teamTechTitans/techtitans/techtitans/__pycache__/settings.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techtitans/__pycache__/urls.cpython-312.pyc b/teamTechTitans/techtitans/techtitans/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..02d66f7 Binary files /dev/null and b/teamTechTitans/techtitans/techtitans/__pycache__/urls.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techtitans/__pycache__/wsgi.cpython-312.pyc b/teamTechTitans/techtitans/techtitans/__pycache__/wsgi.cpython-312.pyc new file mode 100644 index 0000000..3a04d14 Binary files /dev/null and b/teamTechTitans/techtitans/techtitans/__pycache__/wsgi.cpython-312.pyc differ diff --git a/teamTechTitans/techtitans/techtitans/asgi.py b/teamTechTitans/techtitans/techtitans/asgi.py new file mode 100644 index 0000000..af7b48c --- /dev/null +++ b/teamTechTitans/techtitans/techtitans/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for techtitans project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'techtitans.settings') + +application = get_asgi_application() diff --git a/teamTechTitans/techtitans/techtitans/settings.py b/teamTechTitans/techtitans/techtitans/settings.py new file mode 100644 index 0000000..9bc9d8b --- /dev/null +++ b/teamTechTitans/techtitans/techtitans/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for techtitans project. + +Generated by 'django-admin startproject' using Django 5.0.1. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.0/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-o7%(j6qc8#30m*#zbc(-vw)3*tqrz*h9ly3@at5w_+k0ukx1ey' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'techapp' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'techtitans.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'techtitans.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/teamTechTitans/techtitans/techtitans/urls.py b/teamTechTitans/techtitans/techtitans/urls.py new file mode 100644 index 0000000..9595539 --- /dev/null +++ b/teamTechTitans/techtitans/techtitans/urls.py @@ -0,0 +1,12 @@ +# yourprojectname/urls.py + +from django.contrib import admin +from django.urls import include, path + +from techapp.views import execute_on_click + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('techapp.urls')), +] + diff --git a/teamTechTitans/techtitans/techtitans/wsgi.py b/teamTechTitans/techtitans/techtitans/wsgi.py new file mode 100644 index 0000000..acce609 --- /dev/null +++ b/teamTechTitans/techtitans/techtitans/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for techtitans project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'techtitans.settings') + +application = get_wsgi_application()