从热图数据生成边界框

Generating bounding boxes from heatmap data

我有我正在进行的车辆检测项目的热图数据,但我不知道下一步该去哪里。我想在图像的 'hottest' 部分周围绘制一个通用边界框。我的第一个想法是在所有重叠的部分上画一个框,但有些东西告诉我有更准确的方法来做到这一点。任何帮助,将不胜感激!不幸的是,我的声誉阻止我发布图片。以下是我创建热图的方式:

# Positive prediction window coordinate structure: ((x1, y1), (x2, y2))
def create_heatmap(bounding_boxes_list):
     # Create a black image the same size as the input data
     heatmap = np.zeros(shape=(375, 1242))
     # Traverse the list of bounding box locations in test image
     for bounding_box in bounding_boxes_list:
          heatmap[bounding_box[0][1]:bounding_box[1][1], bounding_box[0][ 0]:bounding_box[1][0]] += 1

return heatmap

Here's the link to the heatmap I have

Here's a general idea of what I had in mind

Otsu对二值图像的阈值和轮廓检测应该可以做到。使用这个没有轴线的截图:

import cv2

# Grayscale then Otsu's threshold
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]

# Find contours
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    x,y,w,h = cv2.boundingRect(c)
    cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)

cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()