Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode, iOS - Image line/shape recognition

I want to identify squares/rectangles inside my UIImageView (or UIImage).

I looked at "Very simple image recognition on iOS", but that's not quite what I'm looking.

At the moment I have an UIImageView which is given a UIImage from time to time.

Most of the UIImagees has black squares/rectangles like this: img. But the corners may (or may not) have rounded edges.

How can I identify the first black square/rectangle's size? The end result would be to resize my UIImageView to make the first black square in the UIImage fill the screen. Like so: img With iPhone

like image 256
Aleksander Azizi Avatar asked Sep 09 '12 19:09

Aleksander Azizi


1 Answers

If your images will always be sharp black squares in a horizontal row, you could use corner detection to identify the rectangles, then pick out the four leftmost corners. I have three variants of corner detectors in my open source GPUImage framework based on the Harris, Noble, and Shi-Tomasi corner detection methods.

Running a GPUImageHarrisCornerDetectionFilter against your boxes with a threshold of 0.4 and sensitivity of 4.0 yields the following result:

Harris corner detection results

They're a little hard to see, but red crosshairs mark where the detector found the corners of your boxes. Again, you just need to take the leftmost four points to find your target rectangle, and then simply scale your image or view so that this rectangle now fills your view.

An example of how to run such feature detection can be found in either the FilterShowcase or FeatureExtractionTest example within my framework. I describe the process by which I do this in this answer over at Signal Processing.

like image 138
Brad Larson Avatar answered Sep 18 '22 01:09

Brad Larson