https://github.com/tucan9389/textdetection-coreml
https://github.com/tucan9389/textdetection-coreml
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tucan9389/textdetection-coreml
- Owner: tucan9389
- License: mit
- Created: 2019-02-20T16:10:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-20T20:05:53.000Z (over 6 years ago)
- Last Synced: 2025-04-30T07:47:05.619Z (5 months ago)
- Language: Swift
- Size: 18.7 MB
- Stars: 81
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TextDetection-CoreML


This project is Text Detection on iOS using [Vision](https://developer.apple.com/documentation/vision) built-in model.
If you are interested in iOS + Machine Learning, visit [here](https://github.com/motlabs/iOS-Proejcts-with-ML-Models) you can see various DEMOs.
## Requirements
- Xcode 9.2+
- iOS 12.0+
- Swift 4.2## Performance
### Inference Time
| device | inference time |
| -------- | -------------- |
| iPhone X | 10 ms |## Build & Run
### 1. Prerequisites
#### Add permission in info.plist for device's camera access

### 2. Dependencies
No external library yet.
### 3. Code
#### 3.1 Import Vision framework
```swift
import Vision
```#### 3.2 Define properties for Vision
```swift
// properties on ViewController
var request: VNDetectTextRectanglesRequest?
```#### 3.3 Configure and prepare
```swift
override func viewDidLoad() {
super.viewDidLoad()let request = VNDetectTextRectanglesRequest(completionHandler: self.visionRequestDidComplete)
request.reportCharacterBoxes = true
self.request = request
}func visionRequestDidComplete(request: VNRequest, error: Error?) {
/* ------------------------------------------------------ */
/* something postprocessing what you want after inference */
/* ------------------------------------------------------ */
}
```#### 3.4 Inference 🏃♂️
```swift
// on the inference point
let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer)
if let request = request {
try? handler.perform([self.request])
}
```