// Analyze a remote image private static async Task DetectObjectsFromUrlAsync(ComputerVisionClient computerVision, string imageUrl) { if (!Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute)) { Console.WriteLine("\nInvalid remote image url:\n{0} \n", imageUrl); return; } DetectResult analysis = await computerVision.DetectObjectsAsync(imageUrl); Console.WriteLine(imageUrl); DisplayObjects(analysis); }
/* * DETECT OBJECTS - URL IMAGE */ public static async Task <DetectResult> DetectObjectsUrl(ComputerVisionClient client, string urlImage) { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("DETECT OBJECTS - URL IMAGE"); Console.WriteLine(); Console.WriteLine($"Detecting objects in URL image {Path.GetFileName(urlImage)}..."); Console.WriteLine(); // Detect the objects DetectResult detectObjectAnalysis = await client.DetectObjectsAsync(urlImage); // For each detected object in the picture, print out the bounding object detected, confidence of that detection and bounding box within the image Console.WriteLine("Detected objects:"); Console.WriteLine(); return(detectObjectAnalysis); }
/* * END - ANALYZE IMAGE - LOCAL IMAGE */ /* * DETECT OBJECTS - URL IMAGE */ public async Task DetectObjectsUrl(string urlImage) { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("DETECT OBJECTS - URL IMAGE"); Console.WriteLine(); Console.WriteLine($"Detecting objects in URL image {Path.GetFileName(urlImage)}..."); Console.WriteLine(); // Detect the objects DetectResult detectObjectAnalysis = await _computerVisionClient.DetectObjectsAsync(urlImage); // For each detected object in the picture, print out the bounding object detected, confidence of that detection and bounding box within the image Console.WriteLine("Detected objects:"); foreach (var obj in detectObjectAnalysis.Objects) { Console.WriteLine($"{obj.ObjectProperty} with confidence {obj.Confidence} at location {obj.Rectangle.X}, " + $"{obj.Rectangle.X + obj.Rectangle.W}, {obj.Rectangle.Y}, {obj.Rectangle.Y + obj.Rectangle.H}"); } Console.WriteLine(); }