Introducci贸n y Visi贸n General de SecureVision AI
Introducci贸n a SecureVision AI y CCTV
Fundamentos de Visi贸n Computarizada en CCTV
Procesamiento de Im谩genes y Fundamentos de OpenCV
Introducci贸n a OpenCV para An谩lisis de CCTV
Creaci贸n y An谩lisis de Heatmaps con OpenCV
Quiz: Procesamiento de Im谩genes y Fundamentos de OpenCV
Segmentaci贸n de Im谩genes con YOLO
Configuraci贸n de Modelos Preentrenados para Segmentaci贸n con YOLO
Integraci贸n de Segmentaci贸n en Tiempo Real y Generaci贸n de Heatmaps
Quiz: Segmentaci贸n de Im谩genes con YOLO
Detecci贸n de Objetos con YOLO
Introducci贸n a la Detecci贸n de Objetos con YOLO
Configuraci贸n y Uso de Modelos YOLO Preentrenados
Implementaci贸n de un Sistema de Conteo de Personas con YOLO
Quiz: Detecci贸n de Objetos con YOLO
Pose Estimation con Mediapipe
Fundamentos de Pose Estimation con Mediapipe
Seguimiento y An谩lisis de Miradas con Mediapipe
Generaci贸n de Heatmap de Miradas con Mediapipe y OpenCV
Quiz: Pose Estimation con Mediapipe
Entrenamiento y Creaci贸n de Modelos Personalizados con YOLO
Entrenamiento de un Modelo YOLO para Detectar Defectos en Soldaduras Industriales - Parte 1
Entrenamiento de un Modelo YOLO para Detectar Defectos en Soldaduras Industriales - Parte 2
Etiquetado de Im谩genes con Label Studio
Reflexi贸n y Cierre del Curso
You don't have access to this class
Keep learning! Join and start boosting your career
Real-time people detection using artificial intelligence has revolutionized the way businesses analyze customer behavior. This technology not only makes it possible to identify people, but also to accurately track their movements, which is invaluable for optimizing the layout of retail spaces and improving the customer experience. Automatic people counting using computer vision systems represents an efficient solution for analyzing traffic in commercial establishments.
To implement a customer counting system in a commercial establishment using YOLO (You Only Look Once), we need to follow several fundamental steps. This process begins with the installation of the necessary dependencies, mainly the Ultralytics library, which provides an efficient implementation of YOLO.
# Installing dependencies!pip install ultralytics
Once the dependencies are installed, we must load the video we want to analyze. In this case, we work with a file called "people_detection.mp4" that shows the movement of people in a commercial establishment with different sections.
# Definition of pathsvideo_path = "people_detection.mp4"output_path = "output_video.avi"
The next step is to configure the system to save the results of the analysis, including the people count and the tracking of each individual along the aisles of the store.
The key concept for people counting is line crossing detection. For this, we implement a function that calculates whether a point (the centroid of a detected person) crosses a predefined line. This mathematical function allows us to determine whether a person has passed from one side of a virtual line to the other.
# Function to detect if a point is to the right or left of a linedef is_point_right_of_line(point, line): x, y = point ( x1, y1), (x2, y2) = line return (y2 - y1) * (x - x1) - (x2 - x1) * (y - y1) > 0
To implement this solution, we need to define counting lines at strategic locations. In our example, we establish two lines: one for the clothing section and one for the sports section.
# Definition of counting linesline1 = [(130, 180), (25, 300)] # Line for clothing sectionline2 = [(350, 180), (450, 300)] # Line for sports section
Tracking people between consecutive frames is essential to avoid counting the same person multiple times. To achieve this, we implement a system that associates the centroids detected in the current frame with those of the previous frame.
# Parameters for trackingassociation_threshold = 50 # Threshold for associating detections between framescentroids_prev_frame = [] # List to store centroids from the previous frame.
The complete detection and counting process is performed frame by frame following these steps:
# YOLO model initializationmodel = YOLO('yolov8n.pt')
# Counters for each linecounter_line1 = 0counter_line2 = 0
# Processing video frame by framewhile True: ret, frame = cap.read() if not ret: break
# Detecting people with YOLO results = model(frame)
# Processing detections # .. ...
# Checking line crossings # ...
# Updating counters # ...
# Displaying results # ...
# Save processed frame out.write(frame)
# Update centroids for next frame centroids_prev_frame = current_centroids.copy()
During implementation, we may encounter some challenges that affect the counting accuracy. The most common problems include false positive detection when several people are very close to each other and lack of detection when people move quickly.
To improve the accuracy of the system, we can adjust several parameters:
# Filter out detections with low confidenceconfidence_threshold = 0.7boxes = boxes[confidences >= confidence_threshold].
# Adjusting the position of line 1 line1 = [(130, 120), (25, 300)] # Modified from (130, 180)
# Reduceassociation_threshold association_threshold = 30 # Reduced from 50
These settings allow us to significantly improve the accuracy of the system. For example, in the case where two people walking together were erroneously counted as three, after the adjustments, the system correctly counts only two people.
The last challenge is to detect a person running quickly out of the establishment. To capture this case, further tuning of the parameters is needed, especially reducing the confidence threshold for detecting fast movements and adjusting the position of the lines to ensure that they cross the exit routes.
Implementing people counting systems with artificial intelligence provides businesses with valuable information about their customers' behavior, allowing them to optimize the layout of their spaces, improve the customer experience and make data-driven decisions. Have you implemented any similar solutions or have ideas for improving this system? Share your experience in the comments.
Contributions 4
Questions 0
Want to see more contributions, questions and answers from the community?