SwiftyTesseractRTE (SwiftyTesseract Real-Time Engine) is a real-time optical character recognition library built on top of SwiftyTesseract.
import SwiftyTesseract
import SwiftyTesseractRTE
Create an instance of SwiftyTesseractRTE and assign it's regionOfInterest property.
var realTimeEngine: SwiftyTesseractRTE!
@IBOutlet weak var previewView: UIView!
@IBOutlet weak var regionOfInterest: UIView! // A subview of previewView
override func viewDidLoad() {
let swiftyTesseract = SwiftyTesseract(language: .english)
realTimeEngine = SwiftyTesseractRTE(swiftyTesseract: swiftyTesseract, desiredReliability: .verifiable)
realTimeEngine.delegate = self
}
override func viewDidLayoutSubviews() {
// Must occur during viewDidLayoutSubviews() - Autolayout constraints are not set in viewDidLoad()
realTimeEngine.bindPreviewLayer(to: previewView)
realTimeEngine.regionOfInterest = regionOfInterest.frame
// Only neccessary if providing a visual cue where the regionOfInterest is to your end user
previewView.addSublayer(regionOfInterest.layer)
}
extension YourViewController: SwiftyTesseractRTEDelegate {
func onRecognitionComplete(_ recognizedString: String) {
// Do something with the recognized string
}
}
// Starts optical character recognition
realTimeEngine.recognitionIsActive = true
// Stops optical character recognition
realTimeEngine.recognitionIsActive = false
// Starts camera preview
realTimeEngine.startPreview()
// Stops camera preview
realTimeEngine.stopPreview()
For camera permissions, you will need to add the Privacy - Camera Usage Description
permission to your Info.plist
file. SwiftyTesseractRTE will handle requesting permission if it is not already granted.
SwiftyTesseractRTE is currently only able to utilized in portrait mode, but that does not mean your entire app also has to be portrait mode only. See the example project's AppDelegate (specifically the addition of a shouldRotate
boolean member variable and the implementation of application(_:supportedInterfaceOrientationsFor:)
) and ViewController files (specifically the viewWillAppear()
and viewWillDisappear()
methods) for an example on how to make a single view controller portrait mode only.
Tested with pod --version
: 1.3.1
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'SwiftyTesseractRTE', '~> 1.0'
end
Replace YOUR_TARGET_NAME
and then, in the Podfile
directory, type:
$ pod install
See SwiftyTesseract's Additional Configuration section on properly setting up SwiftyTesseract to be utilized in your project.
Official documentation for SwiftyTesseractRTE can be found here
Contributions are always welcome! Please refer to Contributing to SwiftyTesseractRTE for the full guidelines on creating issues and opening pull requests to the project.