How to recognize rectangles in this image?

后端 未结 9 1057
北恋
北恋 2020-11-29 00:36

I have a image with horizontal and vertical lines. In fact, this image is the BBC website converted to horizontal and vertical lines. My problem is that I want to be able to

相关标签:
9条回答
  • 2020-11-29 01:11

    iterate from left to right until you hit a color pixel then use modified flood fill algorithm. more info on the algo flood fill @ wiki

    0 讨论(0)
  • 2020-11-29 01:18

    There are several different approaches to your problem. I'd use a morphological image processing tool like this one. You will have the flexibility to define "rectangle" even something that not "exactly closed" (where the fill algorithm will fail).

    Another possibility could be to use a machine learning approach, which basically is more data-driven than definition-driven like the previous one. You'll have to give your algorithm several "examples" of what a rectangle is, and it will eventually learn (with a bias and an error rate).

    0 讨论(0)
  • 2020-11-29 01:19

    The flood fill would work, or you could use a modification of an edge tracking algorithm.

    what you do is: create a 2d array (or any other d2 data struct)- each row represents a horizontal pixel line on screen, and each column a vertical line

    iterate through all the pixels, left to right, and whenever you find a coloured one add its coordinates to the array

    iterate through the array and findying lines and storing the begin and end pixel for each one (different data structure)

    knowing that the begin of each line is its left/top pixel, you can easily check to see if any 4 lines comprise a rectangle

    0 讨论(0)
  • 2020-11-29 01:26

    I believe you are looking for the generalized Hough transform.

    0 讨论(0)
  • 2020-11-29 01:27

    In computer vision there is a algorithm called Generalized Hough Transform which maybe can solve your problem. There should be open source code having implemented this algorithm. Just search for it.

    0 讨论(0)
  • 2020-11-29 01:28

    Opencv (image processing and computer vision library written in c) has implementation for hough transform (the simple hough transform find lines in an image, while the generalized one finds more complex objects) so that could be a good start. For the rectangles which do have closed corners there are also corner detectors such as cornerHarris which can help.

    I ran the houghlines demo provided with opencv and here's the result on the image you gave (detected lines marked in red):
    (source: splintec.com)

    0 讨论(0)
提交回复
热议问题