代码参考chatgpt生成
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter
import random
# 假设我们有一些关键点位置
keypoints = [(50, 50), (70, 80), (90, 30)]
# 创建一个空白的热图
heatmap = np.zeros((100, 100))
# 将关键点位置添加到热图中
for point in keypoints:
y, x = point
heatmap[y, x] = random.random()
# heatmap[y, x] = 1 # 假设置信度为1
# 使用高斯滤波平滑热图
heatmap_smooth = gaussian_filter(heatmap, sigma=1)
# 可视化热图
plt.imshow(heatmap_smooth, cmap='hot', interpolation='nearest')
plt.show()
print(heatmap_smooth.shape)
效果展示:heatmap[y, x] = random.random()决定每个点概率
heatmap_smooth = gaussian_filter(heatmap, sigma=1)决定整体热力大小
修改 sigma=3,效果如下: