Created
August 3, 2017 14:53
-
-
Save codePrincess/4cea0818217188972e94d5902949da44 to your computer and use it in GitHub Desktop.
get text on image for handwriting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetchOCRText () { | |
let manager = CognitiveServices() | |
let ocrImage = image!.crop(rect: ocrImageRect!) | |
manager.retrieveTextOnImage(ocrImage) { | |
operationURL, error in | |
if #available(iOS 10.0, *) { | |
guard let _ = operationURL else { | |
print("Seems like the network call failed - did you enter the Computer Vision Key in CognitiveServices.swift in line 69? :)") | |
return | |
} | |
let when = DispatchTime.now() + 2 | |
DispatchQueue.main.asyncAfter(deadline: when) { | |
manager.retrieveResultForOcrOperation(operationURL!, completion: { | |
results, error -> (Void) in | |
if let theResult = results { | |
var ocrText = "" | |
for result in theResult { | |
ocrText = "\(ocrText) \(result)" | |
} | |
self.addLabelForOCR(text: ocrText) | |
} else { | |
self.addLabelForOCR(text: "No text for writing") | |
} | |
}) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment