Skip to content

patatapython/Sistema-Tracking-Farmacia

Repository files navigation

System Logo

Pharmacy People Counting & Tracking System

Computer vision-powered customer flow analysis for retail pharmacies

Python YOLOv5 YOLOv8 OpenCV License


Leer en Espanol


Overview

Master's Thesis (TFM) project: a real-time system for counting and tracking people inside pharmacies using deep learning. It detects customers with YOLO, tracks them with DeepSORT, analyzes dwell time per zone, and generates heatmaps — all with built-in GDPR-compliant privacy (real-time pixelation, local processing only).


Key Features

Detection & Counting

  • YOLOv5 person detection with virtual counting lines
  • Entry/exit tracking with real-time totals
  • Configurable confidence thresholds
  • JSON export of all counting data

Tracking & Analytics

  • YOLOv8 + DeepSORT persistent tracking
  • Polygonal zone definition with dwell time
  • Automatic heatmap generation
  • Per-person trajectory and zone history

Privacy & Compliance

  • Real-time face/body pixelation (toggle with P)
  • 100% local processing — no external data transfer
  • GDPR compliant by design

User Interface

  • Desktop GUI built with CustomTkinter
  • Interactive line and zone configuration tools
  • Integrated video preview and controls
  • One-click processing start/stop

Gallery

Main Interface

Main interface Processing panel
Control panel Processing & real-time controls

Configuration Tools

Line creator Zone creator
Virtual counting lines Polygonal zone definition

Counting & Tracking

Counting Privacy mode
Real-time people counting Privacy pixelation enabled
Tracking Heatmap
DeepSORT trajectory tracking Generated heatmap

Architecture

graph TD
    A[GUI - CustomTkinter] -->|Tools Tab| B[Configuration]
    B --> B1[Define Virtual Lines]
    B --> B2[Define Polygonal Zones]
    A -->|Processing Tab| C[Detection & Analysis]
    C --> C1[YOLOv5 Counting]
    C --> C2[YOLOv8 + DeepSORT Tracking]
    C1 --> D[Export]
    C2 --> D
    D --> D1[datos_conteo/ JSON]
    D --> D2[datos_tracking/ JSON]
    D --> D3[heatmaps/ PNG]
Loading

Tech Stack

Python YOLOv5 YOLOv8 OpenCV DeepSORT CustomTkinter NumPy


Quick Start

Prerequisites

  • Python 3.8+
  • pip

Installation

git clone https://github.com/patatapython/Sistema-Tracking-Farmacia.git
cd Sistema-Tracking-Farmacia
python -m venv venv
source venv/bin/activate  # Linux/Mac
# venv\Scripts\activate   # Windows
pip install -r requirements.txt

Download YOLO Models

# YOLOv5s (~15MB)
wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt
# YOLOv8s (~22MB)
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt

Run

python uiFarmacia_logo.py

Usage

  1. Configure (Tools tab): define counting lines and polygonal zones interactively
  2. Process (Processing tab): select video source, start counting or tracking
  3. Analyze: results are automatically exported to datos_conteo/, datos_tracking/, and heatmaps/
Output data formats

Counting (datos_conteo/*.json):

{
  "entradas": 15,
  "salidas": 12,
  "total_personas": 27,
  "personas_dentro": 3,
  "timestamp": "2025-09-05T14:42:45.598Z"
}

Tracking (datos_tracking/*.json):

{
  "timestamp": "20250905_144534",
  "total_personas": 5,
  "sistema_tracking": "DeepSORT",
  "personas": [
    {
      "id": 1,
      "zona_actual": "mostrador",
      "tiempo_en_zona_actual": 45.2,
      "historial_zonas": [
        {
          "zona": "entrada",
          "tiempo_entrada": "2025-09-05T14:40:00",
          "tiempo_salida": "2025-09-05T14:40:30",
          "duracion": 30.0
        }
      ]
    }
  ]
}

Project Structure

Sistema-Tracking-Farmacia/
├── uiFarmacia_logo.py      Main GUI application
├── conteo.py               YOLOv5 people counting module
├── tracking.py             YOLOv8 + DeepSORT tracking module
├── crear_linea.py          Interactive counting line creator
├── crear_zonas.py          Interactive polygonal zone creator
├── config/                 Line and zone configuration files
├── datos_conteo/           Counting results (JSON)
├── datos_tracking/         Tracking results (JSON)
├── heatmaps/               Generated heatmap images (PNG)
├── extras/Imagenes/        Screenshots for documentation
├── Logo/                   Application logo
└── requirements.txt        Python dependencies

Credits

Developed as a Master's Thesis (TFM) by Guillermopatatapython

Special thanks to:


License

Distributed under the MIT License. See LICENSE for details.


Built with Python and open-source computer vision

About

Real-time people counting & tracking system for pharmacies using YOLOv5/YOLOv8 + DeepSORT with heatmaps and GDPR-compliant privacy

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages