1

I am looking for a fast idea/algorithm letting me to find squares (as mark points) in the image file. It shouldn't be so much challenge, however...

I started doing this by changing the color of the source image to a grey scale image and scanning each line of the image looking for two, three longest lines (pixel by pixel).

Then having an array of "lines" I am finding elements which may create the desire square.

The better idea would be to find the pattern with known traits, like: it is square, beyond of the square there are no distortion (there is just white space) etc.

The goal is to analyze the image 5000 X 5000 px in less than 1-2s.

Is it possible?

John
  • 1,752
  • 4
  • 24
  • 56
  • Adding a couple of images showing what you are trying to achieve, and what you have attempted, would be very useful. – Chris Jul 03 '12 at 08:46

2 Answers2

4

One of the OpenCV samples squares.cpp does just this, see here for code, . Alternatively you could look up the Hough transform to detect all lines in your image, and then test for two lines intersecting at right angles.

There are also a number of resources on this site which may help you:

I'm sure there are others, these are just the first few I came across.

Community
  • 1
  • 1
Chris
  • 7,494
  • 4
  • 35
  • 55
1

See Scale-invariant feature transform, template matching, and Hough transform. A quick and inaccurate guess may be to make a histogram of color and compare it. If the image is complicated enough, you might be able to distinguish between several sets of images.

To make the matter simple, assume we have three buckets for R, G, and B. A completely white image would have (100%, 100%, 100%) for (R, G, B). A completely red image would have (100%, 0%, 0%). A complicated image might have something like (23%, 53%, 34%). If you take the distance between the points in that (R, G, B) space, you can compare which one is "closer".

I guess links by chris solved the question :)

  • I could add that the image is black&white which should easy the matter. But the problem is that the searching pattern can be the part of the shape which may appear in the image and the only thing which distinguish is the white color beyond of the pattern. – John Jul 03 '12 at 08:45