this post was submitted on 17 Aug 2023
1 points (100.0% liked)

Open Source on Reddit

1 readers
0 users here now

A subreddit for everything open source related.

founded 1 year ago
MODERATORS
 
This is an automated archive.

The original was posted on /r/opensource by /u/atypicalCookie on 2023-08-17 17:34:43+00:00.


swt.h is a header-only library to recognize and isolate text from the image, this is particularly useful in ocr where you want to just extract the text not any other shape.

so swt.h is short for stroke width transform, the library operates on raw pixel data aka unsigned char *, here are steps that go into extracting (and highlighting the text)

  • convert the image to grayscale for easier computation
  • convert the image into a black and white "mask" this is called a threshold
  • apply "connective component analysis" which is an graph based algorithm that traverses all the white pixels in a "connected" area
  • loop through each component, for each point we determine where it ends, store these widths and find their median. this is how "confident" we are thatthe component is a text, this exploits the fact that most fonts and handwritten texts share a similar stroke width.
  • and then optionally visualize the points on the image!

here is a peek on the code-equivalent of this

swtimage image = { image\_data, width, height, channels };
swtcomponents \*components = swt\_allocate\_components(image.width \* image.height);
swtresults \*results = swt\_allocate\_results(image.width \* image.height);

swt\_apply\_stroke\_width\_transform(&image, components, results);
swt\_visualize\_text\_on\_image(&image, results);

swt\_free\_components(components);
swt\_free\_results(results);

links

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here