Skip to content

Commit 516596d

Browse files
Merge pull request #249512 from PatrickFarley/comvis-tut
[ai-svcs] update for latest comvis sdk
2 parents cdf63ef + de5954d commit 516596d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

articles/ai-services/computer-vision/Tutorials/storage-lab-tutorial.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ Navigate to the *Web.config* file at the root of the project. Add the following
403403
<add key="VisionEndpoint" value="VISION_ENDPOINT" />
404404
```
405405

406-
Then in the Solution Explorer, right-click the project and use the **Manage NuGet Packages** command to install the package **Microsoft.Azure.CognitiveServices.Vision.ComputerVision**. This package contains the types needed to call the Azure AI Vision API.
406+
In the Solution Explorer. right-click on the project solution and select **Manage NuGet Packages**. In the package manager that opens select **Browse**, check **Include prerelease**, and search for **Azure.AI.Vision.ImageAnalysis**. Select **Install**.
407407

408408
### Add metadata generation code
409409

@@ -412,29 +412,38 @@ Next, you'll add the code that actually uses the Azure AI Vision service to crea
412412
1. Open the *HomeController.cs* file in the project's **Controllers** folder and add the following `using` statements at the top of the file:
413413

414414
```csharp
415-
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
416-
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
415+
using Azure.AI.Vision.Common;
416+
using Azure.AI.Vision.ImageAnalysis;
417417
```
418418

419419
1. Then, go to the **Upload** method; this method converts and uploads images to blob storage. Add the following code immediately after the block that begins with `// Generate a thumbnail` (or at the end of your image-blob-creation process). This code takes the blob containing the image (`photo`), and uses Azure AI Vision to generate a description for that image. The Azure AI Vision API also generates a list of keywords that apply to the image. The generated description and keywords are stored in the blob's metadata so that they can be retrieved later on.
420420
421421
```csharp
422422
// Submit the image to the Azure AI Vision API
423-
ComputerVisionClient vision = new ComputerVisionClient(
424-
new ApiKeyServiceClientCredentials(ConfigurationManager.AppSettings["SubscriptionKey"]),
425-
new System.Net.Http.DelegatingHandler[] { });
426-
vision.Endpoint = ConfigurationManager.AppSettings["VisionEndpoint"];
423+
var serviceOptions = new VisionServiceOptions(
424+
Environment.GetEnvironmentVariable(ConfigurationManager.AppSettings["VisionEndpoint"]),
425+
new AzureKeyCredential(ConfigurationManager.AppSettings["SubscriptionKey"]));
427426

428-
List<VisualFeatureTypes?> features = new List<VisualFeatureTypes?>() { VisualFeatureTypes.Description };
429-
var result = await vision.AnalyzeImageAsync(photo.Uri.ToString(), features);
427+
var analysisOptions = new ImageAnalysisOptions()
428+
{
429+
Features = ImageAnalysisFeature.Caption | ImageAnalysisFeature.Tags,
430+
Language = "en",
431+
GenderNeutralCaption = true
432+
};
433+
434+
using var imageSource = VisionSource.FromUrl(
435+
new Uri(photo.Uri.ToString()));
436+
437+
using var analyzer = new ImageAnalyzer(serviceOptions, imageSource, analysisOptions);
438+
var result = analyzer.Analyze();
430439

431440
// Record the image description and tags in blob metadata
432-
photo.Metadata.Add("Caption", result.Description.Captions[0].Text);
441+
photo.Metadata.Add("Caption", result.Caption.ContentCaption.Content);
433442

434-
for (int i = 0; i < result.Description.Tags.Count; i++)
443+
for (int i = 0; i < result.Tags.ContentTags.Count; i++)
435444
{
436445
string key = String.Format("Tag{0}", i);
437-
photo.Metadata.Add(key, result.Description.Tags[i]);
446+
photo.Metadata.Add(key, result.Tags.ContentTags[i]);
438447
}
439448

440449
await photo.SetMetadataAsync();

0 commit comments

Comments
 (0)