This is a complicated task I did the first part of a task in an old article
Connected Component Labeling and Vectorization[
^]
That creates little line segments that form the connected part of the image but to really do anything useful you now have to run recognition and/or filters on it. This next part of the process is the subject of an article I am currently writing and you really need to know what you desire as the end point.
For example I wrote commercial code that then took that output and ran fitters to recognize arcs and lines for CNC machines which is not that complicated. However to do things like text and number recognition that is not the best approach and a totally different kettle of fish.
So really what approach to take depends on what you are actually trying to do.