/// <summary> /// Uploads the image to Cognitive Services and generates a bounding rectangle representing the area of interest. /// </summary> /// <param name="imageFilePath">The image file path.</param> /// <returns>Awaitable AreaOfInterest result.</returns> private async Task <AreaOfInterestResult> UploadAndGenerateImageAreaOfInterestAsync(string imageFilePath) { // ----------------------------------------------------------------------- // KEY SAMPLE CODE STARTS HERE // ----------------------------------------------------------------------- // // Create Cognitive Services Vision API Service client. // using (var client = new ComputerVisionClient(Credentials) { Endpoint = Endpoint }) { Log("ComputerVisionClient is created"); using (Stream imageFileStream = File.OpenRead(imageFilePath)) { // // Upload an image and generate the area of interest. // Log("Calling ComputerVisionClient.GetAreaOfInterestInStreamAsync()..."); return(await client.GetAreaOfInterestInStreamAsync(imageFileStream)); } } // ----------------------------------------------------------------------- // KEY SAMPLE CODE ENDS HERE // ----------------------------------------------------------------------- }
// Analyze a local image private static async Task GetAreaOfInterestFromStreamAsync(ComputerVisionClient computerVision, string imagePath) { if (!File.Exists(imagePath)) { Console.WriteLine("\nUnable to open or read local image path:\n{0} \n", imagePath); return; } using (Stream imageStream = File.OpenRead(imagePath)) { AreaOfInterestResult analysis = await computerVision.GetAreaOfInterestInStreamAsync(imageStream); Console.WriteLine(imagePath); DisplayAreaOfInterest(analysis); } }
private Task <AreaOfInterestResult> ComputerVisionGetAreaOfInterestByStreamAsync(Stream imageStream) { return(_computerVisionClient.GetAreaOfInterestInStreamAsync(imageStream)); }