如何在Java中检测图像中的四边形形状? [英] How to detect a quadrilateral shape in an image in Java?

查看:404
本文介绍了如何在Java中检测图像中的四边形形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中检测图像中的四边形形状.我可以在OpenCV中使用HoughLinesP方法(将javaCV用于opencv java绑定)来检测线段.但我不知道如何检测四边形-是否有另一种方法或某种方式使用霍夫线?同样,一旦检测到四边形的角,我希望它像该类一样返回一个矩形-

I want to detect a quadrilateral shape in an image in Java. I can use the HoughLinesP method in OpenCV (using javaCV for opencv java binding) to detect line segments. But I can't figure out how to detect a quadrilateral shape - is there another method for that or some way to use the hough lines? Also once the corners of the quadrilateral are detected, I want it to return a rectangle just like this class does - http://www.aforgenet.com/framework/docs/html/7039a71d-a87d-47ef-7907-ad873118e374.htm - is there an equivalent library in openCV?

推荐答案

您的输入图像看起来如何?如果通过霍夫变换检测到许多线段,则可以尝试使用 RANSAC 生成一个大量的四边形假设,找到一种方法来评估其适合度并返回最佳假设.

How do your input images look like? If you detect lots of line segments with the Hough transformation, you could maybe try using RANSAC to generate a number of quadrilateral shape hypothesis, find a way to rate their fitness and return the best hypothesis.

可以这样生成一个假设:

One hypothesis could be generated like this:

  • 从检测到的线段集中选择四个随机线段
  • 通过查找所选线段所在的线的交点找到四个角点
  • 评估由这四个点定义的四边形的适合度

适应度可能是假设的四边形的面积(请参见 Bretschneider的公式用于计算凸四边形的面积),四边形边缘到检测到的集合中其他线段的距离,或者更适合您的应用的

The fitness could maybe be the area of the hypothetical quadrilateral (see the Bretschneider's formula for calculating the area of a convex quadrilateral), the distance of the quadrilateral edges from the other line segments in the detected set, or something that better fits your application.

这只是一个主意,我还没有尝试使用这种方法(但是我计划实现类似的方法).让我知道您是否认为这行得通,或者为什么行不通! :)

This is just an idea, I haven't tried using this approach yet (but I'm planing on implementing something similar). Let me know if you think this could work, or why it won't! :)

这篇关于如何在Java中检测图像中的四边形形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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