Skip to main content

Drowsiness detection using facial landmarks or CNN.

Project description

filepath: /Users/shazi/Desktop/projects/drowsiness-validator/README.md

Drowsiness Validator

A Python package for detecting drowsiness using facial landmarks or a Convolutional Neural Network (CNN).

Installation

Install the package using pip:

pip install drowsiness-validator

Usage

Here's a basic example of how to use the package:

from drowsiness_validator import DrowsinessDetector
import cv2

# Initialize the detector (choose 'landmarks' or 'cnn')
detector = DrowsinessDetector(method='landmarks')
# Or: detector = DrowsinessDetector(method='cnn')

# Load an image (replace with your image path or video frame)
image_path = 'path/to/your/image.jpg'
frame = cv2.imread(image_path)

if frame is not None:
    # Detect drowsiness
    is_drowsy, details = detector.detect_drowsiness(frame)

    if is_drowsy:
        print("Drowsiness detected!")
        # You can access more details if needed, e.g., eye aspect ratio for landmarks
        if 'ear' in details:
            print(f"Eye Aspect Ratio (EAR): {details['ear']:.2f}")
    else:
        print("Not drowsy.")
else:
    print(f"Error loading image: {image_path}")

# Example with video stream (using OpenCV)
# cap = cv2.VideoCapture(0) # Use 0 for default webcam
# while True:
#     ret, frame = cap.read()
#     if not ret:
#         break
#
#     is_drowsy, _ = detector.detect_drowsiness(frame)
#
#     status = "Drowsy" if is_drowsy else "Awake"
#     cv2.putText(frame, f"Status: {status}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255) if is_drowsy else (0, 255, 0), 2)
#
#     cv2.imshow("Drowsiness Detection", frame)
#
#     if cv2.waitKey(1) & 0xFF == ord('q'):
#         break
#
# cap.release()
# cv2.destroyAllWindows()

(Note: Ensure you have the necessary model files (shape_predictor_68_face_landmarks.dat for landmarks, drowsiness_cnn_model.h5 for CNN) accessible by the package as defined in setup.py)

Author

Sharjeel Baig

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drowsiness_validator-0.1.2.tar.gz (74.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drowsiness_validator-0.1.2-py3-none-any.whl (74.8 MB view details)

Uploaded Python 3

File details

Details for the file drowsiness_validator-0.1.2.tar.gz.

File metadata

  • Download URL: drowsiness_validator-0.1.2.tar.gz
  • Upload date:
  • Size: 74.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for drowsiness_validator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 330eb62254ff559fd5fc375f96d84aa6a8cfeb88b7880c7f0c0a4135335ccadd
MD5 6288df8cf2c0e716f0c4563143586561
BLAKE2b-256 bf2f4714247344f2ad2b7ca8b32f109b33c85dba48380b0d6c094b01ec1a1b4e

See more details on using hashes here.

File details

Details for the file drowsiness_validator-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for drowsiness_validator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 912d00895b10813ad370bcd568c893de3edd89356e067001495e5236306d1310
MD5 71f96aa7d3d37bff3b6427d3a77ec4cc
BLAKE2b-256 06ee41712c157eeaf63762f926e5eb529820ec12c248fd531ca94e9bd7ba5125

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page