Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions teamTechTitans/facial-landmarks-recognition
Submodule facial-landmarks-recognition added at d37b6a
Binary file added teamTechTitans/techtitans/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions teamTechTitans/techtitans/manage.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions teamTechTitans/techtitans/techapp/__pycache__/views.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions teamTechTitans/techtitans/techapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions teamTechTitans/techtitans/techapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TechappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'techapp'
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions teamTechTitans/techtitans/techapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
183 changes: 183 additions & 0 deletions teamTechTitans/techtitans/techapp/newMain2.py
Original file line number Diff line number Diff line change
@@ -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()
Loading