首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >OpenCV如何从噪声和误报中清除轮廓

OpenCV如何从噪声和误报中清除轮廓
EN

Stack Overflow用户
提问于 2019-03-08 19:44:13
回答 1查看 4.4K关注 0票数 1

我在Python中使用standart函数cv2.findContours.找到了图像轮廓。

但是正如你所看到的,中间有一个点,我不能在不打破轮廓线的情况下过滤它。

我如何删除这样的假阳性集群?轮廓之外的那些并不重要。

代码语言:javascript
复制
    gray = cv2.cvtColor(self.img, cv2.COLOR_RGB2GRAY)

    _, mask = cv2.threshold(gray, thresh=152, maxval=162, type=cv2.THRESH_BINARY)

    self.mask = cv2.bitwise_and(gray, mask)
    self.contours, hierarchy = cv2.findContours(self.mask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-20 04:17:46

避免误报的一个好方法是考虑具有最大面积的轮廓:

代码语言:javascript
复制
import imutils #to use sorting functionality 
#To install imutils run: pip install imutils for python 2.x
#Run: pip3 install imutils for python 3.x

cnts = imutils.grab_contours(cnts) #where cnts is the variable in which contours are stored, replace it with your variable name
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10] #sorts contours according to their area from largest to smallest.

largestCont = cnts[0] #store the largest contour

这将删除小的点,同时只给出最大的轮廓

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55062579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档