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
Object detection is one of the most fascinating and useful applications of computer vision. With the advancement of pre-trained models such as YOLO (You Only Look Once), it is now possible to implement robust detection systems with relative ease. In this content, we will explore how to create our first object detector using YOLOv11, a model capable of identifying up to 80 different classes of objects in real time.
To start working with object detection, we need to configure our environment with the appropriate libraries. The YOLO model in its version 11 allows us to detect a wide variety of objects such as books, cups, cars and teddy bears, among others. The accuracy of the detection will depend on the angle and conditions in which the image is captured.
For the implementation we will need:
The first step is to load the pre-trained model and configure the video capture:
# We import the necessary librariesimport cv2import timefrom ultralytics import YOLO
# We load the YOLOv11 model model = YOLO('yolov11n.pt')
# We start the video capturecap = cv2.VideoCapture(1) # Use 0 if there is only one camera
# Set the window size for full screencap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
Once the environment is set up, we can start processing each frame of the video to detect objects. It is important to measure the processing time between frames to evaluate the performance of our system.
The next step is to capture each frame, process it with the YOLO model and visualize the results:
while True: # We capture the frame ret, frame = cap.read() if not ret: break
# We measure the time before processing start_time = time.time()
# We process the frame with YOLO results = model(frame)
# We calculate the latency latency = time.time() - start_time
# We access the first result result = results[0]
# We get the detections (boxes) boxes = result.boxes
# Process each detection for box in boxes: # Get the coordinates of the bounding box x1, y1, x2, y2 = box.xyxy[0] x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2), int(y2)
# Get the confidence and class confidence = box.conf[0] class_id = int(box.cls[0]) class_name = result.names[class_id]
# We draw the rectangle and label cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2) label = f"{class_name}: {confidence:.2f}" cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 0), 2)
# Show latency in frame cv2.putText(frame, f "Latency: {latency:.4f}s", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0, 255), 2)
# Show frame cv2.imshow("Object Detection", frame)
# Exit with key 'q' if cv2.waitKey(1) == ord('q'): break
cap.release()cv2.destroyAllWindows()
In this code, for each detected object, we obtain:
The bounding box is defined by two coordinates: the upper left (x1, y1) and the lower right (x2, y2). These coordinates allow us to draw a rectangle around the detected object.
A very useful feature is the ability to filter the detections to show only the objects we are interested in. For example, if we only want to detect people, we can modify our code to filter by the class "person" (which has ID 0 in YOLO) and set a minimum confidence threshold.
# We define the class we want to detect (0 = person)target_class = 0
# We define the confidence thresholdconfidence_threshold = 0.7
# In the processing loop, we modify the detection part:for box in boxes: # We get the confidence and the class confidence = box.conf[0] class_id = int(box.cls[0])
# We only process if it is the target class and exceeds the confidence threshold if class_id == target_class and confidence >= confidence_threshold: # We get the coordinates of the bounding box x1, y1, x2, y2 = box.xyxy[0] x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2), int(y2)
class_name = result.names[class_id]
# Draw the rectangle and label cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2) label = f"{class_name}: {confidence:.2f}" cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
With this modification, our detector will only show people with a confidence level higher than 0.7 (70%). This is especially useful in applications where we are only interested in a specific type of object and we want to avoid false positives.
The YOLOv11 model comes pre-trained to detect 80 different classes of objects. Some of these classes include:
This versatility makes YOLO a powerful tool for a wide range of computer vision applications.
Object detection with YOLO opens up a world of possibilities in diverse industries, from security and surveillance to industrial automation and behavioral analysis. With the code we've explored, you now have the foundation to implement your own object detection system. What practical applications can you imagine for this technology in your field? Share your ideas in the comments.
Contributions 1
Questions 1
Want to see more contributions, questions and answers from the community?