opencv - 阈值化后温度为黑色
问题描述
我想根据密度显示温度。
以下是我使用的功能,
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
add_heat
函数将遍历跟踪器并仅在那些特定区域上调整热图以进行阈值处理- 如果低于某个阈值,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 包含所有被跟踪的坐标。但是,当我尝试显示最终结果时,它仍然是黑色的。我可以知道我错过了什么吗?
解决方案
似乎您的问题出在此处:
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 数组的信息。当我看到这个问题的来源时,我能够说出正在发生的事情。
推荐阅读
- ruby-on-rails - Link_to 更新表中的属性
- matlab - 初始目标函数评估失败。LSQNONLIN 无法继续
- python - 用于 RethinkDB 匹配(正则表达式)查询的 Python unicode 转义
- python - Python 3.7:如何避免这种递归方法的堆栈溢出?
- android - 方法 doWork() 不使用 WorkManager 调用
- uml - UML 序列图:系统返回一个列表
- graph - 将 Grafana 与 BigQuery 数据源结合使用
- vue.js - 如何测试包含 v-text-field Vuetify 子组件的 vue 组件?
- jquery - 在 JQuery 自动完成填充输入字段后调用新函数
- python - 如何设置单个像素的颜色