Ejemplo n.º 1
0
        public IActionResult Detect([FromForm] IFormCollection form)
        {
            var     file          = form.Files[0];
            string  response      = CSPrediction.MakePredictionRequestByImagePath(saveFormFile(file)).Result;
            JObject predictionObj = (JObject)JsonConvert.DeserializeObject(response);
            JToken  token         = predictionObj.GetValue("predictions");

            SortedDictionary <double, Animal> animals = new SortedDictionary <double, Animal>();

            foreach (JToken child in token.Children())
            {
                double prob  = child.SelectToken("probability").ToObject <double>();
                string tagId = child.SelectToken("tagId").ToObject <string>();

                Animal animal = this._context.Animals.Where(a => a.Id.ToLower().Equals(tagId.ToLower()))?.FirstOrDefault();
                if (animal != null)
                {
                    animals.Add(prob, animal);
                }
            }

            if (animals.Any())
            {
                return(Ok(animals));
            }
            return(NotFound());
        }
Ejemplo n.º 2
0
        public void PredictionByImagePathTest()
        {
            string filePath = @"TestAssets\IMG_9681.JPG";
            string response = CSPrediction.MakePredictionRequestByImagePath(filePath).Result;

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Contains("predictions"));
        }
Ejemplo n.º 3
0
        public void PredictionByImageUrlTest()
        {
            string url      = "http://www.cowtownceramics.com/images/Corgi%203%20in.jpg";
            string response = CSPrediction.MakePredictionRequestByImageUrl(url).Result;

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Contains("predictions"));
        }
Ejemplo n.º 4
0
        public void PredictionByImagePathTest()
        {
            string root     = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string filePath = Path.Combine(root, @"TestAssets\IMG_9681.JPG");
            string response = CSPrediction.MakePredictionRequestByImagePath(filePath).Result;

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Contains("predictions"));
        }