import Vision
func recognizedText(image: UIImage?) {
guard let cgImage = image?.cgImage else { return }
let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])
let request = VNRecognizeTextRequest { request, error in
guard let observation = request.results as? [VNRecognizedTextObservation], error == nil else { return }
let text = observation.compactMap({
$0.topCandidates(1).first?.string
}).joined(separator: ", ")
DispatchQueue.main.async {
print(text)
}
}
do {
try handler.perform([request])
} catch {
print(error.localizedDescription)
}
}
참고로 언어가 8가지 밖에 지원이 안되는데 한국어는 없음