public string judgetoy(CustomeVision.ToyModel toyModel) { string Result = string.Empty; var Childrenprobability = (from who in toyModel.predictions where who.probability == toyModel.predictions.Max(s => s.probability) select who).First(); if (Childrenprobability.probability < 0.6) { Result = "無法識別玩具歸屬"; } else { Result = $"This is a {Childrenprobability.tagName}'s toy !!"; } return(Result); }
public string CustomVision(byte[] binary) { string result = string.Empty; var client = new RestClient(System.Environment.GetEnvironmentVariable("CostomVisionURL", EnvironmentVariableTarget.Process)); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Prediction-Key", System.Environment.GetEnvironmentVariable("CustomVisionPrediction-Key", EnvironmentVariableTarget.Process)); request.AddHeader("Content-Type", "application/octet-stream"); request.AddParameter("application/octet-stream", binary, ParameterType.RequestBody); IRestResponse response = client.Execute(request); CustomeVision.ToyModel toyModel = new CustomeVision.ToyModel(); toyModel = JsonSerializer.Deserialize <CustomeVision.ToyModel>(response.Content); return(judgetoy(toyModel)); }