Home

Awesome

TextDetection-CoreML

platform-ios swift-version lisence

This project is Text Detection on iOS using Vision built-in model.<br>If you are interested in iOS + Machine Learning, visit here you can see various DEMOs.<br>

TextDetection-CoreML_DEMO001

Requirements

Performance

Inference Time

deviceinference time
iPhone X10 ms

Build & Run

1. Prerequisites

Add permission in info.plist for device's camera access

prerequest_001_plist

2. Dependencies

No external library yet.

3. Code

3.1 Import Vision framework

import Vision

3.2 Define properties for Vision

// properties on ViewController
var request: VNDetectTextRectanglesRequest?

3.3 Configure and prepare

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 🏃‍♂️

// on the inference point
let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer)
if let request = request {
	try? handler.perform([self.request])
}