问题描述
我需要根据对象的位置生成对象的热图例如:在视频帧中检测到的绿球.如果它长时间停留在某个位置,则该位置应为红色,并且球在短时间内通过的帧中的位置必须为蓝色,这样我就需要生成一个热图.预先感谢
I need to generate the heat map of a object based on its position example: the detected green ball in a video frame . If it stays in a position for a long duration then that place should be red and the positions in the frame where the ball has passes for a short duration must be in blue in that way i need to generate a heat map . Thanks in advance
推荐答案
在这里您可以做的是
1)首先定义一个热图作为图像的大小
1) First define a heatmap as the size of the image
heatmap = np.zeros_like(img[:,:,0]).astype(np.float)
2)由于您已经具有检测到的对象及其位置,因此,在热图中,将1添加到对象边界框中的所有像素.
2) Since you already have the detected object and its position, in the heatmap, add 1 to all pixels in the bounding box of the object.
heatmap[box[0][1]:box[1][1], box[0][0]:box[1][0]] += 1
3)然后,您可以通过将热图中阈值以下的所有像素设置为0来应用阈值.您可以将阈值选择为1,以便边界框内的区域保留在热图中 >
3) you can than apply thresholding by setting all pixels which are below a threshold value in the heatmap to be 0. You can choose the threshold value to be 1 so that the region inside your bounding box remains in the heatmap
heatmap[heatmap <= threshold] = 0
这篇关于我如何使用opencv python根据其位置生成被检测对象的热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!