从 Yolo 检测器获取边界框位置后如何在不影响 FPS 的情况下生成热图

问题描述 投票:0回答:0

我正在尝试设计一个生成购物中心内步行交通热图的应用程序。 我已经为此编写了这段代码,

Looping through all the frames in loop Frame-by-Frame
bounding_box = []
        for obj in to_track:
            bounding_box.append((obj.bbox.x0, obj.bbox.y0, obj.bbox.x1, obj.bbox.y1)) 
        
        all_bounding_boxes.extend(bounding_box)

        # Create a 2D density heatmap for the detected persons
        density = np.zeros((img.shape[0], img.shape[1]), dtype=np.float32)
        for x0, y0, x1, y1 in all_bounding_boxes:
            x, y, w, h = x0, y0, x1-x0, y1-y0
            center = (int(x + w/2), int(y + h/2))
            size = (int(w/2 * 0.04), int(h/2 * 0.04))
            angle = 0
            startAngle = 0
            endAngle = 360
            cv2.ellipse(density, center, size, angle, startAngle, endAngle, (1, 1), -1)

        density = cv2.GaussianBlur(density, (21, 21), 0)
        density = cv2.normalize(density, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
        heatmap = cv2.applyColorMap(density, cv2.COLORMAP_TURBO)
        img = cv2.addWeighted(img, 0.5, heatmap, 0.5, 0)
        >>>> Then render the image using cv2

上面的代码运行良好,可以绘制和跟踪所有热图,但在推进帧时会降低帧速率,因为没有。边界框的数量逐帧增加,热图绘制也在增加。所以,我想知道我该怎么做才能优化掉帧??

如果有人对此有任何想法,请告诉我。 提前致谢...

我期待随着帧的进展,帧丢失可以最小化。

opencv optimization heatmap frame-rate yolov5
© www.soinside.com 2019 - 2024. All rights reserved.