在opencv上检测非闭合轮廓 [英] Detect non-closed contour on opencv

查看:3484
本文介绍了在opencv上检测非闭合轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做自动卡检测的计算机视觉项目。
我需要从背景中分离卡。我已经应用了canny边缘检测,使用自动参数设置从



解释了如何检查轮廓是否关闭


另一个相当简单的解决方案:




  • 不要对图像应用Canny。对otsu阈值图像执行findContours。在findContours



之前,可以在阈值图像上使用形态学打开和关闭来消除噪点。FindContours不需要边缘图像,通常会执行与阈值图像。我不知道你的源图像,所以我不能说这将是多好的工作,但你一定会避免孔形状的问题。



如果源图片不允许这样,那么以下可能有帮助:




  • 使用分水岭将卡与背景分离。使用高阈值获得肯定是前景的一些种子像素和低阈值以获得绝对是背景的像素,然后使用 cv:watershed()生长这两个种子。



如果该图片的背景颜色与卡的颜色相同,则前两种方法可能无法正常工作。在这种情况下,您最好的赌注可能是Micka建议的解决方案:




  • 使用 hough transform 找到图片中最突出的4条线。用这四行形成一个矩形。


I'm doing computer vision project for automatic card detection. I need to separate the card from the background. I have applied the canny edge detection, using automatic parameter settings from this

Automatic calculation of low and high thresholds for the Canny operation in opencv

The result is excellent. However, sometimes the canny is not perfect like this

I have applied cvFindContour to detect the box. However, due to "hole" on the upper side, opencv failed to detect the contour.

How do I tune the cvFindContour to detect the contour or should I tune the canny edge instead?

解决方案

There are multiple possible solutions.

The simplest one may be:

  • if FindContours does not find a closed contour, repeat the canny filter with a slightly decreased low_threshold, until you find a closed contour. If the closed contour has roughly the right size and shape, it is a card. The answer linked by Haris explains how to check whether a contour is closed

Another rather simple solution:

  • Don't apply Canny to the image at all. Execute findContours on the otsu thresholded image. Optionally use morphological opening and closing on the thresholded image to remove noise before findContours

FindContours does not need an edge image, it is usually executed with a thresholded image. I don't know your source image, so I cannot say how good this would work, but you would definitely avoid the problem of holes in the shape.

If the source image does not allow this, then the following may help:

  • use watershed to separate the card from the background. Use a high threshold to get some seed pixels that are definitely foreground and a low threshold to get pixels that are definitely background, then grow those two seeds using cv:watershed().

If the background in that image is the same color as the card, then the previous two methods may not work so well. In that case, your best bet may be the solution suggested by Micka:

  • use hough transform to find the 4 most prominent lines in the image. Form a rectangle with these 4 lines.

这篇关于在opencv上检测非闭合轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