예제 #1
0
        internal async void CreateClassifyRequest(ClassifyTaskModel[] tasks)
        {
            if (tasks == null || tasks.Length == 0 || tasks.Length > 8)
            {
                throw new ArgumentException($"Illegal arguments count in batch. min is 1 max is 8");
            }



            foreach (ClassifyTaskModel t in tasks)
            {
                Image img = new Image()
                {
                    // ImageType = Enum.Parse(Image.Types.ImageType, t.ImageType)
                };

                AnnotationRequest analyzeRequest = new AnnotationRequest()
                {
                    Image = img
                };

                // analyzeRequest.AnalyzeSpecs.Add(makeAnalyzeSpec(t));
            }

            /*var call = await visionRpctClient.BatchAnalyzeAsync(
             *  request: analyzeRequest,
             *  headers: MakeMetadata(),
             *  deadline: DateTime.UtcNow.AddMinutes(5)
             * );*/
        }
        public async Task <ActionResult <AnnotationResponse> > Annotations([FromBody] AnnotationRequest request)
        {
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            var requestJson = JsonConvert.SerializeObject(request);

            _logger.LogInformation(requestJson);
            var response = new AnnotationResponse();

            return(Ok(response));
        }
예제 #3
0
 public virtual Task <List <AnnotationResponse> > Annotations(AnnotationRequest request, CancellationToken cancellationToken)
 {
     return(DataSource?.Annotations(request, cancellationToken) ?? Task.FromResult(new List <AnnotationResponse>()));
 }
예제 #4
0
        public async Task <RecognitionResult.Face[]> DetectEmotions(FaceCropResult.Face[] faces)
        {
            AnnotationRequest request = new AnnotationRequest();

            request.Requests = new AnnotationRequest.AnnotateImageRequest[faces.Length];

            for (int i = 0; i < faces.Length; i++)
            {
                FaceCropResult.Face face = faces[i];

                var r = new AnnotationRequest.AnnotateImageRequest
                {
                    ImageData = new AnnotationRequest.AnnotateImageRequest.Image
                    {
                        Content = face.ImageBase64
                    },
                    Features = new AnnotationRequest.AnnotateImageRequest.Feature[]
                    {
                        new AnnotationRequest.AnnotateImageRequest.Feature
                        {
                            Type       = "FACE_DETECTION",
                            MaxResults = 5
                        }
                    }
                };

                request.Requests[i] = r;
            }

            try
            {
                HttpClient  client  = new HttpClient();
                HttpContent content = new StringContent(JsonConvert.SerializeObject(request));

                var httpResponse = await client.PostAsync("https://vision.googleapis.com/v1/images:annotate?key=" + _apiKey, content);

                string responseData = await httpResponse.Content.ReadAsStringAsync();

                if (httpResponse.IsSuccessStatusCode)
                {
                    AnnotationResponse response = JsonConvert.DeserializeObject <AnnotationResponse>(responseData);

                    List <RecognitionResult.Face> faceResults = new List <RecognitionResult.Face>();

                    for (int i = 0; i < response.Responses.Length && i < faces.Length; i++)
                    {
                        AnnotationResponse.AnnotateImageResponse.FaceAnnotations faceAnnotations = response.Responses[i].FaceAnnotationData[0];
                        RecognitionResult.Face faceResult = new RecognitionResult.Face
                        {
                            Emotion = new RecognitionResult.Emotion
                            {
                                Anger     = FromLikelyhood(faceAnnotations.Anger),
                                Happiness = FromLikelyhood(faceAnnotations.Joy),
                                Neutral   = 0.0,
                                Sadness   = FromLikelyhood(faceAnnotations.Sorrow),
                                Surprise  = FromLikelyhood(faceAnnotations.Surprise)
                            }
                        };

                        faceResults.Add(faceResult);
                    }

                    return(faceResults.ToArray());
                }
            }
            catch (Exception ex)
            {
                // TODO?
            }

            return(null);
        }
 public Task <IActionResult> Annotations([FromBody] AnnotationRequest request)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 public Task<List<AnnotationResponse>> Annotations(string instanceName, string serverName, AnnotationRequest request, CancellationToken cancellationToken)
 {
     return DataSource(instanceName, serverName)?.Annotations(request, cancellationToken) ?? Task.FromResult(new List<AnnotationResponse>());
 }
예제 #7
0
 public IActionResult Create(AnnotationRequest r) =>
 Repo
 .Create(r.ToModel(ActualUser.Id))
 .ToActionResult(x => new { Message = "Annotation added", x.Value.Id });
예제 #8
0
        public Task <List <AnnotationResponse> > Annotations(string site, string service, AnnotationRequest request, CancellationToken cancellationToken)
        {
            if (!DataSources.ContainsKey($"{site.ToUpper()}.{service.ToUpper()}"))
            {
                RefreshMetaData(site.ToUpper(), service.ToUpper());
            }

            return(DataSources[$"{site.ToUpper()}.{service.ToUpper()}"]?.Annotations(request, cancellationToken) ?? Task.FromResult(new List <AnnotationResponse>()));
        }
예제 #9
0
 public List <AnnotationResponse> Annotations(string site, string service, AnnotationRequest request, CancellationToken cancellationToken)
 {
     return(new List <AnnotationResponse>());
 }