Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. private async void UplodatePictureButton_Clicked(object sender, EventArgs e)
  2. {
  3. await CrossMedia.Current.Initialize();
  4. MediaFile file;
  5. if (!CrossMedia.Current.IsPickPhotoSupported)
  6. {
  7. await DisplayAlert("No upload", "Picking a photo is not supported", "OK");
  8. return;
  9.  
  10. }
  11. file = await CrossMedia.Current.PickPhotoAsync();
  12. if (file == null)
  13. {
  14. return;
  15. }
  16.  
  17. MainImage.Source = ImageSource.FromStream(() =>
  18. {
  19. var stream = file.GetStream();
  20.  
  21. return stream;
  22. });
  23.  
  24.  
  25. // Create the Api, passing in the training key
  26. CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient()
  27. {
  28. ApiKey = trainingKey,
  29. Endpoint = SouthCentralUsEndpointTraining
  30. };
  31. var projects = trainingApi.GetProjects();
  32. var project = projects.FirstOrDefault(p => p.Name == "Car");
  33. CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
  34. {
  35. ApiKey = predictionKey,
  36. Endpoint = SouthCentralUsEndpointPrediction
  37. };
  38.  
  39.  
  40. var result = endpoint.ClassifyImageUrl(project.Id, project.Name, new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.ImageUrl(file.Path));
  41.  
  42.  
  43.  
  44. foreach (var c in result.Predictions)
  45. {
  46. Console.WriteLine($"t{c.TagName}: {c.Probability:P1}");
  47. }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement