How to determine if the most obvious object in the picture is a shape?

Ok guys, I think I did everything I could except one important thing: Shape Extraction. I already do this quite simply, but there are times when it is really messy. The way I do this:

  • Select a point in the list generating a bounding box and selecting the closest point to the upper left (p point).
  • Create a new Shape object and add p to the shape outline.
  • If there are no more glasses available for testing in the main image, we simply return the shape object.
  • Get the closest point from p and keep it closest.
  • and the distance from the nearest point, point p, is less than or equal to ten
  • ---- Add it to the circuit
  • ---- Remove from the list of key points
  • ---- Set p to the nearest
  • ---- Get another nearest point from the nearest
  • ---- Repeat
  • If the shape has ten points or less in your circuit, return a null object (ignore all small shapes)
  • Otherwise, return the form object.

I repeat this process until the main list is empty. This means that we have extracted all the shapes.

Now I do the combination several times. It does so if I have |, ---, and | next to each other, it will combine to create a rectangle. Do you understand what I mean? Suppose I have a circle, the above extraction code sometimes says that half of the circle is one shape and the other half is another shape. Therefore, when I combine the figures, it becomes one circle.

Sigh, I can’t post photos, and I can’t upload it anywhere but the download site. This has some problems. Take a look at the following:

enter image description here

The image on the left is the initial image, and the contour points on the right. Now I click the "Define Form" button. It determines the shape of the most dominant form in the image (the shape object that contains most of the points in its outline).

enter image description here

Now he correctly says that it is a quadrangle, but for the wrong reasons. Due to my combinational shapes (which needed to be done to get the shape of a rectangle, otherwise it would be a small line for one shape and another small line like a different shape), it added a finger outline to the test.

So, all one figure is tested (black outline on the right in the second figure). Not only the β€œrectangle” part, but also everything in this picture. Can you guys think about how to clear this thing and extract the JUST part of the rectangle instead of turning on the fingers? I was thinking of some variation of A * for this, but in a case like this picture, it does not create a loop. So, what should I do when A * visits every point (since it cannot return to the starting point). What should I do then?

Can someone help me try to figure this out?

+4
source share
1 answer

I think the next part of your code is not so wise:

int iSelected = selected.ToArgb(); int iNextRight = nextRight.ToArgb(); if (Math.Abs(iSelected - iNextRight) > alpha) 

because the result is comparable almost exclusively to red (the rest are stored in less significant bites), suggesting that you are not using alpha in images.

If you want to achieve better results, you can use the Canny Edge Detector, or at least take a look at its processing steps.

Another option is to use a function similar to a magic wand to separate the main object from the background and then extract its edges. For these purposes, a pot model can be used.

If you need something simpler to determine the edges, how to do it, but use the sum of the difference of all color channels. Then suppose that the point in the middle is part of the search object and fills the form between the nearest edges, such as a brush. If you choose the right solution, you eliminate these fingers.

I wish you good luck.

+1
source

Source: https://habr.com/ru/post/1347811/


All Articles