检测照片中纸张角落的算法 [英] Algorithm to detect corners of paper sheet in photo

查看:133
本文介绍了检测照片中纸张角落的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检测照片中发票/收据/纸张角落的最佳方法是什么?这是在OCR之前用于后续透视校正。

What is the best way to detect the corners of an invoice/receipt/sheet-of-paper in a photo? This is to be used for subsequent perspective correction, before OCR.

RGB >灰色>带阈值的Canny边缘检测>扩张(1)>移除小物体(6)>清除边界物体>根据凸面区域挑选大型博客。 > [角点检测 - 未实现]

RGB > Gray > Canny Edge Detection with thresholding > Dilate(1) > Remove small objects(6) > clear boarder objects > pick larges blog based on Convex Area. > [corner detection - Not implemented]

我不禁认为必须有更强大的智能/统计方法来处理这种类型的分段。我没有很多训练样例,但我可能会得到100张图像。

I can't help but think there must be a more robust 'intelligent'/statistical approach to handle this type of segmentation. I don't have a lot of training examples, but I could probably get 100 images together.

我正在使用matlab进行原型设计,并计划在OpenCV和Tesserect-OCR中实现该系统。这是我需要为此特定应用程序解决的许多图像处理问题中的第一个。因此,我希望推出自己的解决方案并重新熟悉图像处理算法。

I'm using matlab to prototype, and planning to implement the system in OpenCV and Tesserect-OCR. This is the first of a number of image processing problems I need to solve for this specific application. So I'm looking to roll my own solution and re-familiarize myself with image processing algorithms.

以下是我希望算法处理的一些示例图像:如果您想接受挑战,则大图像位于http://madteckhead.com/tmp

Here are some sample image that I'd like the algorithm to handle: If you'd like to take up the challenge the large images are at http://madteckhead.com/tmp

案例1 http://madteckhead.com/tmp/IMG_0773_sml.jpg
案例2 http://madteckhead.com/tmp/IMG_0774_sml.jpg
案例3 http:/ /madteckhead.com/tmp/IMG_0775_sml.jpg
案例4 http://madteckhead.com/tmp/ IMG_0776_sml.jpg

案例1 - canny http://madteckhead.com/tmp/IMG_0773_canny.jpg
案例1 - post canny http://madteckhead.com/tmp/IMG_0773_p ostcanny.jpg
案例1 - 最大的博客http://madteckhead.com/tmp/IMG_0773_blob.jpg

案例2 - canny http://madteckhead.com/tmp/IMG_0774_canny.jpg
案例2 - post canny http://madteckhead.com/tmp/IMG_0774_postcanny.jpg
案例2 - 最大的博客http://madteckhead.com/tmp/IMG_0774_blob.jpg

提前感谢所有伟大的创意!我喜欢这样!

Thanks in advance for all the great ideas! I love SO!

问:什么算法会聚集hough线来查找角落?
根据答案的建议我能够使用Hough变换,选择线并过滤它们。我目前的做法相当粗糙。我已经假设发票总是小于15度,与图像不对齐。如果是这种情况,我最终得到合理的线条结果(见下文)。但我不完全确定一个合适的算法来聚集线(或投票)来推断角落。霍夫线不连续。并且在嘈杂的图像中,可以存在平行线,因此需要与线原点度量的某种形式或距离。有什么想法?

Q: What algorithm would cluster the hough lines to find corners? Following advice from answers I was able to use the Hough Transform, pick lines, and filter them. My current approach is rather crude. I've made the assumption the invoice will always be less than 15deg out of alignment with the image. I end up with reasonable results for lines if this is the case (see below). But am not entirely sure of a suitable algorithm to cluster the lines (or vote) to extrapolate for the corners. The Hough lines are not continuous. And in the noisy images, there can be parallel lines so some form or distance from line origin metrics are required. Any ideas?

案例1 http://madteckhead.com/tmp/ IMG_0773_hough.jpg
案例2 http://madteckhead.com/tmp/IMG_0774_hough.jpg
案例3 http://madteckhead.com/tmp/IMG_0775_hough.jpg
案例4 http://madteckhead.com/tmp/IMG_0776_hough.jpg

推荐答案

我是马丁的朋友,今年早些时候正在研究这个问题。这是我的第一个编码项目,有点匆忙结束,所以代码需要一些错误...解码...
我会从我看到你做的一些提示已经,然后在明天休息时对我的代码进行排序。

I'm Martin's friend who was working on this earlier this year. This was my first ever coding project, and kinda ended in a bit of a rush, so the code needs some errr...decoding... I'll give a few tips from what I've seen you doing already, and then sort my code on my day off tomorrow.

第一个提示, OpenCV python 太棒了,请尽快转移到它们。 :D

First tip, OpenCV and python are awesome, move to them as soon as possible. :D

不是删除小物体和/或噪音,而是降低精确限制,使其接受更多边缘,然后找到最大的闭合轮廓(在OpenCV中使用 findcontour()有一些简单的参数,我想我用 CV_RETR_LIST )。当它在一张白纸上时,它仍然可能会挣扎,但肯定会提供最好的结果。

Instead of removing small objects and or noise, lower the canny restraints, so it accepts more edges, and then find the largest closed contour (in OpenCV use findcontour() with some simple parameters, I think I used CV_RETR_LIST). might still struggle when it's on a white piece of paper, but was definitely providing best results.

对于 Houghline2()转换,请尝试使用 CV_HOUGH_STANDARD 而不是 CV_HOUGH_PROBABILISTIC ,它会给出 rho theta 值,定义极坐标中的直线,然后你可以在一定的容差范围内对线进行分组。

For the Houghline2() Transform, try with the CV_HOUGH_STANDARD as opposed to the CV_HOUGH_PROBABILISTIC, it'll give rho and theta values, defining the line in polar coordinates, and then you can group the lines within a certain tolerance to those.

我的分组作为一个查找表,对于从霍夫变换输出的每一行,它将给出一个rho和theta对。如果这些值在表格中的一对值的5%范围内,则丢弃它们,如果它们超出5%,则会在表格中添加新条目。

My grouping worked as a look up table, for each line outputted from the hough transform it would give a rho and theta pair. If these values were within, say 5% of a pair of values in the table, they were discarded, if they were outside that 5%, a new entry was added to the table.

然后你可以更容易地分析平行线或线之间的距离。

You can then do analysis of parallel lines or distance between lines much more easily.

希望这有帮助。

这篇关于检测照片中纸张角落的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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