0

尊敬的所有人,

我在附加图像中使用分水岭算法,现在我想找到封闭边界图像的大小(图像中的不规则物体)。

附上图片: 在此处输入图像描述

4

1 回答 1

2

更新:

在 OpenCV 3.4 中,cv2.findContours返回image, contours, hierarchy

cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy

在此处输入图像描述

在 OpenCV 4.0 中,cv2.findContours返回contours, hierarchy

cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy

在此处输入图像描述

因此,要在脱粒二值图像中找到轮廓并计算区域,请使用:

cnts= cv.findContours(threshed, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)[-2]
for cnt in cnts:
    area = cv2.contourArea(cnt)
    print(area)
于 2017-12-21T07:23:52.513 回答