Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Ή Queue Monitoring using YOLOv8 (Simulated Multi-Camera Setup)

This project demonstrates how to monitor queues and count people using YOLOv8 (from Ultralytics) with a single video, by simulating a multi-camera setup.

πŸ“½οΈ Video Credit: March Networks on YouTube 🎯 Goal: Track and count people in two queue zones with real-time visualization.


πŸš€ Features

  • People detection and tracking using YOLOv8m
  • Real-time zone-based counting
  • Estimation of waiting time for each person
  • Simulated 2-camera view from a single video
  • Annotated video output with bounding boxes, labels, and statistics

🧩 Requirements

Install the necessary packages:

pip install ultralytics opencv-python imageio matplotlib

πŸ“ Project Structure

β”œβ”€β”€ main.py                      # Core processing and annotation logic
β”œβ”€β”€ input/
β”‚   └── que.mp4                  # Input video
β”œβ”€β”€ output/
β”‚   └── step4_fully_customizable_output.mp4
β”œβ”€β”€ display.py                   # Code to visualize middle frames
└── README.md

πŸŽ₯ Video Setup & Methodology

  • The original video shows a top-down camera above a cashier counter.

  • Since only one video is available, it is logically split into two zones:

    • Camera 1 Zone (Left): Where people enter
    • Camera 2 Zone (Right): Where people reach the cashier
  • Using YOLOv8 tracking IDs, each person is tracked across both zones to avoid double-counting.


🧠 How It Works

  1. Load Video
  2. Split frame into two logical zones
  3. Track people using YOLOv8 with object ID persistence
  4. Count individuals in each zone
  5. Estimate wait time in queue
  6. Overlay statistics and bounding boxes
  7. Save annotated video

πŸ–ΌοΈ Sample Output (Middle 300 Frames)

from IPython.display import HTML
HTML(display_middle_300("output/step4_fully_customizable_output.mp4").to_html5_video())

πŸ§ͺ Core Functions

  • get_video_details(path): Shows video metadata
  • display_middle_300(path): Preview video using 300 central frames
  • is_inside_area(): Determines if person is in cashier/queue area
  • generate_color(id): Assigns consistent color per person ID
  • boxes_intersect(): Checks bounding box overlap with zone

πŸ” Model Used

  • Model: yolov8m.pt
  • Class: 0 (person)
  • Confidence Threshold: Auto-handled by model default
  • Tracking: Enabled (model.track())

🧠 Core Idea: Wait Time Counting / Analysis

The wait time analysis in this project focuses on measuring how long each person spends in the queue β€” from the moment they enter a defined β€œqueue area” until they reach the cashier.


βœ… How It Works

  1. Unique ID Tracking Each person is assigned a persistent ID by the YOLOv8 tracker.

  2. First Seen Frame The system records the frame number when each person’s ID is first detected in the queue area:

    if track_id not in id_first_seen:
        id_first_seen[track_id] = frame_number
  3. Time Calculation For every frame after, the time waited is calculated as:

    time_waited = (current_frame - first_seen_frame) / fps
  4. Queue Zone Filtering Time is only counted if the person is:

    • In the queue area (not random walking)
    • Not yet at the cashier area
  5. Real-Time Overlay On the video, the system displays:

    • ID, Confidence, and Wait Time
    • Highlighted zones for Queue and Cashier

πŸ“Œ Purpose of Wait Time Analysis

  • βœ… Customer Flow Insight – Understand how long customers are waiting
  • βœ… Queue Management – Detect bottlenecks in real-time
  • βœ… Performance Monitoring – Evaluate service efficiency at counters
  • βœ… No Duplication – IDs ensure people are counted only once

πŸ”„ Example Label

A person in the queue might get a label like:

ID 12 | 87.3% | Queue | 9.5s

This shows:

  • Their unique ID
  • Detection confidence
  • Current zone: Queue
  • Total time spent in queue so far

πŸ§‘β€πŸ’» Example Snippet (Main Loop)

results = model.track(frame, persist=True, classes=[0], verbose=False)
for box in results[0].boxes:
    if box.id is None:
        continue
    # Extract tracking ID, bounding box, and confidence

πŸ“¦ Output

  • The final annotated video is saved at:
/kaggle/working/step4_fully_customizable_output.mp4

It includes:

  • Bounding boxes with ID and confidence
  • Zone-based person counts
  • Wait time for each tracked person
  • Visualized cashier and queue areas

πŸ“„ License

This project is licensed under the terms of the LICENSE.txt. See the file for details.

About

Queue Monitoring with YOLOv8 πŸŽ₯ simulates multi-camera views πŸ“Ή from a single video to track and count people πŸ‘₯ in queue zones, estimating wait times ⏳ with real-time visualization πŸ“Š and annotated outputs πŸ–ΌοΈ.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages