Zum Inhalt springen

Advanced Data Visualization: Heatmaps using Ultralytics YOLO11 🚀

EinfĂŒhrung in Heatmaps

A heatmap generated with Ultralytics YOLO11 transforms complex data into a vibrant, color-coded matrix. This visual tool employs a spectrum of colors to represent varying data values, where warmer hues indicate higher intensities and cooler tones signify lower values. Heatmaps excel in visualizing intricate data patterns, correlations, and anomalies, offering an accessible and engaging approach to data interpretation across diverse domains.



Pass auf: Heatmaps using Ultralytics YOLO11

Warum sollten wir Heatmaps fĂŒr die Datenanalyse wĂ€hlen?

  • Intuitive Visualisierung der Datenverteilung: Heatmaps vereinfachen das VerstĂ€ndnis der Datenkonzentration und -verteilung und wandeln komplexe DatensĂ€tze in leicht verstĂ€ndliche visuelle Formate um.
  • Effiziente Erkennung von Mustern: Durch die Visualisierung der Daten im Heatmap-Format ist es einfacher, Trends, Cluster und Ausreißer zu erkennen, was schnellere Analysen und Erkenntnisse ermöglicht.
  • Verbesserte rĂ€umliche Analyse und Entscheidungsfindung: Heatmaps dienen der Veranschaulichung rĂ€umlicher ZusammenhĂ€nge und helfen bei Entscheidungsprozessen in Bereichen wie Business Intelligence, Umweltstudien und Stadtplanung.

Anwendungen in der realen Welt

Transport Einzelhandel
Ultralytics YOLO11 Transportation Heatmap Ultralytics YOLO11 Retail Heatmap
Ultralytics YOLO11 Transportation Heatmap Ultralytics YOLO11 Retail Heatmap

Heatmaps using Ultralytics YOLO11 Example

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))

# Video writer
video_writer = cv2.VideoWriter("heatmap_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Init heatmap
heatmap = solutions.Heatmap(
    show=True,
    model="yolo11n.pt",
    colormap=cv2.COLORMAP_PARULA,
)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = heatmap.generate_heatmap(im0)
    video_writer.write(im0)

cap.release()
video_writer.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))

# Video writer
video_writer = cv2.VideoWriter("heatmap_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# line for object counting
line_points = [(20, 400), (1080, 404)]

# Init heatmap
heatmap = solutions.Heatmap(
    show=True,
    model="yolo11n.pt",
    colormap=cv2.COLORMAP_PARULA,
    region=line_points,
)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = heatmap.generate_heatmap(im0)
    video_writer.write(im0)

cap.release()
video_writer.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))

# Video writer
video_writer = cv2.VideoWriter("heatmap_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Define polygon points
region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360), (20, 400)]

# Init heatmap
heatmap = solutions.Heatmap(
    show=True,
    model="yolo11n.pt",
    colormap=cv2.COLORMAP_PARULA,
    region=region_points,
)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = heatmap.generate_heatmap(im0)
    video_writer.write(im0)

cap.release()
video_writer.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))

# Video writer
video_writer = cv2.VideoWriter("heatmap_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Define region points
region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360)]

# Init heatmap
heatmap = solutions.Heatmap(
    show=True,
    model="yolo11n.pt",
    colormap=cv2.COLORMAP_PARULA,
    region=region_points,
)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = heatmap.generate_heatmap(im0)
    video_writer.write(im0)

cap.release()
video_writer.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))

