This API Adds Machine Learning Computer Vision To Your App
Microsoft’s Azure has a broad collection of services you can access with an easy-to-use API. Azure is Microsoft’s cloud hosting and computing platform with a catalog of more than 200 different products. It also includes products which allow you to implement Machine Learning services. Those services all have an API which can you can access using client access libraries or a REST client. Delphi takes this ease of use one step further by providing a TAzureConnectionInfo to implement some of those services quickly and with a minimal amount of code. Also, we can access the services using Delphi’s built-in REST client. Is Azure Read Client Free? No, the Azure Read Client is not free, but the good news is when you first register you will get some free 12 months services and an free-tier allowance for services so you can try things out as you develop, test and launch your app. Some Azure services have very generous ‘always free’ levels. The service we going to use in our OCR application is “Cognitive Search” which is one of those which is always free. It has a permanent limit of 10,000 documents, but that’s more than enough for our testing purposes. How do we get API credentials for the “Computer Vision” service resources? For our OCR application, we going to use the “Cognitive Services->Computer Vision” resource. First you must have an “Azure subscription”. Go to the link below and create an “Azure subscription” if you don’t have one. It’s free to start! https://azure.microsoft.com/en-us/free/cognitive-services/ Once you have the subscription, you can create the required service links. Go to this link to create a “Computer Vision” resource. https://portal.azure.com/#create/Microsoft.CognitiveServicesComputerVision Make sure you select the correct region because you can’t go back and change it later. Now go to the resource you created and choose “Keys and Endpoint” from the left-hand menu. Now, copy one of the keys and and the location. We need those in our application. How to connect to the Cognitive Services REST API? We need TRESTClient, TRESTRequest and a TRESTResponse components to connect to the cognitive services REST Api. Lets drag and drop TRESTClient in to the forum and do some basic property changes. Make sure the “Accept” property has “application/json” type. Set the content type to “application/json“. Then drop a TRESTRequest component into the forum and set client property to the client we created earlier. Set the method to “rmPOST“. Place a TRESTResponse component and set the response property in the request component to this response object. Add some edit boxes, buttons and a memo box to complete our interface. How do we use the API to post the image for processing? We cannot post the image to cognitive services and get the result in one call. The image processing takes time, although usually this is less than five seconds. So, first we need to submit our image to the cognitive service and get the “Operation-Location” and check the status until it’s “succeeded”. If the server is still processing the image, status will be “running” instead. For each and every call to cognitive service API, we need to provide our subscription key through the HTTP Header. It’s the key we copied earlier from the resource we created. To do that, add a new parameter to TRESTRequest component, set the ‘kind’ to […]
