Skip to content

saliqasarwi/Drowning_Detection_final

Repository files navigation

Drowning Detection CNN with Enhanced Small Person Detection

This project implements a real-time drowning detection system using Convolutional Neural Networks (CNNs) with two popular architectures: GoogleNet and ResNet. The application provides both a graphical user interface for real-time detection and command-line interfaces for model training and evaluation. Now with advanced person detection and water/land classification, including enhanced small person detection!

Drowning Detection System

Features

  • 👁️ Real-time person detection with counting and tracking
  • 🔍 NEW! Enhanced small person detection with multi-scale analysis
  • 🌊 Water area detection to identify if a person is in water or on land
  • 💧 NEW! Advanced water detection for blue, green, and murky water conditions
  • ⚠️ Drowning alert system with visual and logging notifications
  • 🎯 Real-time drowning detection from webcam, video files, and images
  • 🧠 Two state-of-the-art CNN models: GoogleNet and ResNet
  • 📊 Detailed model evaluation with confusion matrices and ROC curves
  • 📸 Screenshot capture for evidence and record-keeping
  • 📈 TensorBoard integration for monitoring training progress
  • 🖥️ Modern and intuitive PyQt5-based graphical user interface
  • 📁 Organized project structure for easy maintenance
  • 🔄 NEW! Temporal tracking for more stable detection results

Project Structure

drowning-detection-cnn
├── src
│   ├── app.py                 # GUI application implementation
│   ├── main.py                # Entry point with command-line arguments
│   ├── settings.py            # Centralized configuration
│   ├── dataset.py             # Advanced dataset handling with augmentation
│   ├── train.py               # Training with tensorboard and early stopping
│   ├── evaluate.py            # Comprehensive model evaluation
│   ├── utils.py               # Utility functions and helpers
│   ├── models
│   │   ├── googlenet_model.py # GoogleNet implementation
│   │   └── resnet_model.py    # ResNet implementation
├── data
│   ├── normal/                # Images of normal swimming
│   └── drowning/              # Images of drowning incidents
├── models                     # Saved model weights
├── results                    # Evaluation results and visualizations
├── setup.ps1                  # Setup script for environment configuration
├── run_app.bat                # Quick-start batch file for Windows
├── requirements.txt           # Project dependencies
└── README.md                  # Project documentation

Quick Start

Windows

  1. Run the setup script (requires PowerShell):

    powershell -ExecutionPolicy Bypass -File setup.ps1
    
  2. Launch the application:

    run_app.bat
    

Manual Setup

  1. Create and activate a virtual environment:

    python -m venv venv
    venv\Scripts\activate  # Windows
    source venv/bin/activate  # Linux/Mac
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Run the application:

    python src/main.py
    

Usage

Graphical User Interface

Run the standard application in GUI mode:

run_app.bat

Run the enhanced detection application with better small person detection:

run_enhanced_mode.bat

Run the integrated application with both standard and enhanced detection:

run_integrated_app.bat

Command-line options for the integrated application:

python src/main_integrated.py --enhanced-only --model googlenet --video path/to/video.mp4

Available options:

  • --enhanced-only: Start with only the enhanced detection tab visible
  • --model: Choose between googlenet or resnet
  • --video: Specify a video file to use for testing

Training a Model

Train a model from command line:

python src/main.py --mode train --model googlenet --epochs 30 --batch-size 32

Available options:

  • --model: Choose between googlenet or resnet
  • --data-dir: Specify the dataset directory
  • --epochs: Number of training epochs
  • --batch-size: Training batch size
  • --learning-rate: Initial learning rate

Evaluating a Model

Evaluate a trained model:

python src/main.py --mode evaluate --model googlenet --output-dir results

Model Architectures

This project implements two CNN architectures:

  • GoogleNet: A deep network with inception modules for efficient feature extraction
  • ResNet: A residual network that uses skip connections to enable very deep architectures

Both models are pre-trained on ImageNet and fine-tuned on the drowning detection dataset using transfer learning.

Dataset Organization

The dataset should be organized as follows:

data/
  ├── normal/
  │   ├── image1.jpg
  │   ├── image2.jpg
  │   └── ...
  └── drowning/
      ├── image1.jpg
      ├── image2.jpg
      └── ...

Results Visualization

After evaluation, the system generates:

  • Confusion matrices
  • ROC curves
  • Example predictions (correct and incorrect)
  • Detailed classification reports

These outputs are saved in the results directory.

Live Person Detection Features

The application now includes advanced real-time person detection features:

Person Detection and Drowning Classification

The system uses YOLO (You Only Look Once) for detecting people in video streams and images, then classifies:

  1. Whether the person is in water or on land
  2. If in water, whether the person is drowning

How the Detection Works

  • Person Detection: YOLO model identifies all people in the frame
  • Water Detection: Color-based segmentation identifies water areas
  • In-Water Classification: Checks if the lower portion of a person's bounding box overlaps with water
  • Drowning Detection: For people in water, uses the CNN model to classify drowning status

Using Live Detection Tab

  1. Select a video source (webcam or video file)
  2. Choose the drowning detection model (GoogleNet or ResNet)
  3. Click "Start Detection" to begin analysis
  4. The system will:
    • Draw bounding boxes around detected people
    • Label each person as "In Water" or "Not In Water"
    • For people in water, classify and alert if drowning is detected
    • Count and display statistics in real-time

Alerts and Notifications

  • Visual Alerts: Red bounding boxes and text for drowning persons
  • Alert Box: Changes to red with warning text when drowning is detected
  • Detection Log: Records all significant events with timestamps
  • Screenshot Feature: Capture evidence with the "Take Screenshot" button

Water Detection Customization

For different water environments (pools, oceans, rivers), you may need to adjust the water detection parameters in the detection.py file:

# Adjust these HSV color ranges for different water types
self.water_lower = np.array([100, 50, 50])  # Blue-ish colors lower bound
self.water_upper = np.array([140, 255, 255])  # Blue-ish colors upper bound

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages