public IReadOnlyList <LocalizedObjectAnnotation> GetLocalizedObjectAnnotationsResponse(Image image) { if (image == null) { throw new ArgumentNullException(); } var localizedObjectDetectionResponse = _imageAnnotatorClient.DetectLocalizedObjects(image); return(localizedObjectDetectionResponse); }
public void DetectLocalizedObjects() { Image image = Image.FromUri("https://cloud.google.com/vision/docs/images/bicycle_example.png"); // Snippet: DetectLocalizedObjects ImageAnnotatorClient client = ImageAnnotatorClient.Create(); IReadOnlyList <LocalizedObjectAnnotation> annotations = client.DetectLocalizedObjects(image); foreach (LocalizedObjectAnnotation annotation in annotations) { string poly = string.Join(" - ", annotation.BoundingPoly.Vertices.Select(v => $"({v.X}, {v.Y})")); Console.WriteLine( $"Name: {annotation.Name}; ID: {annotation.Mid}; Score: {annotation.Score}; Bounding poly: {poly}"); } // End snippet // TODO: Add assertions about the annotations. }
public void DetectLocalizedObjects() { Image image = Image.FromUri("https://cloud.google.com/vision/docs/images/bicycle_example.png"); // Snippet: DetectLocalizedObjects ImageAnnotatorClient client = ImageAnnotatorClient.Create(); IReadOnlyList <LocalizedObjectAnnotation> annotations = client.DetectLocalizedObjects(image); foreach (LocalizedObjectAnnotation annotation in annotations) { string poly = string.Join(" - ", annotation.BoundingPoly.NormalizedVertices.Select(v => $"({v.X}, {v.Y})")); Console.WriteLine( $"Name: {annotation.Name}; ID: {annotation.Mid}; Score: {annotation.Score}; Bounding poly: {poly}"); } // End snippet // We don't want to be too strict about what we get back here, but these should be okay. Assert.Contains(annotations, a => a.Name == "Bicycle"); Assert.Contains(annotations, a => a.Name == "Picture frame"); }