Generating Bounding Boxes From Heatmap Data
I have the heatmap data for a vehicle detection project I'm working on but I'm at a loss for where to go next. I want to draw a generalized bounding box around the 'hottest' portio
Solution 1:
Otsu's threshold and contour detection on the binary image should do it. Using this screenshotted image without the axis lines:
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()
Post a Comment for "Generating Bounding Boxes From Heatmap Data"