Skip to content

acass/IOT-Security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI-Driven Home Security Target Detection System

A real-time home security application that uses YOLOv8 computer vision to detect predefined targets (people, objects) and automatically triggers MQTT notifications when matches are detected.

Overview

This system monitors video feeds in real-time, detects objects or persons using YOLOv8, and publishes MQTT messages when configured targets are detected. Perfect for home automation, security monitoring, and IoT integration.

Key Features

  • Real-time Detection: Process video feeds from webcams, RTSP streams, or video files
  • YOLOv8 Integration: State-of-the-art object detection with multiple model options
  • Target Matching: Configure specific objects or people to monitor
  • MQTT Publishing: Automatic notifications to your MQTT broker with detection metadata
  • Intuitive UI: Streamlit-based interface for easy configuration and monitoring
  • Live Visualization: See detections in real-time with bounding boxes
  • Detection Logging: Track all detection events with timestamps and confidence scores

Use Cases

  • Home security monitoring
  • Package delivery detection
  • Pet monitoring
  • Specific object tracking
  • Integration with Home Assistant, Node-RED, or other home automation platforms

Quick Start

Prerequisites

  • Python 3.10 or higher
  • Webcam, RTSP camera, or video file
  • MQTT broker (local or remote)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd customIOTSecurity
  2. Create a virtual environment (recommended)

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt

    The first time you run the application, YOLOv8 will automatically download the selected model.

Running the Application

streamlit run app.py

The application will open in your default web browser at http://localhost:8501

๐ŸŽฎ Usage Guide

1. Configure Video Source

In the sidebar, select your video source:

  • Webcam: Choose camera index (usually 0 for built-in camera)
  • RTSP Stream: Enter RTSP URL (e.g., rtsp://192.168.1.100:554/stream)
  • Video File: Provide path to local video file

2. Select Detection Model

Choose a YOLOv8 model based on your needs:

  • yolov8n.pt: Nano - Fastest, lowest accuracy
  • yolov8s.pt: Small - Balanced (recommended)
  • yolov8m.pt: Medium - More accurate
  • yolov8l.pt: Large - Most accurate, slower
  • Custom: Provide path to your custom trained model

Click "Load Model & Get Classes" to see available detection classes.

3. Configure Target Detection

  • Target Class: Select the object/person class to monitor (e.g., "person", "cell phone", "bottle")
  • Confidence Threshold: Set minimum confidence (0.0-1.0) for valid detections

4. Setup MQTT Connection

Configure your MQTT broker:

  • Broker Address: Hostname or IP address
  • Port: Usually 1883 for standard MQTT
  • Topic: Default is irvine/home/bedroom/item (customize as needed)
  • Username/Password: Optional authentication credentials
  • Include Image: Optionally include base64-encoded detection crop in payload

5. Start Detection

Click "Start Detection" to begin monitoring. The system will:

  1. Connect to your video source
  2. Load the YOLOv8 model
  3. Start processing frames in real-time
  4. Display live feed with bounding boxes
  5. Publish MQTT messages when targets are detected

MQTT Message Format

When a target is detected, the system publishes a JSON message to the configured topic:

{
  "class": "person",
  "confidence": 0.92,
  "timestamp": "2025-11-16T12:34:56.789",
  "bbox": [120, 45, 340, 580],
  "frame_id": 1034,
  "image": "<base64-encoded-jpeg-optional>"
}

Fields:

  • class: Detected object class name
  • confidence: Detection confidence score (0.0-1.0)
  • timestamp: ISO 8601 formatted timestamp
  • bbox: Bounding box coordinates [x1, y1, x2, y2]
  • frame_id: Sequential frame identifier
  • image: Optional base64-encoded JPEG of detection crop

Architecture

Components

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Streamlit UI (app.py)                โ”‚
โ”‚  - Configuration Controls  - Live Video Display         โ”‚
โ”‚  - Statistics Dashboard    - Detection Logs             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ”‚               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Video    โ”‚  โ”‚   Detection    โ”‚
โ”‚   Source   โ”‚โ”€โ–ถโ”‚    Engine      โ”‚
โ”‚            โ”‚  โ”‚   (YOLOv8)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚     MQTT      โ”‚
                  โ”‚   Publisher   โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Modules

  • app.py: Main Streamlit application and UI
  • video_source.py: Video capture handler (webcam, RTSP, file)
  • detection_engine.py: YOLOv8 detection and target matching
  • mqtt_publisher.py: MQTT client with retry logic
  • utils.py: Image processing and annotation utilities

Configuration

Environment Variables

You can set default values using environment variables:

export MQTT_BROKER="localhost"
export MQTT_PORT="1883"
export MQTT_TOPIC="irvine/home/bedroom/item"
export DEFAULT_MODEL="yolov8s.pt"

Custom Models

To use a custom trained YOLOv8 model:

  1. Train your model using Ultralytics YOLOv8
  2. Save the .pt file
  3. Select "Custom" in the model dropdown
  4. Provide the path to your model file

Troubleshooting

Camera Issues

  • Camera not detected: Try different camera indices (0, 1, 2...)
  • RTSP connection fails: Verify URL format and network connectivity
  • Video file won't load: Check file path and format (MP4, AVI supported)

MQTT Connection Issues

  • Connection refused: Verify broker is running and accessible
  • Authentication failed: Check username/password
  • Messages not received: Verify topic name matches subscriber

Performance Issues

  • Low FPS: Use a smaller model (yolov8n.pt) or reduce video resolution
  • High CPU usage: Consider using GPU acceleration (install torch with CUDA)
  • Detection latency: Lower confidence threshold or use faster model

Performance

Expected performance on standard hardware:

Model FPS (CPU) FPS (GPU) Accuracy
yolov8n 25-30 100+ Good
yolov8s 15-20 80+ Better
yolov8m 8-12 50+ Great
yolov8l 4-8 30+ Best

Security Considerations

  • Network Security: Use TLS/SSL for MQTT connections in production
  • Authentication: Always use MQTT username/password in production
  • Camera Access: Limit network exposure of camera feeds
  • Data Privacy: Be mindful of privacy when capturing video

Roadmap

Future enhancements (v2.0+):

  • Multi-camera support
  • Multiple simultaneous targets
  • Face recognition integration
  • Push notifications (Pushover, Telegram)
  • Historical event database
  • Web API for integration
  • Mobile app support
  • Cloud deployment options

License

[Specify your license here]

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

Support

For issues, questions, or suggestions, please open an issue on GitHub.

Acknowledgments


Version: 1.0 Last Updated: 2025-11-16

About

A real-time home security application that uses YOLOv8 computer vision to detect predefined targets (people, objects) and automatically triggers MQTT notifications when matches are detected.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages