public void AnalyzeImageTest() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { HttpMockServer.Initialize(this.GetType().FullName, "AnalyzeImageTest"); using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance())) { ImageAnalysis result = client.AnalyzeImageAsync( GetTestImageUrl("house.jpg"), new List <VisualFeatureTypes>() { VisualFeatureTypes.Adult, VisualFeatureTypes.Categories, VisualFeatureTypes.Color, VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType, VisualFeatureTypes.Tags }) .Result; Assert.Equal("grass", result.Tags[0].Name); Assert.True(result.Tags[0].Confidence > 0.9); Assert.Equal("Jpeg", result.Metadata.Format); Assert.False(result.Adult.IsAdultContent); Assert.False(result.Adult.IsRacyContent); Assert.True(result.Adult.AdultScore < 0.1); Assert.True(result.Adult.RacyScore < 0.1); Assert.Equal("building_", result.Categories[0].Name); Assert.True(result.Categories[0].Score > 0.5); Assert.Equal("Green", result.Color.DominantColorBackground); Assert.Equal("Green", result.Color.DominantColorForeground); } } }
public void AnalyzeImageInvalidUrlTest() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "AnalyzeImageInvalidUrlTest"); using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance())) { try { ImageAnalysis result = client.AnalyzeImageAsync( "https://invalidurl", new List <VisualFeatureTypes?>() { VisualFeatureTypes.Categories }) .Result; } catch (Exception ex) when(ex.InnerException is ComputerVisionErrorResponseException cverex) { Assert.Equal("InvalidImageUrl", cverex.Body.Error.Innererror.Code); } } } }
public void AnalyzeImageNullImageTest() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "AnalyzeImageNullImageTest"); using (IComputerVisionClient client = GetComputerVisionClient(HttpMockServer.CreateInstance())) { Assert.ThrowsAsync <ValidationException>(() => client.AnalyzeImageAsync(null)); } } }
public async Task <Result <ImageAnalysis, Error> > AnalyzeFaces(string imageUrl, List <VisualFeatureTypes> features) { if (!Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute)) { return(Error(UnknownError("Badly formed url"))); } var analysis = await ImageAnalysisClient.AnalyzeImageAsync(imageUrl, features); Logger.LogWarning("Response: {@analysis}", analysis); return(Ok(analysis)); }
private static async Task <ImageAnalysis> AnalyzeAsync(IComputerVisionClient computerVision, string imageUrl, ILogger log) { if (!Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute)) { log.LogError( "Invalid remoteImageUrl: {0}", imageUrl); return(null); } ImageAnalysis analysis = await computerVision.AnalyzeImageAsync(imageUrl, Features); return(analysis); }
public async Task <ImageAnalysis> AnalyzePhoto(string imageUrl) { var uri = new Uri(imageUrl); if (PhotoNeedsToBeDownloaded(uri)) { return(await DownloadAndAnalyzePhoto(uri)); } else { var analysis = await _computerVisionClient.AnalyzeImageAsync( imageUrl, AnalysisFeatures); return(analysis); } }
public async Task <ImageAnalysis> AnalyzeImageFromUrlAsync(string url) { return(await _computerVisionClient.AnalyzeImageAsync(url, VisualFeatures)); }