コード例 #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getprediction")] HttpRequest req,
            ILogger log)
        {
            string imgLink = req.Query["img"];

            if (IsValidImgLink(imgLink))
            {
                var imageUrl        = new ImageUrl(imgLink);
                var projectId       = Guid.Parse(Environment.GetEnvironmentVariable("CustomVisionProjectId"));
                var publishedName   = Environment.GetEnvironmentVariable("CustomVisionPublishedName");
                var imagePrediction = await _customVisionPredictionClient.ClassifyImageUrlAsync(
                    projectId,
                    publishedName,
                    imageUrl);

                var highestPrediction = imagePrediction.Predictions
                                        .OrderByDescending(prediction => prediction.Probability)
                                        .First();
                var message = $"This looks like {highestPrediction.TagName}! I'm {highestPrediction.Probability} certain of it 🤓.";

                return(new OkObjectResult(message));
            }
            else
            {
                return(new BadRequestObjectResult("Please provide an image url (png/jp(e)g/gif) in the `img` query parameter."));
            }
        }
コード例 #2
0
 public static async Task <ImagePrediction> ClassifyImageUrlWithRetryAsync(this ICustomVisionPredictionClient predictionApi, Guid projectId, ImageUrl imageUrl, string publishedName)
 {
     return(await RunTaskWithAutoRetryOnQuotaLimitExceededError(async() => await predictionApi.ClassifyImageUrlAsync(projectId, publishedName, imageUrl)));
 }
コード例 #3
0
 /// <summary>
 /// Classify an image url and saves the result.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='projectId'>
 /// The project id.
 /// </param>
 /// <param name='publishedName'>
 /// Specifies the name of the model to evaluate against.
 /// </param>
 /// <param name='imageUrl'>
 /// An ImageUrl that contains the url of the image to be evaluated.
 /// </param>
 /// <param name='application'>
 /// Optional. Specifies the name of application using the endpoint.
 /// </param>
 public static ImagePrediction ClassifyImageUrl(this ICustomVisionPredictionClient operations, System.Guid projectId, string publishedName, ImageUrl imageUrl, string application = default(string))
 {
     return(operations.ClassifyImageUrlAsync(projectId, publishedName, imageUrl, application).GetAwaiter().GetResult());
 }