gitmyhub

SwiftOCR

Swift ★ 4.6k updated 5y ago

Fast and simple OCR library written in Swift

A deprecated Swift library for reading short alphanumeric codes from images on iOS and macOS using a neural network, now superseded by Apple's built-in Vision framework.

SwiftCocoaPodsiOSmacOSsetup: easycomplexity 2/5

SwiftOCR is a Swift library for reading text from images on iOS and macOS, with a specific focus on short alphanumeric codes like serial numbers, gift card codes, or verification strings. It uses a neural network internally to recognize characters after separating them from the image. The README begins with a prominent notice: this project is deprecated and no longer maintained. The author recommends using Apple's built-in Vision framework instead.

The library was designed as a faster, lighter alternative to Tesseract, an older C++ OCR engine. On short alphanumeric strings, the README reports that SwiftOCR was roughly 8 times faster than Tesseract (0.08 seconds vs 0.63 seconds), used significantly less CPU and memory, and was far more accurate (97.7% vs 45.2% in the author's tests). The trade-off is scope: SwiftOCR was built for codes, not for general text like articles or documents. For longer natural-language text, the author explicitly suggests Tesseract or Apple's Vision framework.

Adding it to a project was done through CocoaPods with a single line, and using it required only a few lines of Swift code: create an instance, pass an image, and get the recognized string back in a callback.

Training the neural network to recognize a new font was also possible through a macOS training app bundled in the repository. You select fonts, specify which characters to include, start the training process (which takes one to two minutes), and save the resulting trained model file. A test button let you evaluate accuracy before saving.

The library depended on three other Swift packages for the neural network, image processing, and connected-component analysis. It is licensed under the Apache 2.0 license. Because the project is now deprecated, it is not suitable for new development.

Where it fits