Skip to content

Real-time person detection and tracking system using YOLOv5, DeepSort, OpenCV, and Flask. Saves detection events and images to a MySQL database. Web interface for live video stream and detection history.

Notifications You must be signed in to change notification settings

gulis-dev/safeEye

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafeEye

SafeEye is an advanced person detection and tracking system built with Python. It uses computer vision and deep learning technologies to detect and track people in real time from a webcam stream. The system stores detections in a MySQL database, saves images of detected people, and provides a simple web interface for live video streaming and browsing detection history.

Features

  • Real-time person detection using YOLOv5 (deep learning object detection).
  • Person tracking with DeepSort algorithm—each person gets a unique ID.
  • Web interface for live video streaming (Flask-based).
  • Detection history: browse all detected people, their images, timestamps, and IDs.
  • Automatic photo saving of newly detected persons.
  • MySQL database integration for persistent storage of detections.
  • Simple, responsive web frontend.
  • CORS enabled for easy integration with external frontends.

How It Works

  1. Live video is captured from your default webcam.
  2. YOLOv5 detects people in each frame.
  3. DeepSort tracker assigns and maintains unique IDs for tracked individuals.
  4. Detected persons are saved as cropped images in the static/tracked_persons directory.
  5. Detection events are recorded in a MySQL database (track_id, timestamp, image path).
  6. Web interface provides:
    • / for live video stream
    • /data for browsing detection history with images

Requirements

  • Python 3.7+
  • MySQL server
  • Webcam

Python dependencies

Install required libraries:

pip install -r requirements.txt

Main packages used:

  • opencv-python
  • torch
  • ultralytics/yolov5 (via torch.hub)
  • deep_sort_realtime
  • flask
  • flask_cors
  • mysql-connector-python

Database Setup

Create a MySQL database and the required table:

CREATE DATABASE person_tracker;
USE person_tracker;

CREATE TABLE tracked_persons (
    id INT AUTO_INCREMENT PRIMARY KEY,
    track_id INT NOT NULL,
    timestamp DATETIME NOT NULL,
    image_path VARCHAR(255) NOT NULL
);

Adjust MySQL credentials in main.py if needed:

db_config = {
    'host': 'localhost',
    'user': 'admin',
    'password': 'admin',
    'database': 'person_tracker'
}

Running the Application

  1. Make sure your MySQL server is running.
  2. Plug in your webcam.
  3. Run the application:
python main.py

The server will start on http://0.0.0.0:5761/.

Web Endpoints

  • / — Live video stream.
  • /video_feed — MJPEG video stream (used by the main page).
  • /data — Detection history with images of tracked persons.

Directory Structure

safeEye/
├── main.py
├── requirements.txt
├── static/
│   └── tracked_persons/
└── README.md

Notes

  • The app saves images only for newly detected (unique) people.
  • The live stream overlays bounding boxes, IDs, and detection times on the video.
  • All data is persistent as long as the database and static/tracked_persons directory are preserved.

License

This project is licensed under the MIT License.


SafeEye — Real-time person detection and tracking for security, analytics, and smart monitoring.

About

Real-time person detection and tracking system using YOLOv5, DeepSort, OpenCV, and Flask. Saves detection events and images to a MySQL database. Web interface for live video stream and detection history.

Resources

Stars

Watchers

Forks

Packages

No packages published