XDevMag: Text Recognition
Using Appleās Vision to Extract Text from an Image

Let us point you to an article in the Xojo Developer Magazine in the 22.4 issue:
In this article, Stefanie Juchmes introduces how to use Apple’s Vision framework to recognize text within images on Mac and iOS systems using the MBS Xojo Plugins in Xojo. She explains the general capabilities of the Vision framework, such as recognizing text, barcodes, and classifying images into categories. The main focus of the article is text recognition, which can be achieved through Apple's Vision functions. The process begins with loading an image into the program using an open dialog, then passing the image to a method called VisionOCR. Depending on the macOS version, the method will either recognize the text's bounding boxes (on older versions, 10.13 and 10.14) or extract the actual text (on macOS 10.15 and higher).
The article provides detailed steps on handling different macOS versions and what functionalities are available for text recognition. On macOS 10.13 and 10.14, Vision can detect text positions but does not recognize the actual text, while macOS 10.15 and above can identify both the text and its position. The code snippet presented demonstrates how to detect text and its bounding boxes and how to handle errors using the VNRecognizeTextRequestMBS and VNDetectTextRectanglesRequestMBS methods. Additionally, the author explains how to store results and draw polygons around detected text areas on the image, which helps visualize the recognized regions.
Finally, the article covers how to extract the actual text from the image on macOS 10.15 and above, determine an appropriate font size, and display the recognized text on the image. The results can be output as text or processed further in a text field. The author also shows how to draw the image with the text onto a canvas, scaling it appropriately for display. This allows developers to integrate text recognition into their apps, making it easier to process and display text from images on macOS and iOS platforms.
Please subscribe to the Xojo Developer Magazine and read this article and the ones coming later this year.