PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Finding polygons from edge points of a photo

Can anyone point me in the right direction ...

See attached image - it is from a photo that has had an edge detection routine run over it. From here I want to be able to identify shapes. Particularly I'm interested in the square shapes near the center - I want to be able to detect it within a picture.

There must be some way of getting lines (in the form of vector with angle, gradient) from the points, filtered so short lines are ignored as they are probably not the shape trying to be identified, and from there the lines can be checked against each other to see what shapes they make.
Attachments:
Edges.gif
Looking at the picture this is a non trivial shape recognition problem in the computer vision research field, we touched it a bit at uni, but I don’t think it will be that simple unless ive missed an easy way of going about it.

It could probably be handled in a character recognition way using trained neural networks, but im not so sure.

Youd probably want to make a generalised corner detector that can then try to mach up corners to get the vectors you want.

Mmm theres about 100 ways of going about this depending on how much information you can feed the system about the picture. Try finding some computer vision boards and asking there :)
Yeah, I originally thought that it would be a good idea to find the corners first, and then make lines from them but I've written a little test app and done some "testing" of a few algorithms on paper and there is nothing easy about finding corners - it is easier to find the lines.

Neural network isn't appropriate because I don't want to just check if it exists - I need to know it's exact dimensions to extract angles from it.

All of the maths related solutions I've found seem way to complex, and would require far too much computational power.

Here is what I've come up with so far...have tried on paper and it works really well :) ...

(by the way, the plan is to have it done in real time at least 10fps on a pda with inbuilt camera)


- firstly, only deal with a component of the original camera image (128x128 pixels)
- split the image into 8x8 pixel grid (16x16 grid)
- for each 8x8 pixel block calculate the gradient by finding where pixels cross the boundary and following it through to an extremity pixel at a time, ignoring white pixels
- each 8x8 cell will have stored xStart, yStart, xEnd, yEnd, xInc, yInc
- once the pixel analysis is complete, then start interpreting the 16x16 grid of gradients by stepping through from top left and seeing if any surrounding element has a similar gradient - if so see if the xStart/yStart/xEnd/yEnd match between them - if so then it can be deemed as the "same line" so follow the gradient through to find the line end (never process element more than once, assumed one gradient per 8x8 pixels - so once an element is flagged as being part of a line it is ignored) - keep array of lines
- from paper tests this seems to be highly effective in extracting lines, but 8x8grid elements containing corners are ignored (only one gradient per element)
- the final step is to identify from the line array which ones intersect within one/perhaps two elements by extending their lines or solving a simultaneous equat etc - haven't got this quite sorted yet - but where they intersect will produce a polygon list and there shouldn't be too many four sided polygons because my edge filtering is biased to highlight transitions between black and white (which the marker I'm trying to identify will be)

Next step is to build a prototype, but the above algorithm should be very fast - the pixel processing, although not cache aligned access will at worst case have to investigate every pixel once in a 128x128 image which should be quick, and from there it's broken down into a 16x16 problem which at most has each element inspected about 5 times, and then depending on how many lines it will take a few more inspections to see how they join to form polygons. ... well that's the plan :)
hi,

maybe this is not exactly what you want but it might show you how to do it (and how fast it can get).

we ported a library called ARToolKit to the PocketPC some time ago and optimized it by using fixed point math, lookup tables, etc. ARToolKit finds rectangular "markers" in camera images and calculates the cameras relative pose from it.

our version runs at up to 150 images/sec on a PocketPC and since you probably don't need the pose estimation part (which is a major bottleneck) it could run a lot faster in your case...

you can find more information and our complete source code at http://studierstube.org/handheld_ar/artoolkitplus.php

bye,
Daniel