首页 > 解决方案 > 阈值化后温度为黑色

问题描述

我想根据密度显示温度。

以下是我使用的功能,

def add_heat(heatmap, bbox_list):
    for i in range(len(bbox_list)):
        rect = trackers[i].get_position()

        heatmap[int(rect.left()):int(rect.top()), int(rect.right()):int(rect.bottom())] += 1
    return heatmap

def apply_threshold(heatmap, threshold):
    # Zero out pixels below the threshold
    heatmap[heatmap <= threshold] = 0
    # Return thresholded map

    cv2.imwrite("heatmap.png",heatmap)
    return heatmap
  1. add_heat函数将遍历跟踪器并仅在那些特定区域上调整热图以进行阈值处理
  2. 如果低于某个阈值,apply_threshold 会将所有像素转换为零。

我这样称呼它,

heat = np.zeros_like(frame[:, :, 0]).astype(np.float)
heat = add_heat(heat,trackers)
heat = apply_threshold(heat, 80)
heatmap = np.clip(heat, 0, 255)

trackers 包含所有被跟踪的坐标。但是,当我尝试显示最终结果时,它仍然是黑色的。我可以知道我错过了什么吗?

标签: opencvheatmapdetectiondlibimage-thresholding

解决方案


似乎您的问题出在此处:

heatmap[int(rect.left()):int(rect.top()), int(rect.right()):int(rect.bottom())] += 1
return heatmap

假设您想将热图与 skimage 之类的东西一起使用,您可能应该这样做:

heatmap[top_row:bottom_row, leftmost_column:rightmost_column]

在您的代码中将如下所示:

heatmap[int(rect.bottom()):int(rect.top()), int(rect.left()):int(rect.right())] += 1
return heatmap

您可能想了解更多关于 numpy 数组的信息。当我看到这个问题的来源时,我能够说出正在发生的事情。


推荐阅读