How to interpret image data

Hi all!
Essentially what I’m trying to do is take an image file, import it into Unity and have unity scan the image for shapes (or black lines that make up shapes) and convert each shape into verticies. I’ve found tutorials on creating 2d mesh’s from vertices but I’d like to be able to pull that information from an image like the one I’ve attached. If anyone can point me in the right direction I’d really appreciate it.
I’m not quite sure how to phrase the question, so I’m sorry if this has been answered somewhere else.

As i’ve understood it, you want to

  1. detect lines in an image
  2. create a mesh that closely represents these lines

You might try to do it yourself with something like Canny Edge Detection.
Another possibility would be to convert your images to .svg’s externally and then extract the vertices from that vector image.
This seems to cover svg parsing pretty well.

This sounds quite similar to what was asked over here. I’ve created this WebGL example. The code is on pastebin.

You can fill the shapes and use Marching Squares to generate the outline.

Another way, which was brought up, was the Canny edge detection. You’ll have to fill the shapes, or you’ll get back two contours, when you only want one. OpenCV has all of this for you. Then you can use the contour points as your vertices.

For anyone else looking for another way to do it, here’s another way I figured out. The image can’t have an alpha layer though.

void CountBlackPixels()
        for (int y = 0; y < texture.height; y++)
            for (int x = 0; x < texture.width; x++)
                float Scale = texture.GetPixel(x, y).grayscale;
                if (Scale<GrayscaleDefinition)
                    //Pixel is considered black
                    Vector2 V2 = new Vector2(x,y);

    void IdentifyShapes()
        while (BlackDots.Count > 0)
            ShapeObj NewShape = new ShapeObj();
            List<Vector2> NshapePoints = new List<Vector2>();
            Vector2 startingP = BlackDots[0];
            Node N = new Node(startingP, true);
            List<Node> AvailableNodes = new List<Node>(); 
            while (AvailableNodes.Count > 0)
                foreach (Vector2 V in AvailableNodes[0].Neighbors)
                    if (BlackDots.Contains(V))
                        Node Nd = new Node(V, true);
            NewShape.DataPoints = NshapePoints;