【问题标题】:size of the enclosed region in opencv python [closed]opencv python中封闭区域的大小[关闭]
【发布时间】:2017-12-21 07:23:02
【问题描述】:

尊重所有人,

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

附上图片:

【问题讨论】:

  • 您对 Silencer 代码的评论是否尝试过并给出错误?如果是这样,请在您的问题中发布。另请参阅我在 Silencer 的其他评论。由于缺乏努力,您的问题现在注定要被否决和关闭..
  • 我使用的是opencv3.5
  • 这不是我的问题的答案.. 除非 cv3.5 给出以下答案的错误。然后发布您的跟踪步骤和错误代码。显示您的以下结果不是问题(评论 Silencer 在您的问题中的回答)。去编辑。
  • @saeediqbal 请帮帮我,可以吗? stackoverflow.com/questions/60978380/…

标签: python python-3.x opencv opencv-contour watershed


【解决方案1】:

更新:

在 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)

【讨论】:

  • cnts = cv.findContours(thresh.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE) print("cnts is ",cnts) 如上:输出如下:cnts is (array( [[255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], ..., [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255]], dtype=uint8) , [array([[[ 0, 0]], [[ 0, 131]], [[199, 131]], [[199, 0]]], dtype=int32)], array([[[- 1, -1, -1, -1]]], dtype=int32))
  • @saeediqbal:请在评论中参考您自己的答案。现在它很难阅读,我不知道您的意思。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-09
  • 2018-02-13
  • 1970-01-01
  • 2020-08-08
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
相关资源
最近更新 更多