A lightweight and extensible iOS OCR toolkit (Open Source Pod)
XYZOCRKit provides efficient APIs for Optical Character Recognition (OCR), designed for iOS app development.
It is built with Swift 5 and is easy for both individual and team integration or secondary development.
- 🚀 High-performance local image-to-text recognition
- 🛡 Defensive image safety validation
- 🛠 Simple API, easy to integrate and extend
- 📦 One-line integration with the public CocoaPods repo
Integrated third-party OCR providers:
- OCR_Tencent (Tencent Cloud OCR)
- OCR_HuaWei (Huawei Cloud OCR)
- OCR_Google (Google Vision OCR)
- OCR_Face++ (Face++ Megvii OCR)
- OCR_Baidu (Baidu OCR)
- OCR_AWS (Amazon AWS Textract/Comprehend OCR)
- OCR_AliBaBailian (Alibaba Bailian OCR)
- OCR_Alibaba (Alibaba Cloud Standard OCR)
- OCR_Iflytek (iFLYTEK OCR)
Add the following to your Podfile:
pod 'XYZOCRKit'
Then run:
pod install
For local development or debugging:
pod 'XYZOCRKit', :path => '../XYZOCRKit'
Supports integration via Swift Package Manager (Xcode 11+).
Steps:
-
In Xcode, go to
File > Add Packages... -
Enter repository URL:
https://github.com/brandy2015/XYZOCRKit.git -
Select version or branch and click “Add Package”
-
In your code, simply
import XYZOCRKit
import XYZOCRKit
let image = UIImage(named: "test_sample.jpg")!
let result = XYZOCRKit.shared.recognizeText(in: image)
print(result.text)
if XYZOCRKit.shared.isValid(image: image) {
// Safe for recognition
}
-
XYZOCRKit.shared.recognizeText(in image: UIImage) -> OCRResult
Converts image to text, returning a structured result. -
XYZOCRKit.shared.isValid(image: UIImage) -> Bool
Checks if the image is valid/recognizable.
public struct OCRResult {
public let text: String // All recognized text
public let lines: [String] // Array of text, line by line
}
- iOS 13.0+
- Swift 5.0+
- Xcode 13/14/15/16
- Current version: 0.1.0
- Issues/PRs and feature suggestions are welcome!
MIT
Contributions and feedback are welcome. Let’s build a stronger open-source community together!