Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line Endpoint Detection

I plan to detect endpoints of lines generated from characters (OCR) in C#. I want something like this:

enter image description here

What I mean by "endpoint" is I want to get the ends of any lines in the characters... for example a 'C' has two endpoints (one at the top and one at the bottom) as seen in the above image represented as a red pixel. I can extract the single lines from the "fatter" existing scanned characters, I can do edge detection and also Flood-fill analysis, but I can't seem to replicate the above! Any pointers to articles or existing code would be much appreciated! Any code samples will be fine as I can easily convert C++ or any .NET language to C#.

Thanks, Josh

like image 565
jduncanator Avatar asked Apr 17 '12 22:04

jduncanator


1 Answers

Since you don't have a definition of "endpoint" yet, I suggest:

  • A black point is an endpoint iif all neighbors (i.e. black points with manhattan distance <= 3) lie in a sector of less than 45 degrees.

Finding the angle to each neighboring black point should not be too difficult. Sorting these angles and finding the range is also not difficult, although you need to be careful of the discontinuity (where the angle suddenly changes by 360 degrees). It may be slightly faster to sort by slope without actually calculating angle. An additional speedup can be obtained with early-exit logic.

like image 130
Ben Voigt Avatar answered Sep 30 '22 06:09

Ben Voigt