Quickstart: Image Analysis 4.0
Get started with the Image Analysis 4.0 REST API or client SDK to set up a basic image analysis application. The Image Analysis service provides you with AI algorithms for processing images and returning information on their visual features. Follow these steps to install a package to your application and try out the sample code.
Use the Image Analysis client SDK for C# to analyze an image to read text and generate an image caption. This quickstart calls a function AnalyzeImage()
, which uses the client object to analyze a remote image and print the results to the console.
Reference documentation | Packages (NuGet) | Samples
Tip
The Analysis 4.0 API can do many different operations. See the Analyze Image how-to guide for examples that showcase all of the available features.
Prerequisites
- An Azure subscription - Create one for free
- The Visual Studio IDE with workload .NET desktop development enabled. Or if you don't plan on using Visual Studio IDE, you need .NET 6.0 SDK or higher installed.
- .NET Runtime installed.
- Once you have your Azure subscription, create a Vision resource in the Azure portal. In order to use the captioning feature in this quickstart, you must create your resource in one of the following Azure regions: East US, France Central, Korea Central, North Europe, Southeast Asia, West Europe, West US. After it deploys, select Go to resource.
- You need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service.
- You can use the free pricing tier (
F0
) to try the service, and upgrade later to a paid tier for production.
Set up application
Create a new C# application.
Open Visual Studio, and under Get started select Create a new project. Set the template filters to C#/All Platforms/Console. Select Console App (command-line application that can run on .NET on Windows, Linux and macOS) and choose Next. Update the project name to ImageAnalysisQuickstart and choose Next. Select .NET 6.0 or above, and choose Create to create the project.
Install the client SDK
Once you've created a new project, install the client SDK by right-clicking on the project solution in the Solution Explorer and selecting Manage NuGet Packages. In the package manager that opens select Browse, check Include prerelease, and search for Azure.AI.Vision.ImageAnalysis
. Select Install. For more information, see the SDK installation guide.
Create environment variables
In this example, write your credentials to environment variables on the local machine that runs the application.
Go to the Azure portal. If the resource you created in the Prerequisites section deployed successfully, select Go to resource under Next Steps. You can find your key and endpoint under Resource Management in the Keys and Endpoint page. Your resource key isn't the same as your Azure subscription ID.
Tip
Don't include the key directly in your code, and never post it publicly. See the Azure AI services security article for more authentication options like Azure Key Vault.
To set the environment variable for your key and endpoint, open a console window and follow the instructions for your operating system and development environment.
- To set the
VISION_KEY
environment variable, replaceyour-key
with one of the keys for your resource. - To set the
VISION_ENDPOINT
environment variable, replaceyour-endpoint
with the endpoint for your resource.
setx VISION_KEY your-key
setx VISION_ENDPOINT your-endpoint
After you add the environment variables, you may need to restart any running programs that will read the environment variables, including the console window.
Analyze Image
From the project directory, open the Program.cs file that was created previously with your new project. Paste in the following code:
Tip
The code shows analyzing an image URL. You can also analyze a local image file, or an image from a memory buffer. For more information, see the Analyze Image how-to guide.
using Azure;
using Azure.AI.Vision.Common;
using Azure.AI.Vision.ImageAnalysis;
class Program
{
static void AnalyzeImage()
{
var serviceOptions = new VisionServiceOptions(
Environment.GetEnvironmentVariable("VISION_ENDPOINT"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("VISION_KEY")));
using var imageSource = VisionSource.FromUrl(
new Uri("https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png"));
var analysisOptions = new ImageAnalysisOptions()
{
Features = ImageAnalysisFeature.Caption | ImageAnalysisFeature.Text,
Language = "en",
GenderNeutralCaption = true
};
using var analyzer = new ImageAnalyzer(serviceOptions, imageSource, analysisOptions);
var result = analyzer.Analyze();
if (result.Reason == ImageAnalysisResultReason.Analyzed)
{
if (result.Caption != null)
{
Console.WriteLine(" Caption:");
Console.WriteLine($" \"{result.Caption.Content}\", Confidence {result.Caption.Confidence:0.0000}");
}
if (result.Text != null)
{
Console.WriteLine($" Text:");
foreach (var line in result.Text.Lines)
{
string pointsToString = "{" + string.Join(',', line.BoundingPolygon.Select(pointsToString => pointsToString.ToString())) + "}";
Console.WriteLine($" Line: '{line.Content}', Bounding polygon {pointsToString}");
foreach (var word in line.Words)
{
pointsToString = "{" + string.Join(',', word.BoundingPolygon.Select(pointsToString => pointsToString.ToString())) + "}";
Console.WriteLine($" Word: '{word.Content}', Bounding polygon {pointsToString}, Confidence {word.Confidence:0.0000}");
}
}
}
}
else
{
var errorDetails = ImageAnalysisErrorDetails.FromResult(result);
Console.WriteLine(" Analysis failed.");
Console.WriteLine($" Error reason : {errorDetails.Reason}");
Console.WriteLine($" Error code : {errorDetails.ErrorCode}");
Console.WriteLine($" Error message: {errorDetails.Message}");
}
}
static void Main()
{
try
{
AnalyzeImage();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
Then, build and run the application. You should see output similar to the one shown here.
Build and run the application by selecting Start Debugging from the Debug menu at the top of the IDE window (or press F5).
Output
The console output should show something similar to the following text:
Caption:
"a person pointing at a screen", Confidence 0.4892
Text:
Line: '9:35 AM', Bounding polygon {{X=130,Y=129},{X=215,Y=130},{X=215,Y=149},{X=130,Y=148}}
Word: '9:35', Bounding polygon {{X=131,Y=130},{X=171,Y=130},{X=171,Y=149},{X=130,Y=149}}, Confidence 0.9930
Word: 'AM', Bounding polygon {{X=179,Y=130},{X=204,Y=130},{X=203,Y=149},{X=178,Y=149}}, Confidence 0.9980
Line: 'E Conference room 154584354', Bounding polygon {{X=130,Y=153},{X=224,Y=154},{X=224,Y=161},{X=130,Y=161}}
Word: 'E', Bounding polygon {{X=131,Y=154},{X=135,Y=154},{X=135,Y=161},{X=131,Y=161}}, Confidence 0.1040
Word: 'Conference', Bounding polygon {{X=142,Y=154},{X=174,Y=154},{X=173,Y=161},{X=141,Y=161}}, Confidence 0.9020
Word: 'room', Bounding polygon {{X=175,Y=154},{X=189,Y=155},{X=188,Y=161},{X=175,Y=161}}, Confidence 0.7960
Word: '154584354', Bounding polygon {{X=192,Y=155},{X=224,Y=154},{X=223,Y=162},{X=191,Y=161}}, Confidence 0.8640
Line: '#: 555-173-4547', Bounding polygon {{X=130,Y=163},{X=182,Y=164},{X=181,Y=171},{X=130,Y=170}}
Word: '#:', Bounding polygon {{X=131,Y=163},{X=139,Y=164},{X=139,Y=171},{X=131,Y=171}}, Confidence 0.0360
Word: '555-173-4547', Bounding polygon {{X=142,Y=164},{X=182,Y=165},{X=181,Y=171},{X=142,Y=171}}, Confidence 0.5970
Line: 'Town Hall', Bounding polygon {{X=546,Y=180},{X=590,Y=180},{X=590,Y=190},{X=546,Y=190}}
Word: 'Town', Bounding polygon {{X=547,Y=181},{X=568,Y=181},{X=568,Y=190},{X=546,Y=191}}, Confidence 0.9810
Word: 'Hall', Bounding polygon {{X=570,Y=181},{X=590,Y=181},{X=590,Y=191},{X=570,Y=190}}, Confidence 0.9910
Line: '9:00 AM - 10:00 AM', Bounding polygon {{X=546,Y=191},{X=596,Y=192},{X=596,Y=200},{X=546,Y=199}}
Word: '9:00', Bounding polygon {{X=546,Y=192},{X=555,Y=192},{X=555,Y=200},{X=546,Y=200}}, Confidence 0.0900
Word: 'AM', Bounding polygon {{X=557,Y=192},{X=565,Y=192},{X=565,Y=200},{X=557,Y=200}}, Confidence 0.9910
Word: '-', Bounding polygon {{X=567,Y=192},{X=569,Y=192},{X=569,Y=200},{X=567,Y=200}}, Confidence 0.6910
Word: '10:00', Bounding polygon {{X=570,Y=192},{X=585,Y=193},{X=584,Y=200},{X=570,Y=200}}, Confidence 0.8850
Word: 'AM', Bounding polygon {{X=586,Y=193},{X=593,Y=194},{X=593,Y=200},{X=586,Y=200}}, Confidence 0.9910
Line: 'Aaron Buaion', Bounding polygon {{X=543,Y=201},{X=581,Y=201},{X=581,Y=208},{X=543,Y=208}}
Word: 'Aaron', Bounding polygon {{X=545,Y=202},{X=560,Y=202},{X=559,Y=208},{X=544,Y=208}}, Confidence 0.6020
Word: 'Buaion', Bounding polygon {{X=561,Y=202},{X=580,Y=202},{X=579,Y=208},{X=560,Y=208}}, Confidence 0.2910
Line: 'Daily SCRUM', Bounding polygon {{X=537,Y=259},{X=575,Y=260},{X=575,Y=266},{X=537,Y=265}}
Word: 'Daily', Bounding polygon {{X=538,Y=259},{X=551,Y=260},{X=550,Y=266},{X=538,Y=265}}, Confidence 0.1750
Word: 'SCRUM', Bounding polygon {{X=552,Y=260},{X=570,Y=260},{X=570,Y=266},{X=551,Y=266}}, Confidence 0.1140
Line: '10:00 AM 11:00 AM', Bounding polygon {{X=536,Y=266},{X=590,Y=266},{X=590,Y=272},{X=536,Y=272}}
Word: '10:00', Bounding polygon {{X=539,Y=267},{X=553,Y=267},{X=552,Y=273},{X=538,Y=272}}, Confidence 0.8570
Word: 'AM', Bounding polygon {{X=554,Y=267},{X=561,Y=267},{X=560,Y=273},{X=553,Y=273}}, Confidence 0.9980
Word: '11:00', Bounding polygon {{X=564,Y=267},{X=578,Y=267},{X=577,Y=273},{X=563,Y=273}}, Confidence 0.4790
Word: 'AM', Bounding polygon {{X=579,Y=267},{X=586,Y=267},{X=585,Y=273},{X=578,Y=273}}, Confidence 0.9940
Line: 'Churlette de Crum', Bounding polygon {{X=538,Y=273},{X=584,Y=273},{X=585,Y=279},{X=538,Y=279}}
Word: 'Churlette', Bounding polygon {{X=539,Y=274},{X=562,Y=274},{X=561,Y=279},{X=538,Y=279}}, Confidence 0.4640
Word: 'de', Bounding polygon {{X=563,Y=274},{X=569,Y=274},{X=568,Y=279},{X=562,Y=279}}, Confidence 0.8100
Word: 'Crum', Bounding polygon {{X=570,Y=274},{X=582,Y=273},{X=581,Y=279},{X=569,Y=279}}, Confidence 0.8850
Line: 'Quarterly NI Hands', Bounding polygon {{X=538,Y=295},{X=588,Y=295},{X=588,Y=301},{X=538,Y=302}}
Word: 'Quarterly', Bounding polygon {{X=540,Y=296},{X=562,Y=296},{X=562,Y=302},{X=539,Y=302}}, Confidence 0.5230
Word: 'NI', Bounding polygon {{X=563,Y=296},{X=570,Y=296},{X=570,Y=302},{X=563,Y=302}}, Confidence 0.3030
Word: 'Hands', Bounding polygon {{X=572,Y=296},{X=588,Y=296},{X=588,Y=302},{X=571,Y=302}}, Confidence 0.6130
Line: '11.00 AM-12:00 PM', Bounding polygon {{X=536,Y=304},{X=588,Y=303},{X=588,Y=309},{X=536,Y=310}}
Word: '11.00', Bounding polygon {{X=538,Y=304},{X=552,Y=304},{X=552,Y=310},{X=538,Y=310}}, Confidence 0.6180
Word: 'AM-12:00', Bounding polygon {{X=554,Y=304},{X=578,Y=304},{X=577,Y=310},{X=553,Y=310}}, Confidence 0.2700
Word: 'PM', Bounding polygon {{X=579,Y=304},{X=586,Y=304},{X=586,Y=309},{X=578,Y=310}}, Confidence 0.6620
Line: 'Bebek Shaman', Bounding polygon {{X=538,Y=310},{X=577,Y=310},{X=577,Y=316},{X=538,Y=316}}
Word: 'Bebek', Bounding polygon {{X=539,Y=310},{X=554,Y=310},{X=554,Y=317},{X=539,Y=316}}, Confidence 0.6110
Word: 'Shaman', Bounding polygon {{X=555,Y=310},{X=576,Y=311},{X=576,Y=317},{X=555,Y=317}}, Confidence 0.6050
Line: 'Weekly stand up', Bounding polygon {{X=537,Y=332},{X=582,Y=333},{X=582,Y=339},{X=537,Y=338}}
Word: 'Weekly', Bounding polygon {{X=538,Y=332},{X=557,Y=333},{X=556,Y=339},{X=538,Y=338}}, Confidence 0.6060
Word: 'stand', Bounding polygon {{X=558,Y=333},{X=572,Y=334},{X=571,Y=340},{X=557,Y=339}}, Confidence 0.4890
Word: 'up', Bounding polygon {{X=574,Y=334},{X=580,Y=334},{X=580,Y=340},{X=573,Y=340}}, Confidence 0.8150
Line: '12:00 PM-1:00 PM', Bounding polygon {{X=537,Y=340},{X=583,Y=340},{X=583,Y=347},{X=536,Y=346}}
Word: '12:00', Bounding polygon {{X=539,Y=341},{X=553,Y=341},{X=552,Y=347},{X=538,Y=347}}, Confidence 0.8260
Word: 'PM-1:00', Bounding polygon {{X=554,Y=341},{X=575,Y=341},{X=574,Y=347},{X=553,Y=347}}, Confidence 0.2090
Word: 'PM', Bounding polygon {{X=576,Y=341},{X=583,Y=341},{X=582,Y=347},{X=575,Y=347}}, Confidence 0.0390
Line: 'Delle Marckre', Bounding polygon {{X=538,Y=347},{X=582,Y=347},{X=582,Y=352},{X=538,Y=353}}
Word: 'Delle', Bounding polygon {{X=540,Y=348},{X=559,Y=347},{X=558,Y=353},{X=539,Y=353}}, Confidence 0.5800
Word: 'Marckre', Bounding polygon {{X=560,Y=347},{X=582,Y=348},{X=582,Y=353},{X=559,Y=353}}, Confidence 0.2750
Line: 'Product review', Bounding polygon {{X=538,Y=370},{X=577,Y=370},{X=577,Y=376},{X=538,Y=375}}
Word: 'Product', Bounding polygon {{X=539,Y=370},{X=559,Y=371},{X=558,Y=376},{X=539,Y=376}}, Confidence 0.6150
Word: 'review', Bounding polygon {{X=560,Y=371},{X=576,Y=371},{X=575,Y=376},{X=559,Y=376}}, Confidence 0.0400
Clean up resources
If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
Next steps
In this quickstart, you learned how to install the Image Analysis client SDK and make basic image analysis calls. Next, learn more about the Analysis 4.0 API features.
- Image Analysis overview
- Sample source code can be found on GitHub.
Use the Image Analysis client SDK for Python to analyze a remote image to read text and generate an image caption. This quickstart uses the client object to analyze a remote image and print the results to the console.
Reference documentation | Package (PyPi) | Samples
Tip
The Analysis 4.0 API can do many different operations. See the Analyze Image how-to guide for examples that showcase all of the available features.
Prerequisites
An Azure subscription - Create one for free
Python 3.x. Your Python installation should include pip. You can check if you have pip installed by running
pip --version
on the command line. Get pip by installing the latest version of Python.Once you have your Azure subscription, create a Vision resource in the Azure portal. In order to use the captioning feature in this quickstart, you must create your resource in one of the following Azure regions: East US, France Central, Korea Central, North Europe, Southeast Asia, West Europe, West US, East Asia. After it deploys, select Go to resource.
- You need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service.
- You can use the free pricing tier (
F0
) to try the service, and upgrade later to a paid tier for production.
Create environment variables
In this example, write your credentials to environment variables on the local machine that runs the application.
Go to the Azure portal. If the resource you created in the Prerequisites section deployed successfully, select Go to resource under Next Steps. You can find your key and endpoint under Resource Management in the Keys and Endpoint page. Your resource key isn't the same as your Azure subscription ID.
Tip
Don't include the key directly in your code, and never post it publicly. See the Azure AI services security article for more authentication options like Azure Key Vault.
To set the environment variable for your key and endpoint, open a console window and follow the instructions for your operating system and development environment.
- To set the
VISION_KEY
environment variable, replaceyour-key
with one of the keys for your resource. - To set the
VISION_ENDPOINT
environment variable, replaceyour-endpoint
with the endpoint for your resource.
setx VISION_KEY your-key
setx VISION_ENDPOINT your-endpoint
After you add the environment variables, you may need to restart any running programs that will read the environment variables, including the console window.
Analyze Image
Open a command prompt where you want the new project, and create a new file named quickstart.py.
Run this command to install the Azure AI Vision client SDK:
python -m pip install azure-ai-vision
For more information, see the SDK installation guide.
Copy the following code into quickstart.py:
Tip
The code shows analyzing an image URL. You can also analyze a local image file, or an image from a memory buffer. For more information, see the Analyze Image how-to guide.
import os
import azure.ai.vision as sdk
service_options = sdk.VisionServiceOptions(os.environ["VISION_ENDPOINT"],
os.environ["VISION_KEY"])
vision_source = sdk.VisionSource(
url="https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png")
analysis_options = sdk.ImageAnalysisOptions()
analysis_options.features = (
sdk.ImageAnalysisFeature.CAPTION |
sdk.ImageAnalysisFeature.TEXT
)
analysis_options.language = "en"
analysis_options.gender_neutral_caption = True
image_analyzer = sdk.ImageAnalyzer(service_options, vision_source, analysis_options)
result = image_analyzer.analyze()
if result.reason == sdk.ImageAnalysisResultReason.ANALYZED:
if result.caption is not None:
print(" Caption:")
print(" '{}', Confidence {:.4f}".format(result.caption.content, result.caption.confidence))
if result.text is not None:
print(" Text:")
for line in result.text.lines:
points_string = "{" + ", ".join([str(int(point)) for point in line.bounding_polygon]) + "}"
print(" Line: '{}', Bounding polygon {}".format(line.content, points_string))
for word in line.words:
points_string = "{" + ", ".join([str(int(point)) for point in word.bounding_polygon]) + "}"
print(" Word: '{}', Bounding polygon {}, Confidence {:.4f}"
.format(word.content, points_string, word.confidence))
else:
error_details = sdk.ImageAnalysisErrorDetails.from_result(result)
print(" Analysis failed.")
print(" Error reason: {}".format(error_details.reason))
print(" Error code: {}".format(error_details.error_code))
print(" Error message: {}".format(error_details.message))
Then run the application with the
python
command on your quickstart file.python quickstart.py
Output
The console output should show something similar to the following text:
Caption:
'a person pointing at a screen', Confidence 0.4892
Text:
Line: '9:35 AM', Bounding polygon {130, 129, 215, 130, 215, 149, 130, 148}
Word: '9:35', Bounding polygon {131, 130, 171, 130, 171, 149, 130, 149}, Confidence 0.9930
Word: 'AM', Bounding polygon {179, 130, 204, 130, 203, 149, 178, 149}, Confidence 0.9980
Line: 'E Conference room 154584354', Bounding polygon {130, 153, 224, 154, 224, 161, 130, 161}
Word: 'E', Bounding polygon {131, 154, 135, 154, 135, 161, 131, 161}, Confidence 0.1040
Word: 'Conference', Bounding polygon {142, 154, 174, 154, 173, 161, 141, 161}, Confidence 0.9020
Word: 'room', Bounding polygon {175, 154, 189, 155, 188, 161, 175, 161}, Confidence 0.7960
Word: '154584354', Bounding polygon {192, 155, 224, 154, 223, 162, 191, 161}, Confidence 0.8640
Line: '#: 555-173-4547', Bounding polygon {130, 163, 182, 164, 181, 171, 130, 170}
Word: '#:', Bounding polygon {131, 163, 139, 164, 139, 171, 131, 171}, Confidence 0.0360
Word: '555-173-4547', Bounding polygon {142, 164, 182, 165, 181, 171, 142, 171}, Confidence 0.5970
Line: 'Town Hall', Bounding polygon {546, 180, 590, 180, 590, 190, 546, 190}
Word: 'Town', Bounding polygon {547, 181, 568, 181, 568, 190, 546, 191}, Confidence 0.9810
Word: 'Hall', Bounding polygon {570, 181, 590, 181, 590, 191, 570, 190}, Confidence 0.9910
Line: '9:00 AM - 10:00 AM', Bounding polygon {546, 191, 596, 192, 596, 200, 546, 199}
Word: '9:00', Bounding polygon {546, 192, 555, 192, 555, 200, 546, 200}, Confidence 0.0900
Word: 'AM', Bounding polygon {557, 192, 565, 192, 565, 200, 557, 200}, Confidence 0.9910
Word: '-', Bounding polygon {567, 192, 569, 192, 569, 200, 567, 200}, Confidence 0.6910
Word: '10:00', Bounding polygon {570, 192, 585, 193, 584, 200, 570, 200}, Confidence 0.8850
Word: 'AM', Bounding polygon {586, 193, 593, 194, 593, 200, 586, 200}, Confidence 0.9910
Line: 'Aaron Buaion', Bounding polygon {543, 201, 581, 201, 581, 208, 543, 208}
Word: 'Aaron', Bounding polygon {545, 202, 560, 202, 559, 208, 544, 208}, Confidence 0.6020
Word: 'Buaion', Bounding polygon {561, 202, 580, 202, 579, 208, 560, 208}, Confidence 0.2910
Line: 'Daily SCRUM', Bounding polygon {537, 259, 575, 260, 575, 266, 537, 265}
Word: 'Daily', Bounding polygon {538, 259, 551, 260, 550, 266, 538, 265}, Confidence 0.1750
Word: 'SCRUM', Bounding polygon {552, 260, 570, 260, 570, 266, 551, 266}, Confidence 0.1140
Line: '10:00 AM 11:00 AM', Bounding polygon {536, 266, 590, 266, 590, 272, 536, 272}
Word: '10:00', Bounding polygon {539, 267, 553, 267, 552, 273, 538, 272}, Confidence 0.8570
Word: 'AM', Bounding polygon {554, 267, 561, 267, 560, 273, 553, 273}, Confidence 0.9980
Word: '11:00', Bounding polygon {564, 267, 578, 267, 577, 273, 563, 273}, Confidence 0.4790
Word: 'AM', Bounding polygon {579, 267, 586, 267, 585, 273, 578, 273}, Confidence 0.9940
Line: 'Churlette de Crum', Bounding polygon {538, 273, 584, 273, 585, 279, 538, 279}
Word: 'Churlette', Bounding polygon {539, 274, 562, 274, 561, 279, 538, 279}, Confidence 0.4640
Word: 'de', Bounding polygon {563, 274, 569, 274, 568, 279, 562, 279}, Confidence 0.8100
Word: 'Crum', Bounding polygon {570, 274, 582, 273, 581, 279, 569, 279}, Confidence 0.8850
Line: 'Quarterly NI Hands', Bounding polygon {538, 295, 588, 295, 588, 301, 538, 302}
Word: 'Quarterly', Bounding polygon {540, 296, 562, 296, 562, 302, 539, 302}, Confidence 0.5230
Word: 'NI', Bounding polygon {563, 296, 570, 296, 570, 302, 563, 302}, Confidence 0.3030
Word: 'Hands', Bounding polygon {572, 296, 588, 296, 588, 302, 571, 302}, Confidence 0.6130
Line: '11.00 AM-12:00 PM', Bounding polygon {536, 304, 588, 303, 588, 309, 536, 310}
Word: '11.00', Bounding polygon {538, 304, 552, 304, 552, 310, 538, 310}, Confidence 0.6180
Word: 'AM-12:00', Bounding polygon {554, 304, 578, 304, 577, 310, 553, 310}, Confidence 0.2700
Word: 'PM', Bounding polygon {579, 304, 586, 304, 586, 309, 578, 310}, Confidence 0.6620
Line: 'Bebek Shaman', Bounding polygon {538, 310, 577, 310, 577, 316, 538, 316}
Word: 'Bebek', Bounding polygon {539, 310, 554, 310, 554, 317, 539, 316}, Confidence 0.6110
Word: 'Shaman', Bounding polygon {555, 310, 576, 311, 576, 317, 555, 317}, Confidence 0.6050
Line: 'Weekly stand up', Bounding polygon {537, 332, 582, 333, 582, 339, 537, 338}
Word: 'Weekly', Bounding polygon {538, 332, 557, 333, 556, 339, 538, 338}, Confidence 0.6060
Word: 'stand', Bounding polygon {558, 333, 572, 334, 571, 340, 557, 339}, Confidence 0.4890
Word: 'up', Bounding polygon {574, 334, 580, 334, 580, 340, 573, 340}, Confidence 0.8150
Line: '12:00 PM-1:00 PM', Bounding polygon {537, 340, 583, 340, 583, 347, 536, 346}
Word: '12:00', Bounding polygon {539, 341, 553, 341, 552, 347, 538, 347}, Confidence 0.8260
Word: 'PM-1:00', Bounding polygon {554, 341, 575, 341, 574, 347, 553, 347}, Confidence 0.2090
Word: 'PM', Bounding polygon {576, 341, 583, 341, 582, 347, 575, 347}, Confidence 0.0390
Line: 'Delle Marckre', Bounding polygon {538, 347, 582, 347, 582, 352, 538, 353}
Word: 'Delle', Bounding polygon {540, 348, 559, 347, 558, 353, 539, 353}, Confidence 0.5800
Word: 'Marckre', Bounding polygon {560, 347, 582, 348, 582, 353, 559, 353}, Confidence 0.2750
Line: 'Product review', Bounding polygon {538, 370, 577, 370, 577, 376, 538, 375}
Word: 'Product', Bounding polygon {539, 370, 559, 371, 558, 376, 539, 376}, Confidence 0.6150
Word: 'review', Bounding polygon {560, 371, 576, 371, 575, 376, 559, 376}, Confidence 0.0400
Clean up resources
If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
Next steps
In this quickstart, you learned how to install the Image Analysis client SDK and make basic image analysis calls. Next, learn more about the Analysis 4.0 API features.
- Image Analysis overview
- Sample source code can be found on GitHub.
Use the Image Analysis client SDK for C++ to analyze an image to read text and generate an image caption. This quickstart calls a function AnalyzeImage()
, which uses the client object to analyze a remote image and print the results to the console.
Reference documentation | Package (NuGet) | Samples
Tip
The Analysis 4.0 API can do many different operations. See the Analyze Image how-to guide for examples that showcase all of the available features.
Prerequisites
- An Azure subscription - Create one for free
- For Windows development, the Visual Studio IDE with workload Desktop development with C++ enabled.
- Once you have your Azure subscription, create a Vision resource in the Azure portal. In order to use the captioning feature in this quickstart, you must create your resource in one of the following Azure regions: East US, France Central, Korea Central, North Europe, Southeast Asia, West Europe, West US, East Asia, East Asia. After it deploys, select Go to resource.
- You need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service.
- You can use the free pricing tier (
F0
) to try the service, and upgrade later to a paid tier for production.
Set up application
Create a new C++ application.
Open Visual Studio, and under Get started select Create a new project. Set the template filters to C++/Windows/Console. Select Console App and choose Next. Update the project name to ImageAnalysisQuickstart and choose Create to create the project.
Install the client SDK
Once you've created a new project, install the client SDK by right-clicking on the project solution in the Solution Explorer and selecting Manage NuGet Packages. In the package manager that opens select Browse, check Include prerelease, and search for Azure.AI.Vision.ImageAnalysis
. Select Install. For more information, see the SDK installation guide.
Create environment variables
In this example, write your credentials to environment variables on the local machine that runs the application.
Go to the Azure portal. If the resource you created in the Prerequisites section deployed successfully, select Go to resource under Next Steps. You can find your key and endpoint under Resource Management in the Keys and Endpoint page. Your resource key isn't the same as your Azure subscription ID.
Tip
Don't include the key directly in your code, and never post it publicly. See the Azure AI services security article for more authentication options like Azure Key Vault.
To set the environment variable for your key and endpoint, open a console window and follow the instructions for your operating system and development environment.
- To set the
VISION_KEY
environment variable, replaceyour-key
with one of the keys for your resource. - To set the
VISION_ENDPOINT
environment variable, replaceyour-endpoint
with the endpoint for your resource.
setx VISION_KEY your-key
setx VISION_ENDPOINT your-endpoint
After you add the environment variables, you may need to restart any running programs that will read the environment variables, including the console window.
Analyze Image
From the project directory, open the ImageAnalysisQuickstart.cpp file that was created previously with your new project. Clear its contents and paste in the following code:
Tip
The code shows analyzing an image URL. You can also analyze a local image file, or an image from a memory buffer. For more information, see the Analyze Image how-to guide.
#include <vision_api_cxx_image_analyzer.hpp>
using namespace Azure::AI::Vision::ImageAnalysis;
using namespace Azure::AI::Vision::Input;
using namespace Azure::AI::Vision::Service;
std::string PolygonToString(std::vector<int32_t> boundingPolygon);
std::string GetEnvironmentVariable(const std::string name);
void AnalyzeImage()
{
auto serviceOptions = VisionServiceOptions::FromEndpoint(
GetEnvironmentVariable("VISION_ENDPOINT"),
GetEnvironmentVariable("VISION_KEY"));
auto imageSource = VisionSource::FromUrl(
"https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png");
auto analysisOptions = ImageAnalysisOptions::Create();
analysisOptions->SetFeatures(
{
ImageAnalysisFeature::Caption,
ImageAnalysisFeature::Text,
});
analysisOptions->SetLanguage("en");
analysisOptions->SetGenderNeutralCaption(true);
auto analyzer = ImageAnalyzer::Create(serviceOptions, imageSource, analysisOptions);
auto result = analyzer->Analyze();
if (result->GetReason() == ImageAnalysisResultReason::Analyzed)
{
const auto caption = result->GetCaption();
if (caption.HasValue())
{
std::cout << " Caption:" << std::endl;
std::cout << " \"" << caption.Value().Content << "\", Confidence " << caption.Value().Confidence << std::endl;
}
const auto detectedText = result->GetText();
if (detectedText.HasValue())
{
std::cout << " Text:\n";
for (const auto line : detectedText.Value().Lines)
{
std::cout << " Line: \"" << line.Content << "\"";
std::cout << ", Bounding polygon " << PolygonToString(line.BoundingPolygon) << std::endl;
for (const auto word : line.Words)
{
std::cout << " Word: \"" << word.Content << "\"";
std::cout << ", Bounding polygon " << PolygonToString(word.BoundingPolygon);
std::cout << ", Confidence " << word.Confidence << std::endl;
}
}
}
}
else
{
auto errorDetails = ImageAnalysisErrorDetails::FromResult(result);
std::cout << " Analysis failed." << std::endl;
std::cout << " Error reason = " << (int)errorDetails->GetReason() << std::endl;
std::cout << " Error code = " << errorDetails->GetErrorCode() << std::endl;
std::cout << " Error message = " << errorDetails->GetMessage() << std::endl;
}
}
std::string PolygonToString(std::vector<int32_t> boundingPolygon)
{
std::string out = "{";
for (int i = 0; i < boundingPolygon.size(); i += 2)
{
out += ((i == 0) ? "{" : ",{") +
std::to_string(boundingPolygon[i]) + "," +
std::to_string(boundingPolygon[i + 1]) + "}";
}
out += "}";
return out;
}
std::string GetEnvironmentVariable(const std::string name)
{
#if defined(_MSC_VER)
size_t size = 0;
char buffer[1024];
getenv_s(&size, nullptr, 0, name.c_str());
if (size > 0 && size < sizeof(buffer))
{
getenv_s(&size, buffer, size, name.c_str());
return std::string{ buffer };
}
#else
const char* value = getenv(name.c_str());
if (value != nullptr)
{
return std::string{ value };
}
#endif
return std::string{ "" };
}
int main()
{
try
{
AnalyzeImage();
}
catch (std::exception e)
{
std::cout << e.what();
}
return 0;
}
Then, compile and run the application by selecting Start Debugging from the Debug menu at the top of the IDE window (or press F5). You should see output similar to the one shown here.
Output
The console output should show something similar to the following text:
Caption:
"a person pointing at a screen", Confidence 0.489159
Text:
Line: "9:35 AM", Bounding polygon {{130,129},{215,130},{215,149},{130,148}}
Word: "9:35", Bounding polygon {{131,130},{171,130},{171,149},{130,149}}, Confidence 0.993
Word: "AM", Bounding polygon {{179,130},{204,130},{203,149},{178,149}}, Confidence 0.998
Line: "E Conference room 154584354", Bounding polygon {{130,153},{224,154},{224,161},{130,161}}
Word: "E", Bounding polygon {{131,154},{135,154},{135,161},{131,161}}, Confidence 0.104
Word: "Conference", Bounding polygon {{142,154},{174,154},{173,161},{141,161}}, Confidence 0.902
Word: "room", Bounding polygon {{175,154},{189,155},{188,161},{175,161}}, Confidence 0.796
Word: "154584354", Bounding polygon {{192,155},{224,154},{223,162},{191,161}}, Confidence 0.864
Line: "#: 555-173-4547", Bounding polygon {{130,163},{182,164},{181,171},{130,170}}
Word: "#:", Bounding polygon {{131,163},{139,164},{139,171},{131,171}}, Confidence 0.036
Word: "555-173-4547", Bounding polygon {{142,164},{182,165},{181,171},{142,171}}, Confidence 0.597
Line: "Town Hall", Bounding polygon {{546,180},{590,180},{590,190},{546,190}}
Word: "Town", Bounding polygon {{547,181},{568,181},{568,190},{546,191}}, Confidence 0.981
Word: "Hall", Bounding polygon {{570,181},{590,181},{590,191},{570,190}}, Confidence 0.991
Line: "9:00 AM - 10:00 AM", Bounding polygon {{546,191},{596,192},{596,200},{546,199}}
Word: "9:00", Bounding polygon {{546,192},{555,192},{555,200},{546,200}}, Confidence 0.09
Word: "AM", Bounding polygon {{557,192},{565,192},{565,200},{557,200}}, Confidence 0.991
Word: "-", Bounding polygon {{567,192},{569,192},{569,200},{567,200}}, Confidence 0.691
Word: "10:00", Bounding polygon {{570,192},{585,193},{584,200},{570,200}}, Confidence 0.885
Word: "AM", Bounding polygon {{586,193},{593,194},{593,200},{586,200}}, Confidence 0.991
Line: "Aaron Buaion", Bounding polygon {{543,201},{581,201},{581,208},{543,208}}
Word: "Aaron", Bounding polygon {{545,202},{560,202},{559,208},{544,208}}, Confidence 0.602
Word: "Buaion", Bounding polygon {{561,202},{580,202},{579,208},{560,208}}, Confidence 0.291
Line: "Daily SCRUM", Bounding polygon {{537,259},{575,260},{575,266},{537,265}}
Word: "Daily", Bounding polygon {{538,259},{551,260},{550,266},{538,265}}, Confidence 0.175
Word: "SCRUM", Bounding polygon {{552,260},{570,260},{570,266},{551,266}}, Confidence 0.114
Line: "10:00 AM 11:00 AM", Bounding polygon {{536,266},{590,266},{590,272},{536,272}}
Word: "10:00", Bounding polygon {{539,267},{553,267},{552,273},{538,272}}, Confidence 0.857
Word: "AM", Bounding polygon {{554,267},{561,267},{560,273},{553,273}}, Confidence 0.998
Word: "11:00", Bounding polygon {{564,267},{578,267},{577,273},{563,273}}, Confidence 0.479
Word: "AM", Bounding polygon {{579,267},{586,267},{585,273},{578,273}}, Confidence 0.994
Line: "Churlette de Crum", Bounding polygon {{538,273},{584,273},{585,279},{538,279}}
Word: "Churlette", Bounding polygon {{539,274},{562,274},{561,279},{538,279}}, Confidence 0.464
Word: "de", Bounding polygon {{563,274},{569,274},{568,279},{562,279}}, Confidence 0.81
Word: "Crum", Bounding polygon {{570,274},{582,273},{581,279},{569,279}}, Confidence 0.885
Line: "Quarterly NI Hands", Bounding polygon {{538,295},{588,295},{588,301},{538,302}}
Word: "Quarterly", Bounding polygon {{540,296},{562,296},{562,302},{539,302}}, Confidence 0.523
Word: "NI", Bounding polygon {{563,296},{570,296},{570,302},{563,302}}, Confidence 0.303
Word: "Hands", Bounding polygon {{572,296},{588,296},{588,302},{571,302}}, Confidence 0.613
Line: "11.00 AM-12:00 PM", Bounding polygon {{536,304},{588,303},{588,309},{536,310}}
Word: "11.00", Bounding polygon {{538,304},{552,304},{552,310},{538,310}}, Confidence 0.618
Word: "AM-12:00", Bounding polygon {{554,304},{578,304},{577,310},{553,310}}, Confidence 0.27
Word: "PM", Bounding polygon {{579,304},{586,304},{586,309},{578,310}}, Confidence 0.662
Line: "Bebek Shaman", Bounding polygon {{538,310},{577,310},{577,316},{538,316}}
Word: "Bebek", Bounding polygon {{539,310},{554,310},{554,317},{539,316}}, Confidence 0.611
Word: "Shaman", Bounding polygon {{555,310},{576,311},{576,317},{555,317}}, Confidence 0.605
Line: "Weekly stand up", Bounding polygon {{537,332},{582,333},{582,339},{537,338}}
Word: "Weekly", Bounding polygon {{538,332},{557,333},{556,339},{538,338}}, Confidence 0.606
Word: "stand", Bounding polygon {{558,333},{572,334},{571,340},{557,339}}, Confidence 0.489
Word: "up", Bounding polygon {{574,334},{580,334},{580,340},{573,340}}, Confidence 0.815
Line: "12:00 PM-1:00 PM", Bounding polygon {{537,340},{583,340},{583,347},{536,346}}
Word: "12:00", Bounding polygon {{539,341},{553,341},{552,347},{538,347}}, Confidence 0.826
Word: "PM-1:00", Bounding polygon {{554,341},{575,341},{574,347},{553,347}}, Confidence 0.209
Word: "PM", Bounding polygon {{576,341},{583,341},{582,347},{575,347}}, Confidence 0.039
Line: "Delle Marckre", Bounding polygon {{538,347},{582,347},{582,352},{538,353}}
Word: "Delle", Bounding polygon {{540,348},{559,347},{558,353},{539,353}}, Confidence 0.58
Word: "Marckre", Bounding polygon {{560,347},{582,348},{582,353},{559,353}}, Confidence 0.275
Line: "Product review", Bounding polygon {{538,370},{577,370},{577,376},{538,375}}
Word: "Product", Bounding polygon {{539,370},{559,371},{558,376},{539,376}}, Confidence 0.615
Word: "review", Bounding polygon {{560,371},{576,371},{575,376},{559,376}}, Confidence 0.04
Clean up resources
If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
Next steps
In this quickstart, you learned how to install the Image Analysis client SDK and make basic image analysis calls. Next, learn more about the Analysis 4.0 API features.
- Image Analysis overview
- Sample source code can be found on GitHub.
Use the Image Analysis client SDK for Java to analyze an image to read text and generate an image caption. This quickstart analyzes a remote image and prints the results to the console.
Reference documentation | Maven Package | Samples
Tip
The Analysis 4.0 API can do many different operations. See the Analyze Image how-to guide for examples that showcase all of the available features.
Prerequisites
- A Windows 10 (or higher) x64, or Linux x64 machine.
- Java Development Kit (JDK) version 8 or above installed, such as Azul Zulu OpenJDK, Microsoft Build of OpenJDK, Oracle Java, or your preferred JDK. Run
java -version
from a command line to see your version and confirm a successful installation. Make sure that the Java installation is native to the system architecture and not running through emulation. - Apache Maven installed. On Linux, install from the distribution repositories if available. Run
mvn -v
to confirm successful installation. - An Azure subscription - Create one for free
- Once you have your Azure subscription, create a Vision resource in the Azure portal. In order to use the captioning feature in this quickstart, you must create your resource in one of the following Azure regions: East US, France Central, Korea Central, North Europe, Southeast Asia, West Europe, West US. After it deploys, select Go to resource.
- You need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service.
- You can use the free pricing tier (
F0
) to try the service, and upgrade later to a paid tier for production.
Set up application
Open a console window and create a new folder for your quickstart application.
- Open a text editor and copy the following content to a new file. Save the file as
pom.xml
in your project directory<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>azure.ai.vision.imageanalysis.samples</groupId> <artifactId>image-analysis-quickstart</artifactId> <version>0.0</version> <dependencies> <!-- https://mvnrepository.com/artifact/com.azure/azure-ai-vision-imageanalysis --> <dependency> <groupId>com.azure</groupId> <artifactId>azure-ai-vision-imageanalysis</artifactId> <version>0.15.1-beta.1</version> </dependency> <!-- https://mvnrepository.com/artifact/com.azure/azure-core-http-netty --> <dependency> <groupId>com.azure</groupId> <artifactId>azure-core-http-netty</artifactId> <version>1.13.6</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>2.0.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>2.0.7</version> </dependency> </dependencies> </project>
- Install the SDK and dependencies by running the following in the project directory:
mvn clean dependency:copy-dependencies
- Once the operation succeeds, verify that the folders
target\dependency
were creating and they contain.jar
files.
For more information, see the SDK installation guide.
Create environment variables
In this example, write your credentials to environment variables on the local machine that runs the application.
Go to the Azure portal. If the resource you created in the Prerequisites section deployed successfully, select Go to resource under Next Steps. You can find your key and endpoint under Resource Management in the Keys and Endpoint page. Your resource key isn't the same as your Azure subscription ID.
Tip
Don't include the key directly in your code, and never post it publicly. See the Azure AI services security article for more authentication options like Azure Key Vault.
To set the environment variable for your key and endpoint, open a console window and follow the instructions for your operating system and development environment.
- To set the
VISION_KEY
environment variable, replaceyour-key
with one of the keys for your resource. - To set the
VISION_ENDPOINT
environment variable, replaceyour-endpoint
with the endpoint for your resource.
setx VISION_KEY your-key
setx VISION_ENDPOINT your-endpoint
After you add the environment variables, you may need to restart any running programs that will read the environment variables, including the console window.
Analyze Image
Open a text editor and copy the following content to a new file. Save the file as ImageAnalysis.java
import java.net.URL;
import java.util.EnumSet;
import com.azure.ai.vision.common.*;
import com.azure.ai.vision.imageanalysis.*;
public class ImageAnalysis {
public static void main(String[] args) {
try (
VisionServiceOptions serviceOptions = new VisionServiceOptions(
new URL(System.getenv("VISION_ENDPOINT")),
System.getenv("VISION_KEY"));
VisionSource imageSource = VisionSource.fromUrl(
new URL("https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png"));
ImageAnalysisOptions analysisOptions = new ImageAnalysisOptions()) {
analysisOptions.setFeatures(EnumSet.of(ImageAnalysisFeature.CAPTION, ImageAnalysisFeature.TEXT));
analysisOptions.setLanguage("en");
analysisOptions.setGenderNeutralCaption(true);
try (
ImageAnalyzer analyzer = new ImageAnalyzer(serviceOptions, imageSource, analysisOptions);
ImageAnalysisResult result = analyzer.analyze()) {
if (result.getReason() == ImageAnalysisResultReason.ANALYZED) {
if (result.getCaption() != null) {
System.out.println(" Caption:");
System.out.println(" \"" + result.getCaption().getContent() + "\", Confidence "
+ String.format("%.4f", result.getCaption().getConfidence()));
}
if (result.getText() != null) {
System.out.println(" Text:");
for (DetectedTextLine line : result.getText()) {
String pointsToString = "{" + String.join(",",
line.getBoundingPolygon().stream().map(Object::toString).toArray(String[]::new))
+ "}";
System.out.println(
" Line: '" + line.getContent() + "', Bounding polygon " + pointsToString);
for (DetectedTextWord word : line.getWords()) {
pointsToString = "{" + String.join(",",
word.getBoundingPolygon().stream().map(Object::toString).toArray(String[]::new))
+ "}";
System.out.println(
" Word: '" + word.getContent() + "', Bounding polygon " + pointsToString +
", Confidence " + String.format("%.4f", word.getConfidence()));
}
}
}
} else { // result.Reason == ImageAnalysisResultReason.Error
ImageAnalysisErrorDetails errorDetails = ImageAnalysisErrorDetails.fromResult(result);
System.out.println(" Analysis failed.");
System.out.println(" Error reason: " + errorDetails.getReason());
System.out.println(" Error code: " + errorDetails.getErrorCode());
System.out.println(" Error message: " + errorDetails.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Tip
The code shows analyzing an image URL. You can also analyze a local image file, or an image from a memory buffer. For more information, see the Analyze Image how-to guide.
To compile the Java file, run the following:
javac ImageAnalysis.java -cp ".;target\dependency\*"
You should see the file ImageAnalysis.class
created in the current folder.
To run the application:
java -cp ".;target\dependency\*" ImageAnalysis
Output
The console output should show something similar to the following text:
Caption:
"a person pointing at a screen", Confidence 0.4892
Text:
Line: '9:35 AM', Bounding polygon {{X=130,Y=129},{X=215,Y=130},{X=215,Y=149},{X=130,Y=148}}
Word: '9:35', Bounding polygon {{X=131,Y=130},{X=171,Y=130},{X=171,Y=149},{X=130,Y=149}}, Confidence 0.9930
Word: 'AM', Bounding polygon {{X=179,Y=130},{X=204,Y=130},{X=203,Y=149},{X=178,Y=149}}, Confidence 0.9980
Line: 'E Conference room 154584354', Bounding polygon {{X=130,Y=153},{X=224,Y=154},{X=224,Y=161},{X=130,Y=161}}
Word: 'E', Bounding polygon {{X=131,Y=154},{X=135,Y=154},{X=135,Y=161},{X=131,Y=161}}, Confidence 0.1040
Word: 'Conference', Bounding polygon {{X=142,Y=154},{X=174,Y=154},{X=173,Y=161},{X=141,Y=161}}, Confidence 0.9020
Word: 'room', Bounding polygon {{X=175,Y=154},{X=189,Y=155},{X=188,Y=161},{X=175,Y=161}}, Confidence 0.7960
Word: '154584354', Bounding polygon {{X=192,Y=155},{X=224,Y=154},{X=223,Y=162},{X=191,Y=161}}, Confidence 0.8640
Line: '#: 555-173-4547', Bounding polygon {{X=130,Y=163},{X=182,Y=164},{X=181,Y=171},{X=130,Y=170}}
Word: '#:', Bounding polygon {{X=131,Y=163},{X=139,Y=164},{X=139,Y=171},{X=131,Y=171}}, Confidence 0.0360
Word: '555-173-4547', Bounding polygon {{X=142,Y=164},{X=182,Y=165},{X=181,Y=171},{X=142,Y=171}}, Confidence 0.5970
Line: 'Town Hall', Bounding polygon {{X=546,Y=180},{X=590,Y=180},{X=590,Y=190},{X=546,Y=190}}
Word: 'Town', Bounding polygon {{X=547,Y=181},{X=568,Y=181},{X=568,Y=190},{X=546,Y=191}}, Confidence 0.9810
Word: 'Hall', Bounding polygon {{X=570,Y=181},{X=590,Y=181},{X=590,Y=191},{X=570,Y=190}}, Confidence 0.9910
Line: '9:00 AM - 10:00 AM', Bounding polygon {{X=546,Y=191},{X=596,Y=192},{X=596,Y=200},{X=546,Y=199}}
Word: '9:00', Bounding polygon {{X=546,Y=192},{X=555,Y=192},{X=555,Y=200},{X=546,Y=200}}, Confidence 0.0900
Word: 'AM', Bounding polygon {{X=557,Y=192},{X=565,Y=192},{X=565,Y=200},{X=557,Y=200}}, Confidence 0.9910
Word: '-', Bounding polygon {{X=567,Y=192},{X=569,Y=192},{X=569,Y=200},{X=567,Y=200}}, Confidence 0.6910
Word: '10:00', Bounding polygon {{X=570,Y=192},{X=585,Y=193},{X=584,Y=200},{X=570,Y=200}}, Confidence 0.8850
Word: 'AM', Bounding polygon {{X=586,Y=193},{X=593,Y=194},{X=593,Y=200},{X=586,Y=200}}, Confidence 0.9910
Line: 'Aaron Buaion', Bounding polygon {{X=543,Y=201},{X=581,Y=201},{X=581,Y=208},{X=543,Y=208}}
Word: 'Aaron', Bounding polygon {{X=545,Y=202},{X=560,Y=202},{X=559,Y=208},{X=544,Y=208}}, Confidence 0.6020
Word: 'Buaion', Bounding polygon {{X=561,Y=202},{X=580,Y=202},{X=579,Y=208},{X=560,Y=208}}, Confidence 0.2910
Line: 'Daily SCRUM', Bounding polygon {{X=537,Y=259},{X=575,Y=260},{X=575,Y=266},{X=537,Y=265}}
Word: 'Daily', Bounding polygon {{X=538,Y=259},{X=551,Y=260},{X=550,Y=266},{X=538,Y=265}}, Confidence 0.1750
Word: 'SCRUM', Bounding polygon {{X=552,Y=260},{X=570,Y=260},{X=570,Y=266},{X=551,Y=266}}, Confidence 0.1140
Line: '10:00 AM 11:00 AM', Bounding polygon {{X=536,Y=266},{X=590,Y=266},{X=590,Y=272},{X=536,Y=272}}
Word: '10:00', Bounding polygon {{X=539,Y=267},{X=553,Y=267},{X=552,Y=273},{X=538,Y=272}}, Confidence 0.8570
Word: 'AM', Bounding polygon {{X=554,Y=267},{X=561,Y=267},{X=560,Y=273},{X=553,Y=273}}, Confidence 0.9980
Word: '11:00', Bounding polygon {{X=564,Y=267},{X=578,Y=267},{X=577,Y=273},{X=563,Y=273}}, Confidence 0.4790
Word: 'AM', Bounding polygon {{X=579,Y=267},{X=586,Y=267},{X=585,Y=273},{X=578,Y=273}}, Confidence 0.9940
Line: 'Churlette de Crum', Bounding polygon {{X=538,Y=273},{X=584,Y=273},{X=585,Y=279},{X=538,Y=279}}
Word: 'Churlette', Bounding polygon {{X=539,Y=274},{X=562,Y=274},{X=561,Y=279},{X=538,Y=279}}, Confidence 0.4640
Word: 'de', Bounding polygon {{X=563,Y=274},{X=569,Y=274},{X=568,Y=279},{X=562,Y=279}}, Confidence 0.8100
Word: 'Crum', Bounding polygon {{X=570,Y=274},{X=582,Y=273},{X=581,Y=279},{X=569,Y=279}}, Confidence 0.8850
Line: 'Quarterly NI Hands', Bounding polygon {{X=538,Y=295},{X=588,Y=295},{X=588,Y=301},{X=538,Y=302}}
Word: 'Quarterly', Bounding polygon {{X=540,Y=296},{X=562,Y=296},{X=562,Y=302},{X=539,Y=302}}, Confidence 0.5230
Word: 'NI', Bounding polygon {{X=563,Y=296},{X=570,Y=296},{X=570,Y=302},{X=563,Y=302}}, Confidence 0.3030
Word: 'Hands', Bounding polygon {{X=572,Y=296},{X=588,Y=296},{X=588,Y=302},{X=571,Y=302}}, Confidence 0.6130
Line: '11.00 AM-12:00 PM', Bounding polygon {{X=536,Y=304},{X=588,Y=303},{X=588,Y=309},{X=536,Y=310}}
Word: '11.00', Bounding polygon {{X=538,Y=304},{X=552,Y=304},{X=552,Y=310},{X=538,Y=310}}, Confidence 0.6180
Word: 'AM-12:00', Bounding polygon {{X=554,Y=304},{X=578,Y=304},{X=577,Y=310},{X=553,Y=310}}, Confidence 0.2700
Word: 'PM', Bounding polygon {{X=579,Y=304},{X=586,Y=304},{X=586,Y=309},{X=578,Y=310}}, Confidence 0.6620
Line: 'Bebek Shaman', Bounding polygon {{X=538,Y=310},{X=577,Y=310},{X=577,Y=316},{X=538,Y=316}}
Word: 'Bebek', Bounding polygon {{X=539,Y=310},{X=554,Y=310},{X=554,Y=317},{X=539,Y=316}}, Confidence 0.6110
Word: 'Shaman', Bounding polygon {{X=555,Y=310},{X=576,Y=311},{X=576,Y=317},{X=555,Y=317}}, Confidence 0.6050
Line: 'Weekly stand up', Bounding polygon {{X=537,Y=332},{X=582,Y=333},{X=582,Y=339},{X=537,Y=338}}
Word: 'Weekly', Bounding polygon {{X=538,Y=332},{X=557,Y=333},{X=556,Y=339},{X=538,Y=338}}, Confidence 0.6060
Word: 'stand', Bounding polygon {{X=558,Y=333},{X=572,Y=334},{X=571,Y=340},{X=557,Y=339}}, Confidence 0.4890
Word: 'up', Bounding polygon {{X=574,Y=334},{X=580,Y=334},{X=580,Y=340},{X=573,Y=340}}, Confidence 0.8150
Line: '12:00 PM-1:00 PM', Bounding polygon {{X=537,Y=340},{X=583,Y=340},{X=583,Y=347},{X=536,Y=346}}
Word: '12:00', Bounding polygon {{X=539,Y=341},{X=553,Y=341},{X=552,Y=347},{X=538,Y=347}}, Confidence 0.8260
Word: 'PM-1:00', Bounding polygon {{X=554,Y=341},{X=575,Y=341},{X=574,Y=347},{X=553,Y=347}}, Confidence 0.2090
Word: 'PM', Bounding polygon {{X=576,Y=341},{X=583,Y=341},{X=582,Y=347},{X=575,Y=347}}, Confidence 0.0390
Line: 'Delle Marckre', Bounding polygon {{X=538,Y=347},{X=582,Y=347},{X=582,Y=352},{X=538,Y=353}}
Word: 'Delle', Bounding polygon {{X=540,Y=348},{X=559,Y=347},{X=558,Y=353},{X=539,Y=353}}, Confidence 0.5800
Word: 'Marckre', Bounding polygon {{X=560,Y=347},{X=582,Y=348},{X=582,Y=353},{X=559,Y=353}}, Confidence 0.2750
Line: 'Product review', Bounding polygon {{X=538,Y=370},{X=577,Y=370},{X=577,Y=376},{X=538,Y=375}}
Word: 'Product', Bounding polygon {{X=539,Y=370},{X=559,Y=371},{X=558,Y=376},{X=539,Y=376}}, Confidence 0.6150
Word: 'review', Bounding polygon {{X=560,Y=371},{X=576,Y=371},{X=575,Y=376},{X=559,Y=376}}, Confidence 0.0400
Clean up resources
If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.
Next steps
In this quickstart, you learned how to install the Image Analysis client SDK and make basic image analysis calls. Next, learn more about the Analysis 4.0 API features.
- Image Analysis overview
- Sample source code can be found on GitHub.
Use the Image Analysis REST API to read text and generate captions for the image (version 4.0 only).
Tip
The Analysis 4.0 API can do many different operations. See the Analyze Image how-to guide for examples that showcase all of the available features.
Prerequisites
- An Azure subscription - Create one for free
- Once you have your Azure subscription, create a Vision resource in the Azure portal to get your key and endpoint. In order to use the captioning feature in this quickstart, you must create your resource in one of the following Azure regions: East US, France Central, Korea Central, North Europe, Southeast Asia, West Europe, West US, East Asia. After it deploys, select Go to resource.
- You'll need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service. You'll paste your key and endpoint into the code below later in the quickstart.
- You can use the free pricing tier (
F0
) to try the service, and upgrade later to a paid tier for production.
- cURL installed
Analyze an image
To analyze an image for various visual features, do the following steps:
Copy the following
curl
command into a text editor.curl.exe -H "Ocp-Apim-Subscription-Key: <subscriptionKey>" -H "Content-Type: application/json" "https://<endpoint>/computervision/imageanalysis:analyze?features=caption,read&model-version=latest&language=en&api-version=2023-02-01-preview" -d "{'url':'https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png'}"
Make the following changes in the command where needed:
- Replace the value of
<subscriptionKey>
with your Vision resource key. - Replace the value of
<endpoint>
with your Vision resource endpoint. For example:https://YourResourceName.cognitiveservices.azure.com
. - Optionally, change the image URL in the request body (
https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png
) to the URL of a different image to be analyzed.
- Replace the value of
Open a command prompt window.
Paste your edited
curl
command from the text editor into the command prompt window, and then run the command.
Examine the response
A successful response is returned in JSON, similar to the following example:
{
"captionResult":
{
"text": "a man pointing at a screen",
"confidence": 0.4891590476036072
},
"modelVersion": "2023-02-01-preview",
"metadata":
{
"width": 1038,
"height": 692
},
"readResult":
{
"stringIndexType": "TextElements",
"content": "9:35 AM\nE Conference room 154584354\n#: 555-173-4547\nTown Hall\n9:00 AM - 10:00 AM\nAaron Buaion\nDaily SCRUM\n10:00 AM 11:00 AM\nChurlette de Crum\nQuarterly NI Hands\n11.00 AM-12:00 PM\nBebek Shaman\nWeekly stand up\n12:00 PM-1:00 PM\nDelle Marckre\nProduct review",
"pages":
[
{
"height": 692,
"width": 1038,
"angle": 0.3048,
"pageNumber": 1,
"words":
[
{"content":"9:35","boundingBox":[131,130,171,130,171,149,130,149],"confidence":0.993,"span":{"offset":0,"length":4}},
{"content":"AM","boundingBox":[179,130,204,130,203,149,178,149],"confidence":0.998,"span":{"offset":5,"length":2}},
{"content":"E","boundingBox":[131,154,135,154,135,161,131,161],"confidence":0.104,"span":{"offset":8,"length":1}},
{"content":"Conference","boundingBox":[142,154,174,154,173,161,141,161],"confidence":0.902,"span":{"offset":10,"length":10}},
{"content":"room","boundingBox":[175,154,189,155,188,161,175,161],"confidence":0.796,"span":{"offset":21,"length":4}},
{"content":"154584354","boundingBox":[192,155,224,154,223,162,191,161],"confidence":0.864,"span":{"offset":26,"length":9}},
{"content":"#:","boundingBox":[131,163,139,164,139,171,131,171],"confidence":0.036,"span":{"offset":36,"length":2}},
{"content":"555-173-4547","boundingBox":[142,164,182,165,181,171,142,171],"confidence":0.597,"span":{"offset":39,"length":12}},
{"content":"Town","boundingBox":[547,181,568,181,568,190,546,191],"confidence":0.981,"span":{"offset":52,"length":4}},
{"content":"Hall","boundingBox":[570,181,590,181,590,191,570,190],"confidence":0.991,"span":{"offset":57,"length":4}},
{"content":"9:00","boundingBox":[546,192,555,192,555,200,546,200],"confidence":0.09,"span":{"offset":62,"length":4}},
{"content":"AM","boundingBox":[557,192,565,192,565,200,557,200],"confidence":0.991,"span":{"offset":67,"length":2}},
{"content":"-","boundingBox":[567,192,569,192,569,200,567,200],"confidence":0.691,"span":{"offset":70,"length":1}},
{"content":"10:00","boundingBox":[570,192,585,193,584,200,570,200],"confidence":0.885,"span":{"offset":72,"length":5}},
{"content":"AM","boundingBox":[586,193,593,194,593,200,586,200],"confidence":0.991,"span":{"offset":78,"length":2}},
{"content":"Aaron","boundingBox":[545,202,560,202,559,208,544,208],"confidence":0.602,"span":{"offset":81,"length":5}},
{"content":"Buaion","boundingBox":[561,202,580,202,579,208,560,208],"confidence":0.291,"span":{"offset":87,"length":6}},
{"content":"Daily","boundingBox":[538,259,551,260,550,266,538,265],"confidence":0.175,"span":{"offset":94,"length":5}},
{"content":"SCRUM","boundingBox":[552,260,570,260,570,266,551,266],"confidence":0.114,"span":{"offset":100,"length":5}},
{"content":"10:00","boundingBox":[539,267,553,267,552,273,538,272],"confidence":0.857,"span":{"offset":106,"length":5}},
{"content":"AM","boundingBox":[554,267,561,267,560,273,553,273],"confidence":0.998,"span":{"offset":112,"length":2}},
{"content":"11:00","boundingBox":[564,267,578,267,577,273,563,273],"confidence":0.479,"span":{"offset":115,"length":5}},
{"content":"AM","boundingBox":[579,267,586,267,585,273,578,273],"confidence":0.994,"span":{"offset":121,"length":2}},
{"content":"Churlette","boundingBox":[539,274,562,274,561,279,538,279],"confidence":0.464,"span":{"offset":124,"length":9}},
{"content":"de","boundingBox":[563,274,569,274,568,279,562,279],"confidence":0.81,"span":{"offset":134,"length":2}},
{"content":"Crum","boundingBox":[570,274,582,273,581,279,569,279],"confidence":0.885,"span":{"offset":137,"length":4}},
{"content":"Quarterly","boundingBox":[540,296,562,296,562,302,539,302],"confidence":0.523,"span":{"offset":142,"length":9}},
{"content":"NI","boundingBox":[563,296,570,296,570,302,563,302],"confidence":0.303,"span":{"offset":152,"length":2}},
{"content":"Hands","boundingBox":[572,296,588,296,588,302,571,302],"confidence":0.613,"span":{"offset":155,"length":5}},
{"content":"11.00","boundingBox":[538,304,552,304,552,310,538,310],"confidence":0.618,"span":{"offset":161,"length":5}},
{"content":"AM-12:00","boundingBox":[554,304,578,304,577,310,553,310],"confidence":0.27,"span":{"offset":167,"length":8}},
{"content":"PM","boundingBox":[579,304,586,304,586,309,578,310],"confidence":0.662,"span":{"offset":176,"length":2}},
{"content":"Bebek","boundingBox":[539,310,554,310,554,317,539,316],"confidence":0.611,"span":{"offset":179,"length":5}},
{"content":"Shaman","boundingBox":[555,310,576,311,576,317,555,317],"confidence":0.605,"span":{"offset":185,"length":6}},
{"content":"Weekly","boundingBox":[538,332,557,333,556,339,538,338],"confidence":0.606,"span":{"offset":192,"length":6}},
{"content":"stand","boundingBox":[558,333,572,334,571,340,557,339],"confidence":0.489,"span":{"offset":199,"length":5}},
{"content":"up","boundingBox":[574,334,580,334,580,340,573,340],"confidence":0.815,"span":{"offset":205,"length":2}},
{"content":"12:00","boundingBox":[539,341,553,341,552,347,538,347],"confidence":0.826,"span":{"offset":208,"length":5}},
{"content":"PM-1:00","boundingBox":[554,341,575,341,574,347,553,347],"confidence":0.209,"span":{"offset":214,"length":7}},
{"content":"PM","boundingBox":[576,341,583,341,582,347,575,347],"confidence":0.039,"span":{"offset":222,"length":2}},
{"content":"Delle","boundingBox":[540,348,559,347,558,353,539,353],"confidence":0.58,"span":{"offset":225,"length":5}},
{"content":"Marckre","boundingBox":[560,347,582,348,582,353,559,353],"confidence":0.275,"span":{"offset":231,"length":7}},
{"content":"Product","boundingBox":[539,370,559,371,558,376,539,376],"confidence":0.615,"span":{"offset":239,"length":7}},
{"content":"review","boundingBox":[560,371,576,371,575,376,559,376],"confidence":0.04,"span":{"offset":247,"length":6}}
],
"spans":
[
{"offset":0,"length":253}
],
"lines":
[
{"content":"9:35 AM","boundingBox":[130,129,215,130,215,149,130,148],"spans":[{"offset":0,"length":7}]},
{"content":"E Conference room 154584354","boundingBox":[130,153,224,154,224,161,130,161],"spans":[{"offset":8,"length":27}]},
{"content":"#: 555-173-4547","boundingBox":[130,163,182,164,181,171,130,170],"spans":[{"offset":36,"length":15}]},
{"content":"Town Hall","boundingBox":[546,180,590,180,590,190,546,190],"spans":[{"offset":52,"length":9}]},
{"content":"9:00 AM - 10:00 AM","boundingBox":[546,191,596,192,596,200,546,199],"spans":[{"offset":62,"length":18}]},
{"content":"Aaron Buaion","boundingBox":[543,201,581,201,581,208,543,208],"spans":[{"offset":81,"length":12}]},
{"content":"Daily SCRUM","boundingBox":[537,259,575,260,575,266,537,265],"spans":[{"offset":94,"length":11}]},
{"content":"10:00 AM 11:00 AM","boundingBox":[536,266,590,266,590,272,536,272],"spans":[{"offset":106,"length":17}]},
{"content":"Churlette de Crum","boundingBox":[538,273,584,273,585,279,538,279],"spans":[{"offset":124,"length":17}]},
{"content":"Quarterly NI Hands","boundingBox":[538,295,588,295,588,301,538,302],"spans":[{"offset":142,"length":18}]},
{"content":"11.00 AM-12:00 PM","boundingBox":[536,304,588,303,588,309,536,310],"spans":[{"offset":161,"length":17}]},
{"content":"Bebek Shaman","boundingBox":[538,310,577,310,577,316,538,316],"spans":[{"offset":179,"length":12}]},
{"content":"Weekly stand up","boundingBox":[537,332,582,333,582,339,537,338],"spans":[{"offset":192,"length":15}]},
{"content":"12:00 PM-1:00 PM","boundingBox":[537,340,583,340,583,347,536,346],"spans":[{"offset":208,"length":16}]},
{"content":"Delle Marckre","boundingBox":[538,347,582,347,582,352,538,353],"spans":[{"offset":225,"length":13}]},
{"content":"Product review","boundingBox":[538,370,577,370,577,376,538,375],"spans":[{"offset":239,"length":14}]}
]
}
],
"styles": [],
"modelVersion": "2022-04-30"
}
}
Next steps
In this quickstart, you learned how to make basic image analysis calls using the REST API. Next, learn more about the Analysis 4.0 API features.
Feedback
Submit and view feedback for