# Video writer
video_writer = cv2.VideoWriter("heatmap_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Init heatmap
heatmap = solutions.Heatmap(
    show=True,
    model="yolo11n.pt",
    classes=[0, 2],
)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    im0 = heatmap.generate_heatmap(im0)
    video_writer.write(im0)

cap.release()
video_writer.release()
cv2.destroyAllWindows()

Argumente Heatmap()

Name Typ Standard Beschreibung
colormap int cv2.COLORMAP_JET Farbkarte, die fĂŒr die Heatmap verwendet werden soll.
show bool False Ob das Bild mit dem Heatmap-Overlay angezeigt werden soll.
show_in bool True Ob die Anzahl der Objekte angezeigt werden soll, die die Region betreten.
show_out bool True Ob die Anzahl der Objekte, die die Region verlassen, angezeigt werden soll.
region list None Punkte, die den ZĂ€hlbereich definieren (entweder eine Linie oder ein Polygon).
line_width int 2 Dicke der beim Zeichnen verwendeten Linien.

Argumente model.track

Argument Typ Standard Beschreibung
source str None Specifies the source directory for images or videos. Supports file paths and URLs.
persist bool False Enables persistent tracking of objects between frames, maintaining IDs across video sequences.
tracker str botsort.yaml Specifies the tracking algorithm to use, e.g., bytetrack.yaml oder botsort.yaml.
conf float 0.3 Sets the confidence threshold for detections; lower values allow more objects to be tracked but may include false positives.
iou float 0.5 Sets the Intersection over Union (IoU) threshold for filtering overlapping detections.
classes list None Filters results by class index. For example, classes=[0, 2, 3] only tracks the specified classes.
verbose bool True Controls the display of tracking results, providing a visual output of tracked objects.

Heatmap COLORMAPs

Colormap Name Beschreibung
cv::COLORMAP_AUTUMN Farbkarte Herbst
cv::COLORMAP_BONE Knochen-Farbkarte
cv::COLORMAP_JET Jet-Farbkarte
cv::COLORMAP_WINTER Farbkarte Winter
cv::COLORMAP_RAINBOW Regenbogen-Farbkarte
cv::COLORMAP_OCEAN Farbkarte Ozean
cv::COLORMAP_SUMMER Sommer Farbkarte
cv::COLORMAP_SPRING Farbkarte FrĂŒhling
cv::COLORMAP_COOL Coole Farbkarte
cv::COLORMAP_HSV HSV (Farbton, SĂ€ttigung, Wert) Farbkarte
cv::COLORMAP_PINK Rosa Farbkarte
cv::COLORMAP_HOT Heiße Farbkarte
cv::COLORMAP_PARULA Parula Farbkarte
cv::COLORMAP_MAGMA Magma Farbkarte
cv::COLORMAP_INFERNO Inferno Farbkarte
cv::COLORMAP_PLASMA Plasma-Farbkarte
cv::COLORMAP_VIRIDIS Viridis Farbkarte
cv::COLORMAP_CIVIDIS Cividis Farbkarte
cv::COLORMAP_TWILIGHT Farbkarte der DĂ€mmerung
cv::COLORMAP_TWILIGHT_SHIFTED Verschobene Farbkarte der DĂ€mmerung
cv::COLORMAP_TURBO Turbo Farbkarte
cv::COLORMAP_DEEPGREEN Deep Green Farbkarte

Diese Farbkarten werden hÀufig zur Visualisierung von Daten mit verschiedenen Farbdarstellungen verwendet.

FAQ

How does Ultralytics YOLO11 generate heatmaps and what are their benefits?

Ultralytics YOLO11 generates heatmaps by transforming complex data into a color-coded matrix where different hues represent data intensities. Heatmaps make it easier to visualize patterns, correlations, and anomalies in the data. Warmer hues indicate higher values, while cooler tones represent lower values. The primary benefits include intuitive visualization of data distribution, efficient pattern detection, and enhanced spatial analysis for decision-making. For more details and configuration options, refer to the Heatmap Configuration section.

Can I use Ultralytics YOLO11 to perform object tracking and generate a heatmap simultaneously?

Yes, Ultralytics YOLO11 supports object tracking and heatmap generation concurrently. This can be achieved through its Heatmap solution integrated with object tracking models. To do so, you need to initialize the heatmap object and use YOLO11's tracking capabilities. Here's a simple example:

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("path/to/video/file.mp4")
heatmap = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, show=True, model="yolo11n.pt")

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        break
    im0 = heatmap.generate_heatmap(im0)
    cv2.imshow("Heatmap", im0)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

Weitere Hinweise findest du auf der Seite Tracking-Modus.

What makes Ultralytics YOLO11 heatmaps different from other data visualization tools like those from OpenCV or Matplotlib?

Ultralytics YOLO11 heatmaps are specifically designed for integration with its object detection and tracking models, providing an end-to-end solution for real-time data analysis. Unlike generic visualization tools like OpenCV or Matplotlib, YOLO11 heatmaps are optimized for performance and automated processing, supporting features like persistent tracking, decay factor adjustment, and real-time video overlay. For more information on YOLO11's unique features, visit the Ultralytics YOLO11 Introduction.

How can I visualize only specific object classes in heatmaps using Ultralytics YOLO11?

Du kannst bestimmte Objektklassen visualisieren, indem du die gewĂŒnschten Klassen in der track() Methode des YOLO Modells. Wenn du zum Beispiel nur Autos und Personen visualisieren möchtest (unter der Annahme, dass ihre Klassenindizes 0 und 2 sind), kannst du die classes Parameter entsprechend anpassen.

import cv2

from ultralytics import solutions

cap = cv2.VideoCapture("path/to/video/file.mp4")
heatmap = solutions.Heatmap(show=True, model="yolo11n.pt", classes=[0, 2])

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        break
    im0 = heatmap.generate_heatmap(im0)
    cv2.imshow("Heatmap", im0)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

Why should businesses choose Ultralytics YOLO11 for heatmap generation in data analysis?

Ultralytics YOLO11 offers seamless integration of advanced object detection and real-time heatmap generation, making it an ideal choice for businesses looking to visualize data more effectively. The key advantages include intuitive data distribution visualization, efficient pattern detection, and enhanced spatial analysis for better decision-making. Additionally, YOLO11's cutting-edge features such as persistent tracking, customizable colormaps, and support for various export formats make it superior to other tools like TensorFlow and OpenCV for comprehensive data analysis. Learn more about business applications at Ultralytics Plans.


📅 Created 10 months ago ✏ Updated 5 days ago

Kommentare