{"id":2654,"date":"2020-06-28T10:00:00","date_gmt":"2020-06-28T08:00:00","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=2654"},"modified":"2022-01-28T15:34:24","modified_gmt":"2022-01-28T14:34:24","slug":"swift-native-ocr-reader","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/","title":{"rendered":"Swift &#8211; Native OCR reader"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Starting from iOS 11, Apple introduces a new framework called <strong>Vision<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The Vision framework performs face and face landmark detection, text detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection.<\/p><cite><a href=\"https:\/\/developer.apple.com\/documentation\/vision\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.apple.com\/documentation\/vision<\/a><\/cite><\/blockquote>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Today we implement with few lines of code one of the simplest features of this beautiful framework, the OCR reader.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>OCR<\/strong> means: <strong>O<\/strong>ptical <strong>C<\/strong>haracter <strong>R<\/strong>ecognition. If you want to learn more, wikipedia helps you: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Optical_character_recognition\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/en.wikipedia.org\/wiki\/Optical_character_recognition<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-luminous-vivid-orange-background-color has-luminous-vivid-orange-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"let-s-start\"><strong>L<\/strong>et&#8217;s start!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new empty XCode project and a simple interface like this beautiful one:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"982\" height=\"1310\" src=\"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\" alt=\"\" class=\"wp-image-2655\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?w=982&amp;ssl=1 982w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?resize=768%2C1025&amp;ssl=1 768w\" sizes=\"auto, (max-width: 982px) 100vw, 982px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Composed of an <strong>UIImageView<\/strong>, an <strong>UITextView<\/strong> and <strong>UIButton<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Connect outlets and actions and prepare the code!<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"import-vision-framework\"><strong>I<\/strong>mport Vision framework<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First stuff, simplest is to add the new framework. So on top of your view controller, add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">import UIKit\nimport Vision\nimport VisionKit\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"show-the-documentcameraviewcontroller\"><strong>S<\/strong>how the DocumentCameraViewController<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Second thing, just to make a test, show the new <strong>VNDocumentCameraViewController<\/strong> that helps you to catch the document from any angle!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Attach the code to a button action:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">@IBAction func didScanPressed(_ sender: Any) {\n    let scanVC = VNDocumentCameraViewController()\n    scanVC.delegate = self\n    present(scanVC, animated: true)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remember to add the delegates needed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">extension ViewController: VNDocumentCameraViewControllerDelegate {\n\n    func documentCameraViewController(_ controller: VNDocumentCameraViewController,\n                                      didFinishWith scan: VNDocumentCameraScan)\n    {\n        guard scan.pageCount &gt;= 1 else {\n            controller.dismiss(animated: true)\n            return\n        }\n\n        imgDocument.image = scan.imageOfPage(at: 0)\n        processImage(scan.imageOfPage(at: 0))\n        controller.dismiss(animated: true)\n    }\n    \n    func documentCameraViewController(_ controller: VNDocumentCameraViewController,\n                                      didFailWithError error: Error)\n    {\n        controller.dismiss(animated: true)\n    }\n    \n    func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {\n        controller.dismiss(animated: true)\n    }\n\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>VNDocumentCameraViewController<\/strong> is your new photo view controller.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can automatically <strong>recognize the documents<\/strong>, can <strong>adjust colors<\/strong>, <strong>crop<\/strong>, <strong>resize<\/strong>, <strong>align<\/strong> and much more&#8230; and <em>the picture is taken automatically<\/em>!<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1125\" height=\"2436\" data-id=\"2661\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?fit=473%2C1024&amp;ssl=1\" alt=\"\" class=\"wp-image-2661\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?w=1125&amp;ssl=1 1125w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1775.png?resize=946%2C2048&amp;ssl=1 946w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1125\" height=\"2436\" data-id=\"2660\" src=\"https:\/\/i2.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?fit=473%2C1024&amp;ssl=1\" alt=\"\" class=\"wp-image-2660\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?w=1125&amp;ssl=1 1125w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1777.png?resize=946%2C2048&amp;ssl=1 946w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1125\" height=\"2436\" data-id=\"2659\" src=\"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?fit=473%2C1024&amp;ssl=1\" alt=\"\" class=\"wp-image-2659\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?w=1125&amp;ssl=1 1125w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_1778.png?resize=946%2C2048&amp;ssl=1 946w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cool<\/strong>&#8230; but now we want to read the text of our documents!<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"implement-the-text-request\"><strong>I<\/strong>mplement the Text Request<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start creating the class:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">private var ocrRequest = VNRecognizeTextRequest(completionHandler: nil)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to configure our request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>VNRecognizeTextRequest<\/strong> have different options that can be used:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>recognitionLanguages<\/li><li>customWords<\/li><li>recognitionLevel<\/li><li>usesLanguageCorrection<\/li><li>minimumTextHeight<\/li><li>etc..<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"setup-the-ocr\">Setup the OCR<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">private func setupOCR() {\n    \/\/ the OCR request to inizialize\n    ocrRequest = VNRecognizeTextRequest { (request, error) in\n        guard let observations = request.results as? [VNRecognizedTextObservation] else {\n            return\n        }\n\n        var ocrText = \"\"\n        for observation in observations {\n            \/\/ the top words candidates founded\n            guard let topCandidate = observation.topCandidates(1).first else {\n                return\n            }\n            ocrText += topCandidate.string + \"\\n\"\n        }\n        \n        DispatchQueue.main.async {\n            \/\/ the response\n            self.txtRecognizedText.text = ocrText\n        }\n    }\n\n    \/\/ we want an accurate recognition\n    ocrRequest.recognitionLevel = .accurate\n\n    \/\/ correcting eventual misspelled words\n    ocrRequest.usesLanguageCorrection = true\n\n    \/\/ and our languages in priority order are:\n    ocrRequest.recognitionLanguages = [\"it-IT\", \"es-ES\", \"en-US\", \"en-GB\", \"fr-FR\", \"de-DE\"]\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"process-the-image\"><strong>P<\/strong>rocess the image<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Last but first important stuff is to analyze the taken image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the delegates before we called the <strong>processImage()<\/strong> function and this is the code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">private func processImage(_ image: UIImage) {\n    guard let cgImage = image.cgImage else {\n        return\n    }\n    \n    DispatchQueue.main.async {\n        self.txtRecognizedText.text = \"\"\n    }\n\n    let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:])\n    do {\n        \/\/ we use our created OCR request\n        try requestHandler.perform([self.ocrRequest])\n    } catch {}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We reset the text field and <strong>perform<\/strong> an <strong>ocrRequest<\/strong> after the image is taken.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this tutorial, we skip the multiple image management and consider only the first one taken.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now everything is complete, remember to call <strong>setupOCR()<\/strong> in your init (viewDidLoad ).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-luminous-vivid-orange-background-color has-luminous-vivid-orange-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"final-result\"><strong>F<\/strong>inal result<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A full text recognized, automatically that you can read, edit, share and whatever you want:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1125\" height=\"2436\" src=\"https:\/\/i2.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?fit=473%2C1024&amp;ssl=1\" alt=\"\" class=\"wp-image-2671\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?w=1125&amp;ssl=1 1125w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?resize=139%2C300&amp;ssl=1 139w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?resize=473%2C1024&amp;ssl=1 473w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?resize=768%2C1663&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?resize=709%2C1536&amp;ssl=1 709w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/IMG_516CEC615D11-1.jpeg?resize=946%2C2048&amp;ssl=1 946w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption>I have no idea on what is this document. I&#8217;ve searched &#8220;document&#8221; on google&#8230;<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Now<\/strong>: add some <strong>UI<\/strong>, <strong>storage<\/strong>, a <strong>pay-per-use<\/strong> and you have created one of the 1000000 apps presents on the App Store that reads and scan documents &#x1f600;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enjoy scanning!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting from iOS 11, Apple introduces a new framework called Vision. The Vision framework performs face and face landmark detection, text detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection. https:\/\/developer.apple.com\/documentation\/vision Today we implement with few lines of <a class=\"read-more\" href=\"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[763,3],"tags":[943,582,711,747,583,940,944,942,46,255,603,938,939,946,945],"class_list":["post-2654","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-crop","tag-documents","tag-ocr","tag-orientation","tag-pdf","tag-reader","tag-resize","tag-scan","tag-swift","tag-text","tag-tutorial","tag-vision","tag-visionkit","tag-vnimagerequesthandler","tag-vnrecognizetextrequest"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift - Native OCR reader - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift - Native OCR reader - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"Starting from iOS 11, Apple introduces a new framework called Vision. The Vision framework performs face and face landmark detection, text detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection. https:\/\/developer.apple.com\/documentation\/vision Today we implement with few lines of Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-28T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-28T14:34:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"Swift &#8211; Native OCR reader\",\"datePublished\":\"2020-06-28T08:00:00+00:00\",\"dateModified\":\"2022-01-28T14:34:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/\"},\"wordCount\":394,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i1.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\",\"keywords\":[\"crop\",\"documents\",\"ocr\",\"orientation\",\"pdf\",\"reader\",\"resize\",\"scan\",\"swift\",\"text\",\"tutorial\",\"vision\",\"visionkit\",\"VNImageRequestHandler\",\"VNRecognizeTextRequest\"],\"articleSection\":[\"ios\",\"swift\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/\",\"name\":\"Swift - Native OCR reader - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i1.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\",\"datePublished\":\"2020-06-28T08:00:00+00:00\",\"dateModified\":\"2022-01-28T14:34:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i1.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\",\"contentUrl\":\"https:\\\/\\\/i1.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-native-ocr-reader\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift &#8211; Native OCR reader\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift - Native OCR reader - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/","og_locale":"en_US","og_type":"article","og_title":"Swift - Native OCR reader - while (true) {\u00a0}","og_description":"Starting from iOS 11, Apple introduces a new framework called Vision. The Vision framework performs face and face landmark detection, text detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection. https:\/\/developer.apple.com\/documentation\/vision Today we implement with few lines of Read More","og_url":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2020-06-28T08:00:00+00:00","article_modified_time":"2022-01-28T14:34:24+00:00","og_image":[{"url":"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1","type":"","width":"","height":""}],"author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#article","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"Swift &#8211; Native OCR reader","datePublished":"2020-06-28T08:00:00+00:00","dateModified":"2022-01-28T14:34:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/"},"wordCount":394,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#primaryimage"},"thumbnailUrl":"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1","keywords":["crop","documents","ocr","orientation","pdf","reader","resize","scan","swift","text","tutorial","vision","visionkit","VNImageRequestHandler","VNRecognizeTextRequest"],"articleSection":["ios","swift"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/","url":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/","name":"Swift - Native OCR reader - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#primaryimage"},"image":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#primaryimage"},"thumbnailUrl":"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1","datePublished":"2020-06-28T08:00:00+00:00","dateModified":"2022-01-28T14:34:24+00:00","breadcrumb":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#primaryimage","url":"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1","contentUrl":"https:\/\/i1.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2020\/05\/Schermata-2020-05-07-alle-19.09.21.png?fit=525%2C700&amp;ssl=1"},{"@type":"BreadcrumbList","@id":"https:\/\/www.albertopasca.it\/whiletrue\/swift-native-ocr-reader\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"Swift &#8211; Native OCR reader"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=2654"}],"version-history":[{"count":17,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2654\/revisions"}],"predecessor-version":[{"id":3086,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/2654\/revisions\/3086"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=2654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=2654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=2654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}