A webcam checks people are standing in line and spacing out, with voice reminders.
Built and tested by Shahan Fathima K · Industrial Robotics Institute
Python 3.11, OpenCV, MediaPipe, pyttsx3, NumPy
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.
| Component | Qty |
|---|---|
| Laptop / PC | 1 |
| Webcam | 1 |
| Speaker | 1 |
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()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.
You need: Laptop / PC (1), Webcam (1), Speaker (1). Software: Python 3.11, OpenCV, MediaPipe, pyttsx3, NumPy.
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.
The complete, tested Python code is free on this page. Copy it into Python 3.11 and upload it and run it.
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.