Temperature is black after thresholding

谁说胖子不能爱 提交于 2019-12-08 11:52:22

问题


I want to show the temperature based on the density.

Following are the function that Im using,

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 function will loop through the trackers and will tweak the heatmap only on those specific areas for the thresholding
  2. apply_threshold will convert all pixels to zero if it is below certain threshold.

Im calling it as follows,

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 contains all the tracked coordinates. however when i try to show the final result, it is still black. May i know what am i missing?


回答1:


Seems like your problem lies in here:

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

Assuming you want to use the heatmap with something like skimage, you should probably do it like this:

heatmap[top_row:bottom_row, leftmost_column:rightmost_column]

which in your code will look like this:

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

You may want to read a little more about numpy arrays. I was able to tell what is happening as I saw where this question originated.



来源:https://stackoverflow.com/questions/51341091/temperature-is-black-after-thresholding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!