Introduction
The Microsoft Azure has a lot to offer when it comes to Cognitive Services, trying them out is really fun. Here in this article, we are going to see how we can detect and read texts from an image and show it in the display using the Cognitive Service Computer Vision AI. The service Computer Vision has its own machine language running which helps us to do our tasks in an easy and effective manner. It uses the technology Optical Character Recognition and extracts the words or text to a readable format. All we have to do is,use the service and write some custom codes as per our requirement. Sounds good? If yes, let’s just skip the introduction and jump on to the real fun. You can always read this article on my blog here.
Background
I love quotes, and I strongly believe that a single quote can make an impact in your life sometimes. One of my hobbies is collecting the images which contain quotes in it. Now, with the help of Azure Computer Vision cognitive service, I thought of creating an application which can get the quotes from the image and save it. You can easily think of many other usages of this service, below are some of them.
- Using the translator, which scans the image, reads the text and translates it
- Document creation from the images, which will be useful to save time
- A Google Glass, which capture what you see and translates the contents to your native language
- A digital medical prescription from the actual one
Imagine that you need to create a solution which can save all of your medical prescription contents in a table in a database, so that you can easily sort/filter and show them in a UI. You can even create a mobile application to do that. The possibilities are endless. Now let’s build one of them.
Prerequisites
Before we start, we should have the following things on hand.
- A valid Azure Subscription
- A good Code editor, I prefer VSCode or Visual Studio
Source Code
The source code be downloaded from here.
Let us start.
As I mentioned earlier, we will be using an Azure service to build our application. Azure is a cloud computing service created by Microsoft. For the last few years there has been the Computer Vision Resource in Azure
To create the Azure resource, login to the Azure portal and click on the +Create a resource menu. Once the window loads, you can search for the resource Computer Vision as shown in the preceding image.
Computer Vision Azure Resource
Now, click on the create button and fill in the form.

Create Resource
It may take a few minutes to finish the development of the resource. Once it is finished, we can go to the resource and get our keys from the Keys section under Resource Management. Save those keys somewhere as we need them while we create our applications.
Develop the Angular Client Application
Here, we will be creating an Angular application with the help of Angular CLI and to create the application we are going to use the command ng new Azure-AI-Image-Text-Reader where the last parameter is our application name. You should also be given a chance to select your CSS and routing option. Please note that you can add them later as well.
Once the application is ready, we can create our own Angular service.
detection.service.ts
To create the service, let’s use the preceding command.
ng g service detection
Here the name ‘detection’ is our service name. Now we can edit the service code as preceding.
- import {
- Injectable
- } from '@angular/core';
- import {
- HttpClient,
- HttpHeaders,
- HttpResponse
- } from '@angular/common/http';
- import {
- config
- } from './config';
- @Injectable({
- providedIn: 'root'
- })
- export class DetectionService {
- constructor(private http: HttpClient) {}
- async post(url: string): Promise < any > {
- const body = {
- url: url
- };
- const options = {
- headers: new HttpHeaders({
- 'Content-Type': 'application/json',
- 'Ocp-Apim-Subscription-Key': config.api.apiKey
- })
- };
- return await this.http.post(config.api.baseUrl, body, options).toPromise();
- }
- }
As you can see that we are creating an HttpClient call to our baseUrl which is been configured in our config.ts file. To call the Computer Vision AI service, it is mandatory to pass the subscription key, the one we have created in the Azure portal, to the request by using the header Ocp-Apim-Subscription-Key.
config.ts
- const config = {
- api: {
- baseUrl: 'https://westeurope.api.cognitive.microsoft.com/vision/v2.0/ocr',
- apiKey: ''
- }
- };
- export {
- config
- };




Vidyadharran GPosted Dec 12, 2019, 8:51 AM
Thankyou so much bro :) for sharing
Chittaranjan SwainPosted Dec 11, 2019, 11:11 PM
Nice article.
Prabakaran MPosted Dec 11, 2019, 6:51 AM
Nice Article Sir
Rushi MehtaPosted Dec 11, 2019, 1:56 AM
Nicely Explained articles. It will be very suedful