尊敬的所有人,
我在附加图像中使用分水岭算法,现在我想找到封闭边界图像的大小(图像中的不规则物体)。
更新:
在 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)