Temperature is black after thresholding

2019-06-12 23:34发布

问题:

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.