How to extract and simplify lines using OpenCV?

I have a skeletonized image. How can I extract and simplify lines, for example, on the right image using OpenCV?

Example

Thanks.

Update

I have skeleton nodes.

Skeleton nodes

Now I need to combine the points if they are on the same line. How can i do this?

Joined points

And then simplify this path. I think I know how to do this, but if you have any ideas, please give me some advice.

Simplify path

+4
source share
1 answer

Basically you need to create a graph based on the nodes of your skeletal image. The vertices of your graph will correspond to the set of nodes.

I suggest you this algorithm for extracting edges of a graph:

For each node, use an 8-neighborhood (8N) to visit all pixel elements. Put the entire skeleton pixel in the queue and continue until you find the node. When the queue is empty, you will have all the edges for this node

+4
source

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


All Articles