Get Started with Azure AI Vision Read REST API or Client Libraries
The Azure AI Vision Read REST API or client libraries provide developers with AI algorithms for extracting text from images and returning it as structured strings.
This post will guide you through the process of installing the necessary package and trying out the sample code for basic tasks.
Overview:
Get started with the Azure AI Vision Read REST API or client libraries. The Read API provides you with AI algorithms for extracting text from images and returning it as structured strings. Follow these steps to install a package to your application and try out the sample code for basic tasks.
Before we jump to deep dive with OCR and if you are new to AI, refer link to get started on Azure AI Services.
Getting started with Azure AI Services
Getting started with AI vision
Use case:
Scenario: Extracting printed or handwritten text from images.
Use Cases:
Document Digitization:
Convert paper documents, invoices, receipts, and forms into digital text.
Archiving and Search:
Index and search through scanned documents or historical records.
Accessibility:
Generate alt text for images to improve accessibility for visually impaired users.
Content Moderation:
Detect and filter inappropriate or sensitive content in images.
Digital Asset Management:
Automatically tag and categorize images based on extracted text.
Demo:
Prerequisites
- An Azure subscription
- The Visual Studio IDE or current version of .NET Core.
- An Azure AI Vision resource. You can use the free pricing tier (
F0) to try the service. - The key and endpoint from the resource
- Image: https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/printed_text.jpg
Step by step:
Create Computer Vision

Install Microsoft.Azure.CognitiveServices.Vision.ComputerVision

Code Walkthrough
Authenticate the client:
ComputerVisionClient client = Authenticate(endpoint, key);
public static ComputerVisionClient Authenticate(string endpoint, string key)
{
ComputerVisionClient client =
new ComputerVisionClient(new ApiKeyServiceClientCredentials(key))
{ Endpoint = endpoint };
return client;
}
ReadFileUrl:
public static async Task ReadFileUrl(ComputerVisionClient client, string urlFile)
{
Console.WriteLine("----------------------------------------------------------");
Console.WriteLine("READ FILE FROM URL");
Console.WriteLine();
// Read text from URL
var textHeaders = await client.ReadAsync(urlFile);
// After the request, get the operation location (operation ID)
string operationLocation = textHeaders.OperationLocation;
Thread.Sleep(2000);
// Retrieve the URI where the extracted text will be stored from the Operation-Location header.
// We only need the ID and not the full URL
const int numberOfCharsInOperationId = 36;
string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId);
// Extract the text
ReadOperationResult results;
Console.WriteLine($"Extracting text from URL file {Path.GetFileName(urlFile)}...");
Console.WriteLine();
do
{
results = await client.GetReadResultAsync(Guid.Parse(operationId));
}
while ((results.Status == OperationStatusCodes.Running ||
results.Status == OperationStatusCodes.NotStarted));
// Display the found text.
Console.WriteLine();
var textUrlFileResults = results.AnalyzeResult.ReadResults;
foreach (ReadResult page in textUrlFileResults)
{
foreach (Line line in page.Lines)
{
Console.WriteLine(line.Text);
}
}
Console.WriteLine();
}
}
Run the Program:

With the extracted text, you can perform further analysis or operations as per your use case. For example, you can extract specific words or characters from the text, sentiment analysis, or generate metadata based on the text content.
Conclusion
Using the Azure SDK and the OCR client library, you can easily read printed text from images using the Azure AI Vision Read API. This opens up a wide range of possibilities for applications such as document digitization, archiving and search, accessibility, content moderation, and digital asset management.
Don’t miss out on this opportunity to enhance your AI skills and explore the full potential of the Azure OCR service. Follow the steps outlined in this post to get started with OCR and unlock new possibilities for your applications.
