Azure Cognitive Services is a collection of cloud-based APIs and services developed by Microsoft, designed to enable developers to add AI (Artificial Intelligence) capabilities to their applications without requiring deep expertise in AI or machine learning. These services cover a wide range of functionalities as follows:
- Computer Vision: This service allows applications to analyze and understand visual content in images and videos. It can perform tasks like image recognition, object detection, and image classification.
- Text Analytics: Text Analytics service enables sentiment analysis, key phrase extraction, language detection, and entity recognition in text data.
- Speech Services: Developers can integrate speech-to-text and text-to-speech capabilities into their applications, enabling voice recognition and synthesis.
- Language Understanding: Language Understanding Intelligence Service (LUIS) enables applications to understand and interpret user commands through natural language processing (NLP).
- Translator: This service offers text and speech translation in multiple languages, making it easier to create multilingual applications.
- Custom Vision: Developers can train custom machine learning models for image classification and object detection, tailored to their specific use cases.
- Anomaly Detector: This service helps in identifying anomalies and unusual patterns within data, which is useful for applications like fraud detection and predictive maintenance.
- Decision: The Decision service provides AI-powered recommendations and decision-making capabilities for various scenarios, aiding users in making informed choices.
Image Categorization and Text Extraction from Images
Step1:
Create a Computer Vision resource from create a resource on Azure Portal. Fill in the details to create a computer vision resource. The pricing tier of F0 which is a free tier is sufficient for this project.
Step2:
Create an Azure Data Lake Gen 2 storage account within it to create a container, while creating the container set its Public Access level to Container(anonymous read access for containers and blobs).
Upload images into the container. Upload different types of images so that we can have a large dataset for analysis.
Step3:
Now in VScode create a .py file, then open a new terminal and install the following:
pip install azure-identity azure-storage-file-datalake requests
pip install azure-cognitiveservices-vision-computervision
write the code for image categorization and text extraction from images.
- In the Python code various libraries are to imported which are going to be used for text extraction from image and image categorization.
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
- In the code we need to give Computer Vision endpoint and subscription key.
- We need to provide the data lake endpoint where the images are stored.
- We need to specify the container name where the images are stored.
- We use variables to store various values like blob name , container name and then we build a blob_url where we can pass these values to access the images stored in the container by using for loop.
Code snippet of Text Extraction from Image
Code snippet of Image Categorization
Step4:
Run the python code and you will get output as below.
Here, in the output we can see that for Image:carphoto.jpg we can see the various text that are extracted from image.
For the output of Categorize the images for image Landmark.jpg we can see the various categories of image.