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
People traffic analysis in commercial spaces has evolved significantly thanks to the integration of advanced computer vision techniques. The combination of traditional image processing with segmentation models such as YOLO allows for much more accurate results focused exclusively on human movement, eliminating the visual noise that previously hindered these analyses. This technology is transforming the way businesses understand their customers' behavior in physical space.
The initial problem with traditional image processing is that it detects any moving element, without discriminating whether they are people or other objects. This generates "noise" in the data, such as when a rope or other element moves and is incorrectly detected as relevant traffic.
The implemented solution combines two powerful techniques:
The result is a refined hitmap that exclusively shows the movement of people, eliminating false positives and providing much cleaner and more useful data for analysis.
To implement this solution we need to combine traditional image processing with segmentation using YOLO. The process can be divided into the following steps:
The basic code for this implementation would be:
# Install dependencies!pip install ultralytics
# Necessary importsimport cv2import numpy as npfrom ultralytics import YOLO
# Define video pathvideo_path = "data/video.mp4"
# Configure background extractorbg_subtractor = cv2.createBackgroundSubtractorMOG2()
# Initialize refined hitmaphitmap_refined hitmap = np.zeros((height, width), dtype=np.uint8)
# Load YOLO model for segmentationmodel = YOLO('yolov8n-seg.pt')
# Open videocap = cv2.VideoCapture(video_path)
while True: ret, frame = cap.read() if not ret: break
# Motion detection (image processing) fg_mask = bg_subtractor.apply(frame) thresh = cv2.threshold(fg_mask, 200, 255, cv2.THRESH_BINARY)[1]
# Segmentation with YOLO results = model(frame, verbose=False) result = results[0]
# Create segmentation mask seg_mask = np.zeros_like(fg_mask)
if len(result) > 0: for seg, cls in zip(result.masks.data, result.boxes.cls): # Only consider people (class 0) if cls == 0: # Convert segmentation to binary mask segment = seg.cpu().numpy() # Resize to frame size segment = cv2.resize(segment, (width, height)) seg_mask = np.logical_or(seg_mask, segment).astype(np.uint8) * 255
# Combine masks (motion + segmentation) refined_mask = cv2.bitwise_and(thresh, seg_mask)
# Update hitmap hitmap_refined = cv2.add(hitmap_refined, refined_mask)
cap.release()
This code combines motion detection with segmentation to create a hitmap that exclusively shows the movement of people.
Implementing segmentation with YOLO for traffic analysis offers significant benefits:
In the example shown, it was possible to solve the specific problem of a moving rope that was previously incorrectly detected as relevant traffic. With segmentation, the system now ignores the rope and focuses exclusively on people.
To implement this solution in Google Colab, it is important to ensure that you have access to a GPU to speed up processing. The process is similar to the local one, but with some additional considerations:
!wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-seg.pt
The code for Google Colab is essentially the same, but optimized to directly generate the final hitmap without displaying each frame during processing, which significantly speeds up the execution.
A common problem is that YOLO may not automatically download the model. If this happens:
wget
command to download it manually.This approach ensures that you have access to the model even when the automatic download fails.
The results of implementing segmentation with YOLO for traffic analysis are noticeably superior to traditional methods:
In the examples shown, the processing time was approximately 2 minutes and 15 seconds for a complete video using GPU, demonstrating the efficiency of this solution.
The combination of traditional image processing with YOLO segmentation represents a significant advance in human traffic analysis. This technique not only improves data accuracy, but also provides more valuable information for business decision making. The next natural step would be to implement a people counter to quantify traffic in different areas of the retail space, taking the analysis to an even deeper level.
Contributions 1
Questions 0
Want to see more contributions, questions and answers from the community?