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()); }
public void PredictionByImagePathTest() { string filePath = @"TestAssets\IMG_9681.JPG"; string response = CSPrediction.MakePredictionRequestByImagePath(filePath).Result; Assert.IsNotNull(response); Assert.IsTrue(response.Contains("predictions")); }
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")); }
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")); }