AI & MLIntermediatePRJ-097

AI Smart Queue Discipline Monitor

A webcam checks people are standing in line and spacing out, with voice reminders.

Built and tested by Shahan Fathima K · Industrial Robotics Institute

Laptop / PC with webcam

Python 3.11, OpenCV, MediaPipe, pyttsx3, NumPy

LevelIntermediate
Build time1–2 hours
BoardLaptop / PC with webcam
Parts3 components

What is the AI Smart Queue Discipline Monitor?

A computer-vision queue monitor for banks, hospitals and public offices. MediaPipe Pose tracks people’s shoulders through a webcam; the program checks whether they are lined up and keeping distance, shows GOOD, NOT IN LINE or TOO CLOSE on screen, and speaks reminders like "Please maintain distance" every few seconds.

How it works

  1. The webcam captures the queue and MediaPipe Pose finds body landmarks.
  2. The left shoulder position is used as each person’s location.
  3. If the positions spread too far sideways, the queue is NOT IN LINE.
  4. If two people are closer than the set distance, it shows TOO CLOSE.
  5. A voice alert speaks the right reminder at most every 5 seconds.

Parts list

ComponentQty
Laptop / PC1
Webcam1
Speaker1

Software

  • Python 3.11
  • OpenCV
  • MediaPipe
  • pyttsx3
  • NumPy

How to build the AI Smart Queue Discipline Monitor

  1. Install Python 3.11 and tick "Add Python to PATH".
  2. Open a terminal and run: pip install opencv-python mediapipe pyttsx3 numpy
  3. Paste the code into a new Python file and run it.
  4. Point the webcam along the queue.
  5. Adjust LINE_THRESHOLD and DISTANCE_THRESHOLD for your space. Press Esc to quit.

AI Smart Queue Discipline Monitor code

Complete, tested Python code for this project. Copy it into Python 3.11 and upload it and run it.

import cv2
import mediapipe as mp
import pyttsx3
import numpy as np
import time
import threading

# -------------------- VOICE ENGINE --------------------
engine = pyttsx3.init()
engine.setProperty('rate', 160)
speech_lock = False


def speak(text):
    global speech_lock
    if speech_lock:
        return
    speech_lock = True

    def run():
        global speech_lock
        engine.say(text)
        engine.runAndWait()
        speech_lock = False

    threading.Thread(target=run).start()


# -------------------- MEDIAPIPE --------------------
mp_pose = mp.solutions.pose
pose = mp_pose.Pose()
mp_draw = mp.solutions.drawing_utils

cap = cv2.VideoCapture(0)

LINE_THRESHOLD = 50
DISTANCE_THRESHOLD = 80
last_voice_time = 0


def check_alignment(points):
    if len(points) < 2:
        return True
    x_vals = [p[0] for p in points]
    return max(x_vals) - min(x_vals) < LINE_THRESHOLD


def check_distance(points):
    warnings = []
    for i in range(len(points)):
        for j in range(i + 1, len(points)):
            if np.linalg.norm(np.array(points[i]) - np.array(points[j])) < DISTANCE_THRESHOLD:
                warnings.append("too_close")
    return warnings


while True:
    ret, frame = cap.read()
    if not ret:
        break
    frame = cv2.flip(frame, 1)
    results = pose.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))

    points = []
    if results.pose_landmarks:
        h, w, _ = frame.shape
        sh = results.pose_landmarks.landmark[mp_pose.PoseLandmark.LEFT_SHOULDER]
        points.append((int(sh.x * w), int(sh.y * h)))
        mp_draw.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)

    aligned = check_alignment(points)
    distance_issues = check_distance(points)
    now = time.time()

    if now - last_voice_time > 5:
        if not aligned:
            speak("Please stand in a straight line")
            last_voice_time = now
        elif "too_close" in distance_issues:
            speak("Please maintain distance")
            last_voice_time = now
        elif points:
            speak("Queue is moving properly")
            last_voice_time = now

    status, color = "GOOD", (0, 255, 0)
    if not aligned:
        status, color = "NOT IN LINE", (0, 0, 255)
    elif "too_close" in distance_issues:
        status, color = "TOO CLOSE", (0, 165, 255)

    cv2.putText(frame, f"Status: {status}", (10, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, color, 3)
    cv2.putText(frame, "AI Queue Discipline System", (10, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
    cv2.imshow("Smart Queue AI", frame)

    if cv2.waitKey(1) & 0xFF == 27:   # Esc to quit
        break

cap.release()
cv2.destroyAllWindows()

Real-world uses

  • Banks and post offices
  • Hospitals and clinics
  • Airports and stations
  • Learning pose detection

Frequently asked questions

What is a AI Smart Queue Discipline Monitor?

A computer-vision queue monitor for banks, hospitals and public offices. MediaPipe Pose tracks people’s shoulders through a webcam; the program checks whether they are lined up and keeping distance, shows GOOD, NOT IN LINE or TOO CLOSE on screen, and speaks reminders like "Please maintain distance" every few seconds.

What components are needed for the AI Smart Queue Discipline Monitor?

You need: Laptop / PC (1), Webcam (1), Speaker (1). Software: Python 3.11, OpenCV, MediaPipe, pyttsx3, NumPy.

Is the AI Smart Queue Discipline Monitor project good for beginners?

It is rated intermediate and takes about 1–2 hours to build, using the Laptop / PC with webcam. The guide on this page explains every connection and step.

Where can I get the code for the AI Smart Queue Discipline Monitor?

The complete, tested Python code is free on this page. Copy it into Python 3.11 and upload it and run it.

Do I need any hardware for the AI Smart Queue Discipline Monitor?

No kit is needed. This project runs on a laptop or PC with webcam. For help with the setup, message IRI on WhatsApp at +91 86060 82634.

Industrial Robotics Institute
Logo