Introduction
Microsoft Cognitive services is set of cloud-based intelligence APIs for building richer and smarter application development. Cognitive API will use for Search meta data from Photos and video and emotions, sentiment analysis and authenticating speakers via voice verification.

The Computer Vision API will help developers to identify the objects with access to advanced algorithms for processing images and returning image meta data information. In this article, you will learn about Computer Vision API and how to implement Compute Vision API into Bot application.
You can follow below steps for implement object detection in Bot Application
Computer Vision API Key Creation
Computer Vision API returns information about visual content found in an image. You can follow the below steps for creating Vision API key.
- Navigate to https://azure.microsoft.com/en-us/try/cognitive-services/

- Click on “Get API Key “or Login with Azure login.
- Login with Microsoft Account and Get API key

- Copy API key and store securely, we will use this API key into our application
Step 2 Create New Bot Application
Let's create a new bot application using Visual Studio 2017. Open Visual Studio > Select File > Create New Project (Ctrl + Shift +N) > Select Bot application.

The Bot application template gets created with all the components and all required NuGet references installed in the solutions.

In this solution, we are going edit Messagecontroller and add Service class.
Install Microsoft.ProjectOxford.Vision Nuget Package
The Microsoft project oxford vision nuget package will help with access to cognitive service so Install “Microsoft.ProjectOxford.Vision” Library from the solution

Create Vision Service
Create a new helper class to the project called VisionService that wraps around the functionality from the VisionServiceClient from Cognitive Services and only returns what we currently need.
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web;
- using Microsoft.ProjectOxford.Vision;
- using Microsoft.ProjectOxford.Vision.Contract;
- namespace BotObjectDetection.Service
- {
- public class VisionService : ICaptionService
- {
- /// <summary>
- /// Microsoft Computer Vision API key.
- /// </summary>
- private static readonly string ApiKey = "<API Key>";
- /// <summary>
- /// The set of visual features we want from the Vision API.
- /// </summary>
- private static readonly VisualFeature[] VisualFeatures = { VisualFeature.Description };
- public async Task<string> GetCaptionAsync(string url)
- {
- var client = new VisionServiceClient(ApiKey);
- var result = await client.AnalyzeImageAsync(url, VisualFeatures);
- return ProcessAnalysisResult(result);
- }
- public async Task<string> GetCaptionAsync(Stream stream)
- {
- var client = new VisionServiceClient(ApiKey);
- var result = await client.AnalyzeImageAsync(stream, VisualFeatures);
- return ProcessAnalysisResult(result);
- }
- /// <summary>
- /// Processes the analysis result.
- /// </summary>
- /// <param name="result">The result.</param>
- /// <returns>The caption if found, error message otherwise.</returns>
- private static string ProcessAnalysisResult(AnalysisResult result)
- {
- string message = result?.Description?.Captions.FirstOrDefault()?.Text;
- return string.IsNullOrEmpty(message) ?
- "Couldn't find a caption for this one" :
- "I think it's " + message;
- }
- }
- }
In the above helper class, replace vision API key and call the Analyze image client method for identify image meta data
Messages Controller
MessagesController is created by default and it is the main entry point of the application. it will call our helper service class which will handle the interaction with the Microsoft APIs. You can update “Post” method like below



giri KPosted Nov 16, 2018, 9:35 AM
Where is the IcaptionServiceClass??
Rungson SongsermPosted Jul 19, 2018, 2:26 AM
VisionService.cs replace var client = new VisionServiceClient(ApiKey); with var client = new VisionServiceClient(ApiKey, "https://southeastasia.api.cognitive.microsoft.com/vision/v1.0"); ** https://southeastasia.api.cognitive.microsoft.com/vision/v1.0 ** is endpoint of your compute vision api
Jonathan NunezPosted Apr 17, 2018, 11:08 AM
There are a lot of errors. Where is the ICaptionImage class?