Skip to content

Nithya162/Foam-Detection

Repository files navigation

🌊 Automated Water Quality Monitoring System

An intelligent foam detection system that monitors water quality in real-time using YOLOv8 computer vision and automated email notifications.

##Overview

This project implements an automated water quality monitoring solution that:

  • Detects foam presence in live video streams using YOLOv8 object detection
  • Monitors water flow continuously with OpenCV-based analysis
  • Sends automated alerts via email when foam is detected or streams are offline
  • Prevents duplicate processing with intelligent video tracking

✨ Key Features

  • Detection: YOLOv8 model trained for 25 epochs with optimized 224×224 resolution
  • Smart Notifications: Automated email system with 24-hour interval monitoring
  • Stream Validation: Real-time video stream availability checking
  • Water Flow Analysis: OpenCV-based flow detection with 10% pixel threshold
  • Duplicate Prevention: Tracks processed videos to avoid redundant analysis
  • Continuous Monitoring: 24/7 automated surveillance with configurable intervals

🛠️ Technology Stack

  • Deep Learning: YOLOv8 (Ultralytics)
  • Computer Vision: OpenCV
  • Email Service: SMTP with Gmail integration
  • Cloud Platform: Google Colab
  • Storage: Google Drive integration
  • Languages: Python 3.x

📋 Requirements

ultralytics
opencv-python
google-colab
smtplib (built-in)
subprocess (built-in)

🚀 Installation & Setup

  1. Clone the repository

    git clone https://github.com/yourusername/foam-detection.git
    cd foam-detection
  2. Install dependencies

    pip install -U ultralytics opencv-python
  3. Setup Google Drive (if using Colab)

    from google.colab import drive
    drive.mount('/content/drive')
  4. Configure email credentials

    # Update in the script
    TO_EMAIL = 'your-email@gmail.com'
    from_email = 'sender-email@gmail.com'
    from_password = 'your-app-password'  # Gmail App Password

🔧 Configuration

Model Training

!yolo task=detect mode=train model=yolov8m.pt data=data.yaml epochs=25 imgsz=224 plots=True

Key Parameters

  • Detection Confidence: 0.25
  • Image Size: 224×224 pixels
  • Monitoring Interval: 24 hours
  • Email Cooldown: 24 hours
  • Water Flow Threshold: 10% pixel activity

📊 System Architecture

Video Stream → YOLOv8 Detection → Water Flow Analysis → Email Notification
     ↓              ↓                    ↓                    ↓
Stream Check → Foam Detection → Flow Validation → Alert System

🎮 Usage

Training the Model

# Train YOLOv8 on your foam dataset
!yolo task=detect mode=train model=yolov8m.pt data=data.yaml epochs=25 imgsz=224

Running Detection

# Single prediction
!yolo task=detect mode=predict model=runs/detect/train6/weights/best.pt conf=0.25 source=your_video.mp4

# Continuous monitoring
python foam_detection.py

Email Notifications

The system automatically sends different types of alerts:

  • "No Foam Detected" - Water quality is good
  • ⚠️ "Foam Detected" - Foam present in water
  • 🔴 "No Live Stream" - Video stream unavailable
  • 💧 "No Water Flow Detected" - No water movement detected

📁 Project Structure

foam-detection/
├── foam_detection.py          # Main detection script
├── data/
│   ├── train/                # Training images
│   ├── val/                  # Validation images
│   ├── test/                 # Test videos
│   └── data.yaml             # Dataset configuration
├── runs/
│   └── detect/
│       └── train6/
│           └── weights/
│               └── best.pt   # Trained model weights
├── last_email_time.txt       # Email tracking
├── processed_videos.txt      # Video processing log
└── README.md

🔍 Detection Process

  1. Stream Validation: Checks if video stream is accessible
  2. Water Flow Analysis: Validates presence of water movement
  3. YOLOv8 Detection: Runs foam detection on video frames
  4. Result Processing: Analyzes detection outputs
  5. Notification: Sends appropriate email alerts
  6. Logging: Records processed videos to prevent duplicates

📈 Performance Metrics

  • Model: YOLOv8 Medium (yolov8m.pt)
  • Training Epochs: 25
  • Input Resolution: 224×224
  • Confidence Threshold: 0.25
  • Processing: Real-time video analysis
  • Monitoring: 24/7 continuous surveillance

Educational implementation demonstrating fundamental clustering concepts in machine learning.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors