With this project I tried to simplify, as much em possible, the use of Apple's OCR.
This framework will be usable by iOS 13 and above or MacOS 10.15 and above.
LNSimpleOCRKit is available via SwiftPackage.
Add the following to you Package.swift file's dependencies:
.package(url: "https://github.com/sciasxp/LNSimpleOCRKit.git", from: "1.1.0"),
To integrate LNSimpleOCRKit into your project using CocoaPods, specify it in your Podfile:
pod 'LNSimpleOCRKit'
import LNSimpleOCRKit
let ocrKit = LNSimpleOCRKit()
ocrKit.detectText(for: <#Your UIImage Here#>) { result in
switch result {
case .success(let text):
print(text)
case .failure(let error):
print(error.localizedDescription)
}
}
Done!
That's it, simple as that.
There are some callbacks and configurations you can apply if you choose so.
Basically you can configura three elements of your OCR:
To keep it simple, here goes an exemple:
let ocrConfiguration = OCRConfiguration(language: .english, type: .accurate, languageCorrection: true)
let ocrKit = LNSimpleOCRKit(configuration: ocrConfiguration)
You are able to preprocess your image via closure if you so want.
Here how you do it:
let ocrConfiguration = OCRConfiguration(language: .english, type: .accurate, languageCorrection: true)
let ocrKit = LNSimpleOCRKit(preprocessor: { image in
return image.resizableImage(withCapInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
},
configuration: ocrConfiguration)
Also post-process a detected text and display detection progress.
let ocrKit = LNSimpleOCRKit()
ocrKit.detectText(for: image) { progress in
print("Detection progress: \(progress * 100)%")
} postprocessor: { text in
var processed = text
processed = processed.trimmingCharacters(in: .whitespacesAndNewlines)
return processed
} result: { result in
switch result {
case .success(let text):
print(text)
case .failure(let error):
print(error.localizedDescription)
}
}
There is a method to receive all the raw observations ([VNRecognizedTextObservation]).
let ocrKit = LNSimpleOCRKit()
ocrKit.recognizedObservations(for: image) { result in
switch result {
case .success(let observations):
return observations
case .failure(let error):
print(error.localizedDescription)
}
}
You are most welcome in contributing to this project with either new features (maybe one mentioned from the future work or anything else), refactoring and improving the code. Also, feel free to give suggestions and feedbacks.
Created with ❤️ by Luciano Nunes.
Get in touch on [Email](https://raw.github.com/sciasxp/LNSimpleOCRKit/main/mailto: [email protected]) Visit: LinkdIn
link |
Stars: 1 |
Last commit: 1 year ago |
Compatibility to cocoapods
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics