我需要在分割掩模中绘制热图

问题描述 投票:0回答:1
from ultralytics import YOLO, Heatmap
import cv2

model = YOLO("/home/safepro/Documents/croud_map/final-poc/Crowd-heatmap/crowd-seg.pt")  # Load your model
video_path = "/home/safepro/Documents/croud_map/final-poc/Crowd-heatmap/eagle-view.mp4"
cap = cv2.VideoCapture(video_path)

# Ensure video opens correctly
assert cap.isOpened(), "Failed to open video."

# Initialize Heatmap without additional arguments
heatmap_obj = Heatmap()

while True:
    ret, frame = cap.read()
    if not ret:
        break  # Exit loop if no more frames
    
    # Generate predictions and apply heatmaps
    results = model.predict(frame)
    frame_with_heatmap = heatmap_obj.apply(frame, results)
    
    # Display the frame with applied heatmap
    cv2.imshow("Heatmap Visual", frame_with_heatmap)
    if cv2.waitKey(10) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
from ultralytics import YOLO, Heatmap

ImportError:无法从“ultralytics”导入名称“Heatmap”(/home/safepro/.local/lib/python3.10/site-packages/ultralytics/init.py) 我尝试更新 ultralytics,但无法解决这个问题,这个脚本是由 ultralytics 的人之一提供的

我尝试了很多方法来绘制分割的热图,但我无法解决并接受了 Ultralytics 人的帮助,即使他们也无法重新处理如果有人在实例分割上绘制了热图,请分享我

python computer-vision video-processing image-segmentation
1个回答
0
投票

看来“Heatmap”不在ultralytics中。 从文档来看,正确的调用应该是:

from ultralytics.solutions import heatmap

参见:超水解物

© www.soinside.com 2019 - 2024. All rights reserved.