我试图找到一种在scikit-image中检测到的轮廓上绘制边界框的方法,但我找不到任何方法,因为scikit-image方法中的find_contours返回坐标的二维数组检测到的轮廓的点。
答案 0 :(得分:4)
您可以使用这段代码在图像上绘制边界:
# Loop through contours and draw the bounds in red
contours = skimage.measure.find_contours(img, level)
for contour in contours:
img = drawShape(img, contour, [255, 0, 0])
def drawShape(img, coordinates, color)
# In order to draw our line in red
img = skimage.color.gray2rgb(img)
# Make sure the coordinates are expressed as integers
coordinates = coordinates.astype(int)
img[coordinates[:, 0], coordinates[:, 1]] = color
return img