public CropHintsAnnotationModel(CropHintsAnnotation cropHintsAnnotation) { CropHints = new List <CropHintModel>(); foreach (var cropHint in cropHintsAnnotation.CropHints) { CropHints.Add(new CropHintModel(cropHint)); } }
public void DetectCropHints() { Image image = LoadResourceImage("Gladiolos.jpg"); // Snippet: DetectCropHints ImageAnnotatorClient client = ImageAnnotatorClient.Create(); CropHintsAnnotation cropHints = client.DetectCropHints(image); foreach (CropHint hint in cropHints.CropHints) { Console.WriteLine("Crop hint:"); string poly = string.Join(" - ", hint.BoundingPoly.Vertices.Select(v => $"({v.X}, {v.Y})")); Console.WriteLine($" Poly: {poly}"); Console.WriteLine($" Confidence: {hint.Confidence}"); Console.WriteLine($" Importance fraction: {hint.ImportanceFraction}"); } // End snippet Assert.Equal(1, cropHints.CropHints.Count); }
private static object DetectCropHint(Image image) { // [START vision_crop_hint_detection] var client = ImageAnnotatorClient.Create(); CropHintsAnnotation annotation = client.DetectCropHints(image); foreach (CropHint hint in annotation.CropHints) { Console.WriteLine("Confidence: {0}", hint.Confidence); Console.WriteLine("ImportanceFraction: {0}", hint.ImportanceFraction); Console.WriteLine("Bounding Polygon:"); foreach (Vertex vertex in hint.BoundingPoly.Vertices) { Console.WriteLine("\tX:\t{0}\tY:\t{1}", vertex.X, vertex.Y); } } // [END vision_crop_hint_detection] return(0); }
public Annotations SendRequest(string imagePath) { var imageArray = File.ReadAllBytes(imagePath); var imageContent = Convert.ToBase64String(imageArray); var responses = _visionService.Images.Annotate(new BatchAnnotateImagesRequest() { Requests = new[] { new AnnotateImageRequest() { Features = new[] { new Feature() { Type = DetectionTypes.LabelDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.TextDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.LandmarkDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.LogoDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.FaceDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.SafeSearchDetection, MaxResults = _maxResults }, new Feature() { Type = DetectionTypes.ImageProperties, MaxResults = _maxResults }, }, Image = new Image() { Content = imageContent } } } }).Execute(); var labelAnnotations = new List <EntityAnnotation>(); var textAnnotations = new List <EntityAnnotation>(); var landmarkAnnotations = new List <EntityAnnotation>(); var logoAnnotations = new List <EntityAnnotation>(); var faceAnnotations = new List <FaceAnnotation>(); var safeSearchAnnotation = new SafeSearchAnnotation(); var imageProperties = new ImageProperties(); var webDetection = new WebDetection(); var cropHints = new CropHintsAnnotation(); foreach (var response in responses.Responses) { if (response.LabelAnnotations != null) { foreach (var labelAnnotation in response.LabelAnnotations) { labelAnnotations.Add(labelAnnotation); } } if (response.LandmarkAnnotations != null) { foreach (var landmarkAnnotation in response.LandmarkAnnotations) { landmarkAnnotations.Add(landmarkAnnotation); } } if (response.LogoAnnotations != null) { foreach (var logoAnnotation in response.LogoAnnotations) { logoAnnotations.Add(logoAnnotation); } } if (response.TextAnnotations != null) { foreach (var textAnnotation in response.TextAnnotations) { textAnnotations.Add(textAnnotation); } } if (response.FaceAnnotations != null) { foreach (var faceAnnotation in response.FaceAnnotations) { faceAnnotations.Add(faceAnnotation); } } if (response.WebDetection != null) { webDetection = response.WebDetection; } if (response.CropHintsAnnotation != null) { cropHints = response.CropHintsAnnotation; } if (response.SafeSearchAnnotation != null) { safeSearchAnnotation = response.SafeSearchAnnotation; } if (response.ImagePropertiesAnnotation != null) { imageProperties = response.ImagePropertiesAnnotation; } } return(new Annotations(labelAnnotations, textAnnotations, logoAnnotations, landmarkAnnotations, faceAnnotations, safeSearchAnnotation, imageProperties, webDetection, cropHints)); }
public Annotations(IList <EntityAnnotation> labelAnnotations, IList <EntityAnnotation> textAnnotations, IList <EntityAnnotation> logoAnnotations, IList <EntityAnnotation> landmarkAnnotations, IList <FaceAnnotation> faceAnnotations, SafeSearchAnnotation safeSearchAnnotation, ImageProperties imageProperties, WebDetection webDetection, CropHintsAnnotation cropHintsAnnoation) { Labels = new List <EntityAnnotationModel>(); Text = new List <EntityAnnotationModel>(); Logos = new List <EntityAnnotationModel>(); Landmarks = new List <EntityAnnotationModel>(); Faces = new List <FaceAnnotationModel>(); SafeSearch = new SafeSearchModel(safeSearchAnnotation); ImageProperties = new ImagePropertiesModel(imageProperties); WebDetections = new WebDetectionModel(webDetection); CropHints = new CropHintsAnnotationModel(cropHintsAnnoation); foreach (var labelAnnotation in labelAnnotations) { Labels.Add(new EntityAnnotationModel(labelAnnotation)); } foreach (var textAnnotation in textAnnotations) { Text.Add(new EntityAnnotationModel(textAnnotation)); } foreach (var logoAnnotation in logoAnnotations) { Logos.Add(new EntityAnnotationModel(logoAnnotation)); } foreach (var landmarkAnnotation in landmarkAnnotations) { Landmarks.Add(new EntityAnnotationModel(landmarkAnnotation)); } foreach (var faceAnnotation in faceAnnotations) { Faces.Add(new FaceAnnotationModel(faceAnnotation)); } }