랭킹으로 돌아가기

NMAC427/SwiftOCR

Swift

Fast and simple OCR library written in Swift

ocrswiftocr-libraryoptical-character-recognitionocr-engineiosmacosswiftocrdeprecated
스타 성장
스타
4.6k
포크
477
주간 성장
이슈
82
2k4k
2016년 4월2019년 9월2023년 2월2026년 7월
README

⛔️ This Project is deprecated and no longer gets maintained!

Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and much less finicky.


Deprecated Carthage compatible CocoaPods Compatible Platform

SwiftOCR

SwiftOCR is a fast and simple OCR library written in Swift. It uses a neural network for image recognition. As of now, SwiftOCR is optimized for recognizing short, one line long alphanumeric codes (e.g. DI4C9CM). We currently support iOS and OS X.

Features

  • Easy to use training class
  • High accuracy
  • Great default image preprocessing
  • Fast and accurate character segmentation algorithm
  • Add support for lowercase characters
  • Add support for connected character segmentation

Why should I choose SwiftOCR instead of Tesseract?

This is a really good question.

If you want to recognize normal text like a poem or a news article, go with Tesseract, but if you want to recognize short, alphanumeric codes (e.g. gift cards), I would advise you to choose SwiftOCR because that's where it exceeds.

Tesseract is written in C++ and over 30 years old. To use it you first have to write a Objective-C++ wrapper for it. The main issue that's slowing down Tesseract is the way memory is managed. Too many memory allocations and releases slow it down.

I did some testing on over 50 difficult images containing alphanumeric codes. The results where astonishing. SwiftOCR beat Tesseract in every category.

SwiftOCR Tesseract
Speed 0.08 sec. 0.63 sec.
Accuracy 97.7% 45.2%
CPU ~30% ~90%
Memory 45 MB 73 MB

How does it work?

  1. Input image is thresholded (binarized).
  2. Characters are extracted from the image, using a technique called Connected-component labeling.
  3. Separated characters are converted into numbers, which are then fed into the neural network.

How to use it?

SwiftOCR is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftOCR'

If you ever used Tesseract you know how exhausting it can be to implement OCR into your project. SwiftOCR is the exact opposite of Tesseract. It can be implemented using just 6 lines of code.

import SwiftOCR

let swiftOCRInstance = SwiftOCR()
    
swiftOCRInstance.recognize(myImage) { recognizedString in
    print(recognizedString)
}

To improve your experience with SwiftOCR you should set your Build Configuration to Release.

Training

Training SwiftOCR is pretty easy. There are only a few steps you have to do, before it can recognize a new font.

The easiest way to train SwiftOCR is using the training app that can be found under /example/OS X/SwiftOCR Training. First select the fonts you want to train from the list. After that, you can change the characters you want to train in the text field. Finally, you have to press the Start Testing button. The only thing that's left now, is waiting. Depending on your settings, this can take between a half and two minutes. After about two minutes you may manually stop the training. Pressing the Save button will save trained network to your desktop. The Test button is used for evaluating the accuracy of the trained neural network.

Examples

Here is an example image. SwiftOCR has no problem recognizing it. If you try to recognize the same image using Tesseract the output is 'LABMENSW' ?!?!?.

Image 1

This image is difficult to recognize because of two reasons:

  • The lighting is uneven. This problem is solved by the innovative preprocessing algorithm of SwiftOCR.
  • The text in this image is distorted. Since SwiftOCR uses a neural network for the recognition, this isn't a real problem. A NN is flexible like a human brain and can recognize even the most distorted image (most of the time).

TODO

Dependencies

License

The code in this repository is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

NOTE: This software depends on other packages that may be licensed under different open source licenses.

관련 저장소
PaddlePaddle/PaddleOCR

Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between images/PDFs and LLMs. Supports 100+ languages.

PythonPyPIApache License 2.0ocrchineseocr
paddleocr.com
86k11.1k
tesseract-ocr/tesseract

Tesseract Open Source OCR Engine (main repository)

C++Apache License 2.0tesseracttesseract-ocr
tesseract-ocr.github.io
75.5k10.7k
opendatalab/MinerU

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

PythonPyPIOtherextract-datalayout-analysis
opendatalab.github.io/MinerU/
75.4k6.3k
hiroi-sora/Umi-OCR

OCR software, free and offline. 开源、免费的离线OCR软件。支持截屏/批量导入图片,PDF文档识别,排除水印/页眉页脚,扫描/生成二维码。内置多国语言库。

PythonPyPIMIT Licensepaddleocrocr
46.2k4.5k
paperless-ngx/paperless-ngx

A community-supported supercharged document management system: scan, index and archive all your documents

PythonPyPIGNU General Public License v3.0angulararchiving
docs.paperless-ngx.com
43.3k2.9k
ShareX/ShareX

ShareX is a free and open-source application that enables users to capture or record any area of their screen with a single keystroke. It also supports uploading images, text, and various file types to a wide range of destinations.

C#GNU General Public License v3.0screen-capturescreen-recorder
getsharex.com
38.7k3.9k
naptha/tesseract.js

Pure Javascript OCR for more than 100 Languages 📖🎉🖥

JavaScriptnpmApache License 2.0tesseractwebassembly
tesseract.projectnaptha.com
38.5k2.4k
ocrmypdf/OCRmyPDF

OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched

PythonPyPIMozilla Public License 2.0pythonocr
ocrmypdf.readthedocs.io
34.2k2.4k
JaidedAI/EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.

PythonPyPIApache License 2.0ocrdeep-learning
jaided.ai
29.8k3.6k
opendataloader-project/opendataloader-pdf

PDF Parser for AI-ready data. Automate PDF accessibility. Open-source.

JavaMavenApache License 2.0jsonmarkdown
opendataloader.org
27.7k2.7k
pot-app/pot-desktop

🌈一个跨平台的划词翻译和OCR软件 | A cross-platform software for text translation and recognition.

JavaScriptnpmGNU General Public License v3.0translationpot
pot-app.com
19.1k955
lukas-blecher/LaTeX-OCR

pix2tex: Using a ViT to convert images of equations into LaTeX code.

PythonPyPIMIT Licensemachine-learningtransformer
lukas-blecher.github.io/LaTeX-OCR/
16.5k1.3k