Develop Intelligent iOS Apps with Swift by Özgür Sahin

Develop Intelligent iOS Apps with Swift by Özgür Sahin

Author:Özgür Sahin
Language: eng
Format: epub
ISBN: 9781484264218
Publisher: Apress


return

}

let maximumCandidates = 1

if let visionResult = results.first {

guard let candidate =

visionResult.topCandidates(maximumCandidates).first

else { return }

print(candidate.string)

showString(string: candidate.string)

}

Listing 4-2Text Recognition Process Results

In the preceding code, we check whether results exist in the request, and if they exist, we get the first result. This is the prediction result of the text recognition request. The “topCandidates” function returns the prediction results sorted by decreasing confidence score, so the top one is the best prediction. We get the prediction string for the first candidate and show it on the screen. The “showString” method takes the string and shows it in the text view. It dispatches this call in the main thread by calling DispatchQueue.main.async to ensure UI updates performed properly.

Our OCR app is ready. Now you can just run the app and try on your iPhone. If you focus the camera on any text, you will see the OCR results like in Figure 4-5. You can’t use the simulator for this app because it does not provide camera capture.

Figure 4-5Text Recognition App



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.