Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created November 1, 2022 10:12
Show Gist options
  • Save wizard1066/975d5ff5a9d555e86972126a95db12ec to your computer and use it in GitHub Desktop.
Save wizard1066/975d5ff5a9d555e86972126a95db12ec to your computer and use it in GitHub Desktop.
func scanText() {
var superString:String = ""
let requestHandler = VNImageRequestHandler(cgImage: (selectedImage?.cgImage)!)
let request = VNRecognizeTextRequest{ (request, error) in
guard let observations = request.results as? [VNRecognizedTextObservation] else { return }
for textObjects in observations {
let topCandiate = textObjects.topCandidates(1)
if let recognizedText = topCandiate.first {
print(recognizedText.string)
superString += recognizedText.string
}
}
}
request.recognitionLevel = .accurate
try? requestHandler.perform([request])
strings.append(superString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment