-->

Recognize pattern in images

2019-07-26 08:35发布

问题:

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?

回答1:

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:

  • OpenCV C++/Obj-C: Detecting a sheet of paper / Square Detection
  • Are there any opencv function like "cvHoughCircles()" for square detection?
  • square detection, image processing

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



回答2:

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 :)