Esempio n. 1
0
        public IList <FaceAnnotation> detectFaces(string path, int maxResults)
        {
            byte[] data = File.ReadAllBytes(path);

            AnnotateImageRequest request = new AnnotateImageRequest();

            Google.Apis.Vision.v1.Data.Image img = new Google.Apis.Vision.v1.Data.Image();
            img.Content   = Convert.ToBase64String(data);
            request.Image = img;

            Feature feature = new Feature();

            feature.Type       = "FACE_DETECTION";
            feature.MaxResults = maxResults;

            request.Features = new List <Feature>()
            {
                feature
            };



            BatchAnnotateImagesRequest batchAnnotate = new BatchAnnotateImagesRequest();

            batchAnnotate.Requests = new List <AnnotateImageRequest>()
            {
                request
            };
            ImagesResource.AnnotateRequest annotate = _vision.Images.Annotate(batchAnnotate);

            BatchAnnotateImagesResponse batchResponse = annotate.Execute();

            AnnotateImageResponse response = batchResponse.Responses[0];

            if (response.FaceAnnotations == null)
            {
                throw new Exception(response.Error.Message);
            }

            return(response.FaceAnnotations);
        }
Esempio n. 2
0
        private static Boolean checkVision(byte[] imageByteArray)
        {
            string base64String = Convert.ToBase64String(imageByteArray);

            var visionService = CreateAuthorizedClient(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\IMF third year project-46cd5c28569b.json");


            Google.Apis.Vision.v1.Data.BatchAnnotateImagesRequest content = new Google.Apis.Vision.v1.Data.BatchAnnotateImagesRequest();

            content.Requests = new List <AnnotateImageRequest>();
            AnnotateImageRequest newRequest = new AnnotateImageRequest();

            newRequest.Image         = new Google.Apis.Vision.v1.Data.Image();
            newRequest.Image.Content = base64String;
            newRequest.Features      = new List <Feature>();
            newRequest.Features.Add(new Feature()
            {
                Type = "SAFE_SEARCH_DETECTION"
            });
            content.Requests.Add(newRequest);

            ImagesResource.AnnotateRequest request = visionService.Images.Annotate(content);
            Google.Apis.Vision.v1.Data.BatchAnnotateImagesResponse response = request.Execute();

            if (response.Responses.Count > 0)
            {
                string tempAdult = response.Responses[0].SafeSearchAnnotation.Adult.ToString();
                string tempSpoof = response.Responses[0].SafeSearchAnnotation.Spoof.ToString();
                if (tempAdult.Equals("LIKELY") || tempAdult.Equals("VERY_LIKELY"))
                {
                    return(false);
                }
                if (tempSpoof.Equals("LIKELY") || tempSpoof.Equals("VERY_LIKELY"))
                {
                    return(false);
                }
            }
            return(true);
        }