Zum Inhalt springen

Analytics using Ultralytics YOLO11

Einführung

This guide provides a comprehensive overview of three fundamental types of data visualizations: line graphs, bar plots, and pie charts. Each section includes step-by-step instructions and code snippets on how to create these visualizations using Python.



Pass auf: How to generate Analytical Graphs using Ultralytics | Line Graphs, Bar Plots, Area and Pie Charts

Visuelle Muster

LiniendiagrammBar PlotTortendiagramm
LiniendiagrammBar PlotTortendiagramm

Warum Diagramme wichtig sind

  • Liniendiagramme sind ideal, um Veränderungen über kurze und lange Zeiträume zu verfolgen und um Veränderungen für mehrere Gruppen über denselben Zeitraum zu vergleichen.
  • Balkendiagramme hingegen eignen sich für den Vergleich von Mengen über verschiedene Kategorien hinweg und zeigen Beziehungen zwischen einer Kategorie und ihrem Zahlenwert.
  • Schließlich sind Kreisdiagramme gut geeignet, um die Proportionen zwischen den Kategorien zu veranschaulichen und Teile eines Ganzen darzustellen.

Analytik Beispiele

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="line",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="pie",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="bar",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="area",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Argument Analytics

Hier ist eine Tabelle mit den Analytics Argumente:

NameTypStandardBeschreibung
analytics_typestrlineType of graph i.e "line", "bar", "area", "pie"
modelstrNonePath to Ultralytics YOLO Model File
line_widthint2Linienstärke für Begrenzungsrahmen.
showboolFalseFlagge zur Steuerung, ob der Videostream angezeigt werden soll.

Argumente model.track

ArgumentTypStandardBeschreibung
sourcestrNoneSpecifies the source directory for images or videos. Supports file paths and URLs.
persistboolFalseEnables persistent tracking of objects between frames, maintaining IDs across video sequences.
trackerstrbotsort.yamlSpecifies the tracking algorithm to use, e.g., bytetrack.yaml oder botsort.yaml.
conffloat0.3Sets the confidence threshold for detections; lower values allow more objects to be tracked but may include false positives.
ioufloat0.5Sets the Intersection over Union (IoU) threshold for filtering overlapping detections.
classeslistNoneFilters results by class index. For example, classes=[0, 2, 3] only tracks the specified classes.
verboseboolTrueControls the display of tracking results, providing a visual output of tracked objects.

Fazit

Für eine effektive Datenanalyse ist es wichtig zu wissen, wann und wie du die verschiedenen Arten von Visualisierungen einsetzen solltest. Liniendiagramme, Balkendiagramme und Tortendiagramme sind grundlegende Werkzeuge, die dir helfen können, die Geschichte deiner Daten klarer und effektiver zu vermitteln.

FAQ

How do I create a line graph using Ultralytics YOLO11 Analytics?

To create a line graph using Ultralytics YOLO11 Analytics, follow these steps:

  1. Load a YOLO11 model and open your video file.
  2. Initialisiere die Analytics Klasse, wobei der Typ auf "Linie" eingestellt ist.
  3. Iteriere durch die Videobilder und aktualisiere das Liniendiagramm mit relevanten Daten, z. B. der Anzahl der Objekte pro Bild.
  4. Speichere das Ausgabevideo, das das Liniendiagramm anzeigt.

Beispiel:

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="line",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Für weitere Details zur Konfiguration der Analytics Klasse, besuche die Analytics using Ultralytics YOLO11 📊 Abschnitt.

What are the benefits of using Ultralytics YOLO11 for creating bar plots?

Using Ultralytics YOLO11 for creating bar plots offers several benefits:

  1. Real-time Data Visualization: Seamlessly integrate object detection results into bar plots for dynamic updates.
  2. Benutzerfreundlichkeit: Einfache API und Funktionen machen es leicht, Daten zu implementieren und zu visualisieren.
  3. Anpassungen: Passe Titel, Beschriftungen, Farben und mehr an deine spezifischen Anforderungen an.
  4. Effizienz: Verarbeite große Datenmengen effizient und aktualisiere die Diagramme in Echtzeit während der Videoverarbeitung.

Verwende das folgende Beispiel, um ein Balkendiagramm zu erstellen:

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="bar",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Um mehr zu erfahren, besuche den Abschnitt Bar Plot im Leitfaden.

Why should I use Ultralytics YOLO11 for creating pie charts in my data visualization projects?

Ultralytics YOLO11 is an excellent choice for creating pie charts because:

  1. Integration mit der Objektdetektion: Integriere die Ergebnisse der Objekterkennung direkt in Kreisdiagramme, um sofortige Einblicke zu erhalten.
  2. Benutzerfreundliches API: Einfach einzurichten und mit minimalem Code zu nutzen.
  3. Anpassbar: Verschiedene Anpassungsmöglichkeiten für Farben, Etiketten und mehr.
  4. Aktualisierungen in Echtzeit: Verarbeite und visualisiere Daten in Echtzeit, was ideal für Videoanalyseprojekte ist.

Hier ist ein kurzes Beispiel:

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="pie",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Weitere Informationen findest du im Abschnitt Kreisdiagramm im Leitfaden.

Can Ultralytics YOLO11 be used to track objects and dynamically update visualizations?

Yes, Ultralytics YOLO11 can be used to track objects and dynamically update visualizations. It supports tracking multiple objects in real-time and can update various visualizations like line graphs, bar plots, and pie charts based on the tracked objects' data.

Beispiel für das Verfolgen und Aktualisieren eines Liniendiagramms:

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter(
    "ultralytics_analytics.avi",
    cv2.VideoWriter_fourcc(*"MJPG"),
    fps,
    (1920, 1080),  # This is fixed
)

analytics = solutions.Analytics(
    analytics_type="line",
    show=True,
)

frame_count = 0
while cap.isOpened():
    success, im0 = cap.read()
    if success:
        frame_count += 1
        im0 = analytics.process_data(im0, frame_count)  # update analytics graph every frame
        out.write(im0)  # write the video file
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Um mehr über die komplette Funktionalität zu erfahren, lies den Abschnitt Tracking.

What makes Ultralytics YOLO11 different from other object detection solutions like OpenCV and TensorFlow?

Ultralytics YOLO11 stands out from other object detection solutions like OpenCV and TensorFlow for multiple reasons:

  1. State-of-the-art Accuracy: YOLO11 provides superior accuracy in object detection, segmentation, and classification tasks.
  2. Benutzerfreundlichkeit: Die benutzerfreundliche API ermöglicht eine schnelle Implementierung und Integration ohne umfangreichen Programmieraufwand.
  3. Leistung in Echtzeit: Optimiert für Hochgeschwindigkeitsinferenzen, geeignet für Echtzeitanwendungen.
  4. Vielfältige Anwendungen: Unterstützt verschiedene Aufgaben wie die Verfolgung von mehreren Objekten, benutzerdefiniertes Modelltraining und den Export in verschiedene Formate wie ONNX, TensorRT, und CoreML.
  5. Umfassende Dokumentation: Umfassende Dokumentation und Blog-Ressourcen führen die Nutzer durch jeden Schritt.

Ausführlichere Vergleiche und Anwendungsfälle findest du in unserem Ultralytics Blog.

📅 Created 5 months ago ✏️ Updated 10 days ago

Kommentare