Urgent.News

What's breaking now, across thousands of outlets.

Tech

I built a free image preprocessor to get better OCR results (PrepOCR)

The problem OCR is only as good as the image you feed it. A scanned form that's slightly tilted, low-contrast, or has a noisy background can tank recognition accuracy — even with a good OCR engine behind it. Most of the time the fix isn't a better OCR model, it's a cleaner input image. I wanted something small I could throw a batch of images at before sending them to an OCR pipeline, so I built…

OCR accuracy hinges on the quality of the input image. Scanned forms that are slightly tilted, have low contrast, or a noisy background can significantly harm recognition accuracy, even with a robust OCR engine. Often, the solution isn't a more advanced OCR model; it's about having a cleaner input image. I aimed to create a lightweight tool to pre-process multiple images before they are sent to an OCR pipeline.

Thus, I developed PrepOCR - a free image pre-processing service that specifically targets the transformations that truly impact OCR accuracy.

At present, PrepOCR supports the following transformations: tilt correction (rotating the image by a specified angle), enhancing contrast to ensure text separation from the background, and binarization (converting the image to black and white using a configurable threshold). Users simply upload one or more images, choose their desired settings, and receive a zip file containing the optimized versions. You can test PrepOCR here.

The backend is built using Scala, http4s, and AssetFlow. Multipart requests are uploaded, validated (checking size, dimensions, and image type via magic bytes, not just file extensions), processed, and zipped before being returned to the user. Processing each file sequentially, as it is in the backend, is CPU-bound and independent of other files.

To speed up the process, I switched from sequential processing to parallel processing using parTraverseN. On my machine with 14 cores, converting and optimizing 4 PNG images dropped from about 7 seconds to 2 seconds. However, on the free-tier server on which PrepOCR is hosted, most of this benefit is negated because CPU resources are heavily restricted, resulting in merely interleaved, rather than truly concurrent, processing.

A important lesson from this is that the available processors might not accurately reflect the actual CPU power available in a shared environment.

This project is currently an MVP, built due to a personal need, not based on validated demand. It remains to be seen if this tool will be useful to others. If you work with scanned documents, forms, or OCR pipelines and would like to try out the preprocessing step, I would appreciate any feedback, feature requests, bug reports, or even comments stating that "this already exists and does it better."

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Creepy crawlies

Creepy crawlies Konstantin Ryabitsev discusses how bad the "background radiation" of abusive crawlers has become from the perspective of git.kernel.org , the official Git repository for the Linux…

The Sneaky Coordinator Leak in UIViewRepresentable

Let's talk a little about a memory leak I recently found while working with UIViewRepresentable. The issue happened in a custom UIKit view wrapped inside SwiftUI. At first, nothing looked suspicious.

  • Memory leak in UIViewRepresentable custom view
  • Coordinator maintains strong reference to binding title
  • Weakly capture Coordinator instance in FixedCallbackButtonView

More from Monday 7 September →