recognition of shapes from an SVG file

hello all,

i have a question about shape recognition. to simplify my question i will take a simple example. let's say i have a pattern like in the image

i want to get the exact number of appearance of the shapes. as you can see, i have three different shapes that appear in different ways and rotations, in other examples it could be in different sizes(scale). my file is vector , an SVG file. i was wondering how can i do that, parsing the SVG, go through every shape and telling with shape is what. i have no idea how shape recognition works, but i am familiar with SVG, geomerative... any example or library could be helpful..

thank you in advance

Answers

  • Use OpenCV or BoofCV

    1. Are your shapes always tiled (completely filling the space)?
    2. Are the tilings always regular?
    3. Are they ever nested inside one another?
    4. Are they ever overlapping?
    5. Are they always defined by black lines with white outlines?
  • edited June 2017

    hello jeremy, thank your for your answer.

    i don't know much about computer vision and shaped recognition, if you have any good tutorial to recommend me that will be helpful.

    the advantage of using SVG ( i create) is i can change the colors and other aspects of it to fit my needs. so to answer your questions.

    1. Are your shapes always tiled (completely filling the space)?

    the shapes are always tiled, i gave a simple example to start but it can be more comlex

    the advantage is that i already know every piece/shape, they are like alphabet, so the choice is limited to a list of pieces/shapes.

    maybe in the future i would love to scan a real patter from a wall or ground and decompose it like in this example

    2.Are the tilings always regular?

    as you can see the tiling is not always regular, it is radial some times, but it can change

    1. Are they ever nested inside one another?

    no shaped is nested inside an other, it is always again puzzle

    1. Are they ever overlapping

    the shapes are overlapping in the edges, every shape is touching the shapes around and the vertices of one side are always above the vertices of some neighbor

    1. Are they always defined by black lines with white outlines?

    as i said before, i can change the colors or the pattern, commonly, they are filled with and altering colors

  • hi guys,

    i tried boofcv, and openCV, i played with the examples and i could get lines from or edges from my binary image, but i have no idea how to go from the edge detection to shape recognition. any good tutorial or hint ? is it possible to store my shapes in a separate file and ask the program to detect the closest shape from my image to the shapes in the list?

  • This is not easy, although there might be some shortcuts.

    Here are three example discussions of dealing with this problem in OpenCV (not Python specific). Your case is on the complex side because you have a wide variety of different polygons.

    https://stackoverflow.com/questions/11424002/how-to-detect-simple-geometric-shapes-using-opencv

    https://stackoverflow.com/questions/9663841/how-to-extract-simple-geometric-forms-from-contours-in-opencv

    https://stackoverflow.com/questions/22023923/shape-detection-in-python-using-opencv/22042006#22042006

    However, these approaches are meant to be robust as through a camera and uneven lighting. You have a precise image and know the exact shapes ahead of time -- although not their orientations. This suggests that you could use a very simple "image registration" approach -- slide your candidate shape across the entire image at a given size and orientation, and score each pixel by how close it is to a perfect match. This has been applied to fractals and tessellations in the past.

    https://en.m.wikipedia.org/wiki/Image_registration

    http://ieeexplore.ieee.org/document/5413618/?reload=true

  • thank you a lot jeremy , that is a path i am willing to follow. :)

Sign In or Register to comment.