def extractRoi(image, winSize, stepSize):
# hue boundaries
colors = [
(15, 30) # orange-yellow
]
mask, weight_map, mask_scale = roiMask(image, colors)
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
yield weight_map, mask_scale
for resized in pyramid(image, winSize):
scale = image.shape[0] / resized.shape[0]
for x, y, w, h in boundingRects(mask_scale, contours):
x /= scale
y /= scale
w /= scale
h /= scale
center = (min(x + w / 2, resized.shape[1]), min(y + h / 2, resized.shape[0]))
if w > winSize[0] or h > winSize[1]:
for x, y, window in sliding_window(resized, (int(x), int(y), int(w), int(h)), stepSize, winSize):
yield ((x, y, winSize[0], winSize[1]), scale, window)
else:
x = max(0, int(center[0] - winSize[0] / 2))
y = max(0, int(center[1] - winSize[1] / 2))
window = resized[y:y + winSize[1], x:x + winSize[0]]
yield ((x, y, winSize[0], winSize[1]), scale, window)
评论列表
文章目录