コード例 #1
0
ファイル: GetGarbage.cs プロジェクト: meghnakr/EcoHunt
        public static bool CheckGarbage(String link) //Give a link to image file
        {
            string predictionKey = EcoHunt.API_Keys.AzurePredictionKey;
            string endpoint      = EcoHunt.API_Keys.AzureEndpoint;
            string name          = EcoHunt.API_Keys.AzurepublishedName;
            string projectId     = EcoHunt.API_Keys.AzureProjectID;

            CustomVisionPredictionClient predictionAPI = new CustomVisionPredictionClient()
            {
                ApiKey   = predictionKey,
                Endpoint = endpoint
            };

            var uri      = new Uri(link);
            var imageUrl = new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.ImageUrl(link);
            var result   = predictionAPI.ClassifyImageUrl(new Guid(projectId), name, imageUrl);
            var s        = result.Predictions;
            var x        = s[0].TagName;

            // Loop over each prediction and write out the results
            if (result.Predictions[0].TagName.Equals("Garbage"))
            {
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public void MakePredictionRequest(string imageFilePath, IConfiguration configuration)
        {
            CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
            {
                ApiKey   = configuration.GetSection("AzureKeys:PredictionKey").Value,
                Endpoint = "https://centralindia.api.cognitive.microsoft.com"
            };


            using (var stream = System.IO.File.OpenRead(imageFilePath))
            {
                var result = endpoint.ClassifyImage(Guid.Parse(System.IO.File.ReadAllText(@"./ProjectId.txt")), System.IO.File.ReadAllText(@"./PublishedModelName.txt"), System.IO.File.OpenRead(imageFilePath));


                //Loop over each prediction and write out the results
                foreach (var c in result.Predictions)
                {
                    if (c.Probability > 0.80)
                    {
                        tag_name = c.TagName;
                    }
                    //Console.WriteLine($"\t{c.TagName}: {c.Probability:P1} [ {c.BoundingBox.Left}, {c.BoundingBox.Top}, {c.BoundingBox.Width}, {c.BoundingBox.Height} ]");
                }
            }
        }
コード例 #3
0
        public async Task <string> PredictImage(string url)
        {
            try
            {
                CustomVisionPredictionClient client = new CustomVisionPredictionClient()
                {
                    ApiKey   = predictionKey,
                    Endpoint = endpoint
                };

                var result = await client.PredictImageUrlAsync(projectId, new ImageUrl(url), iterationId : iterationId);

                if (result != null)
                {
                    return(result.Predictions.OrderByDescending(p => p.Probability).FirstOrDefault().TagName);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
コード例 #4
0
        async Task InitCustomVision()
        {
            //setup custom vision clients
            if (!string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) &&
                !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey) &&
                !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionResourceId))
            {
                _customVisionTraining = new CustomVisionTrainingClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionTrainingApiKey))
                {
                    Endpoint = SettingsHelper.Instance.CustomVisionTrainingApiKeyEndpoint
                };
                _customVisionPrediction = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionPredictionApiKey))
                {
                    Endpoint = SettingsHelper.Instance.CustomVisionPredictionApiKeyEndpoint
                };
            }

            //get custom vision projects
            CustomVisionProjects.Clear();
            if (_customVisionTraining != null)
            {
                var projects = await _customVisionTraining.GetProjectsAsync();

                CustomVisionProjects.AddRange(projects.OrderBy(i => i.Name).Select(i => new ProjectViewModel {
                    Project = i
                }));
            }

            //enable UI
            CustomVisionApi.IsEnabled = _customVisionTraining != null;
        }
コード例 #5
0
ファイル: MachineLearning.cs プロジェクト: malirezai/slalom
        /// <summary>
        /// Returns prediction or null if an error occurs.
        /// </summary>
        public virtual string Predict(string thumbnailUrl)
        {
            Logger.Log($"Making a prediction of {CustomVisionModelName} for: " + thumbnailUrl);

            predictionApi = new CustomVisionPredictionClient()
            {
                ApiKey   = CustomVisionKey,
                Endpoint = CustomVisionEndPoint
            };

            try
            {
                PredictionModels.ImageUrl thumbnail = new PredictionModels.ImageUrl(CropThumbnailUrl + thumbnailUrl);
                var result = predictionApi.ClassifyImageUrl(ProjectId, CustomVisionModelName, thumbnail);

                //LogPredicitions(result.Predictions);

                return(GetHighestRankedPrediction(result.Predictions));
            }
            catch (PredictionModels.CustomVisionErrorException e)
            {
                Logger.Log($"Error making prediction for {thumbnailUrl}\n\t" +
                           e.Response.Content, e);
                return(null);
            }
        }
コード例 #6
0
        async Task CaptureAndSendScreen(MediaFile file)
        {
            var endpoint = new CustomVisionPredictionClient
            {
                ApiKey   = KeyService.PredictionKey,
                Endpoint = KeyService.Endpoint
            };

            Console.WriteLine(endpoint.ApiKey);

            var result = await endpoint.ClassifyImageAsync(Guid.Parse(KeyService.ProjectId), KeyService.PublishName, file.GetStream());

            List <PredictionModel> res = result.Predictions.Where(p => p.Probability > .9).ToList();

            foreach (PredictionModel model in res)
            {
                if (model.Probability > .9)
                {
                    Console.WriteLine("RECYCLABLE!");
                    //App.user = new User(App.user.User_Name, App.user.User_Password, App.user.User_Email, App.user.User_PhoneNumber, App.user.User_CoinCount+2, App.user.User_Num_ChallengeCompleted);
                    Console.WriteLine(App.user);
                    SQLManager.updateCoins(App.user, 2, App.connectionInfo);
                }
                else
                {
                    Console.WriteLine("NOT RECYCLABLE!");
                }
            }
        }
コード例 #7
0
        public CustomObjectsProcessor(List <string> supported_items, List <string> supported_recordings)
        {
            endpoint = new CustomVisionPredictionClient(new ApiKeyServiceClientCredentials("2d82e21ce48d4465aae842adf5d78598"))
            {
                Endpoint = "https://westeurope.api.cognitive.microsoft.com/"
            };

            project_id     = new Guid("7b7714c2-4ec1-4a8a-88c4-20eda244c08d");
            published_name = "Soundz1";

            busy = false;
            supported_items_to_sounds = new Dictionary <string, AVAudioPlayer>();
            foreach (string supported_item in supported_items)
            {
                NSError err;
                NSUrl   sound_url = NSUrl.FromFilename($"sounds/{supported_item}.wav");
                supported_items_to_sounds[supported_item]            = new AVAudioPlayer(sound_url, "", out err);
                supported_items_to_sounds[supported_item].Volume     = 1.0f;
                supported_items_to_sounds[supported_item].EnableRate = true;
            }
            foreach (string supported_recording in supported_recordings)
            {
                NSData song = NSData.FromUrl(NSUrl.FromFilename(Utils.GetFileName(supported_recording)), NSDataReadingOptions.Uncached, out NSError errr);
                supported_items_to_sounds[supported_recording] = new AVAudioPlayer(
                    song,
                    "",
                    out NSError err
                    );
                supported_items_to_sounds[supported_recording].Volume     = 1.0f;
                supported_items_to_sounds[supported_recording].EnableRate = true;
            }
        }
コード例 #8
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) &&
                !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey))
            {
                userProvidedTrainingApi = new CustomVisionTrainingClient {
                    Endpoint = SouthCentralUsEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionTrainingApiKey
                };
                userProvidedPredictionApi = new CustomVisionPredictionClient {
                    Endpoint = SouthCentralUsEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionPredictionApiKey
                };
            }

            this.DataContext = this;
            await this.LoadProjectsFromService();

            if (!this.Projects.Any())
            {
                await new MessageDialog("It looks like you don't have any projects yet. Please create a project via the '+' button near the Target Project list in this page.", "No projects found").ShowAsync();
                this.webCamButton.IsEnabled         = false;
                this.PicturesAppBarButton.IsEnabled = false;
            }

            base.OnNavigatedTo(e);
        }
        async Task InitCustomVision()
        {
            //setup custom vision clients
            if (!string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) &&
                !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey))
            {
                _customVisionTraining = new CustomVisionTrainingClient {
                    Endpoint = SettingsHelper.Instance.CustomVisionTrainingApiKeyEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionTrainingApiKey
                };
                _customVisionPrediction = new CustomVisionPredictionClient {
                    Endpoint = SettingsHelper.Instance.CustomVisionPredictionApiKeyEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionPredictionApiKey
                };
            }

            //get custom vision projects
            CustomVisionProjects.Clear();
            if (_customVisionTraining != null)
            {
                var projects = await _customVisionTraining.GetProjectsAsync();

                CustomVisionProjects.AddRange(projects.OrderBy(i => i.Name).Select(i => new ProjectViewModel {
                    Project = i
                }));
            }

            //enable UI
            CustomVisionApi.IsEnabled = _customVisionTraining != null;
        }
コード例 #10
0
ファイル: ItemDetector.cs プロジェクト: dvroegop/PiCam
        /// <summary>
        /// Analyzes the image to see if we have
        /// something we're interested in.
        /// </summary>
        /// <param name="endPoint">The endpoint of our CustomVision project</param>
        /// <param name="projectId">The <see cref="Guid"/>of the project</param>
        /// <param name="publishedModelName">The name of the published model</param>
        /// <param name="fileName">The raw image name we're analyzing</param>
        public void DetectImageCharacteristics(
            CustomVisionPredictionClient endPoint,
            Guid projectId,
            string publishedModelName,
            string fileName)
        {
            Console.WriteLine("Making a prediction:");

            // Generate the full path
            var imageFile = Path.Combine("/home/pi/images/", $"{fileName}.jpg");

            // Open the image stream for uploading
            using (FileStream stream = File.OpenRead(imageFile))
            {
                // Call the API with the image stream
                ImagePrediction result = endPoint.DetectImage(
                    projectId,
                    publishedModelName,
                    File.OpenRead(imageFile));

                // Loop over each prediction and write out the results
                foreach (PredictionModel c in result.Predictions)
                {
                    Console.WriteLine(
                        $"\t{c.TagName}: {c.Probability:P1} [ {c.BoundingBox.Left}, {c.BoundingBox.Top}, {c.BoundingBox.Width}, {c.BoundingBox.Height} ]");
                }
            }
        }
コード例 #11
0
        private void MakePredictionRequest(string filepath)
        {
            CustomVisionTrainingClient trainingClient = new CustomVisionTrainingClient()
            {
                ApiKey   = trainingKey,
                Endpoint = SouthCentralUsEndpoint
            };
            // Create a prediction endpoint, passing in obtained prediction key
            CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
            {
                ApiKey   = predictionKey,
                Endpoint = SouthCentralUsEndpoint
            };
            var project = trainingClient.GetProjects().FirstOrDefault();

            // Make a prediction against the new project
            Console.WriteLine("Making a prediction:");
            var result = endpoint.PredictImage(project.Id, new MemoryStream(File.ReadAllBytes(filepath)));

            // Loop over each prediction and write out the results
            foreach (var c in result.Predictions)
            {
                Console.WriteLine($"\t{c.TagName}: {c.Probability:P1}");
            }
        }
コード例 #12
0
        // This part communicates with the customvision.ai REST services
        async void Button_Azure_Clicked(object sender, EventArgs e)
        {
            var imageStream = await PickImage();

            if (imageStream == null)
            {
                return;
            }

            var client = new CustomVisionPredictionClient
            {
                ApiKey   = KeysAndUrls.CustomVisionPredictionApiKey,
                Endpoint = KeysAndUrls.PredictionUrl
            };

            var result = await client.ClassifyImageAsync(KeysAndUrls.ProjectId, KeysAndUrls.IterationName, imageStream);

            var bestResult = result.Predictions.OrderByDescending(p => p.Probability).FirstOrDefault();

            if (bestResult == null)
            {
                return;
            }

            SetLabel($"{bestResult.TagName} ({Math.Round(bestResult.Probability * 100, 2)}%)");
        }
コード例 #13
0
        static void Main(string[] args)
        {
            string apiKey   = "fe3cedd23a9a480fb25bd91184ebb681";
            string endpoint = "https://westeurope.api.cognitive.microsoft.com";

            var client = new CustomVisionPredictionClient();

            client.ApiKey   = apiKey;
            client.Endpoint = endpoint;

            var files = Directory.GetFiles(Environment.CurrentDirectory, "*.jpg");

            foreach (var file in files)
            {
                using (var stream = File.OpenRead(file))
                {
                    var result = client.ClassifyImage(Guid.Parse("5da6478e-b413-4512-be92-1c4bb502893f"),
                                                      "Iteration2", stream);

                    foreach (var p in result.Predictions)
                    {
                        System.Console.WriteLine($"{p.TagName} {p.Probability:P4}");
                    }
                }
            }
        }
コード例 #14
0
        public async Task <Prediction> PredictAsync(Image <Rgba32> image)
        {
            var preprocessor = new Preprocessor(Rgba32.Black, Rgba32.White);

            image = preprocessor.Preprocess(image);

            var customVision = new CustomVisionPredictionClient(_httpClient, false)
            {
                ApiKey   = _apiKey,
                Endpoint = _baseUrl,
            };

            var stream = new MemoryStream();

            image.SaveAsPng(stream);

            var prediction = (await customVision.ClassifyImageWithHttpMessagesAsync(_projectId, _publishedName, stream)).Body;

            var tag = prediction.Predictions.OrderByDescending(p => p.Probability).First();

            return(new Prediction
            {
                Tag = Convert.ToInt32(tag.TagName),
                Probability = tag.Probability
            });
        }
コード例 #15
0
        static void Predict(string imageFile)
        {
            var settings = RetrieveSettings();
            // Now there is a trained endpoint, it can be used to make a prediction

            // Create a prediction endpoint, passing in the obtained prediction key
            CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
            {
                ApiKey   = PredictionKey,
                Endpoint = Endpoint
            };

            // Make a prediction against the new project
            Console.WriteLine("Making a prediction:");
            using (var stream = File.OpenRead(imageFile))
            {
                var result = endpoint.DetectImage(new Guid(settings["projectId"]), settings["modelName"], File.OpenRead(imageFile));

                //Loop over each prediction and write out the results
                foreach (var c in result.Predictions)
                {
                    Console.WriteLine($"\t{c.TagName}: {c.Probability:P1} [ {c.BoundingBox.Left}, {c.BoundingBox.Top}, {c.BoundingBox.Width}, {c.BoundingBox.Height} ]");
                }
            }
            Console.ReadKey();
        }
コード例 #16
0
        private Boolean ClassificationTest(CustomVisionPredictionClient predictionApi)
        {
            Console.WriteLine("Making a prediction:");
            String filename = "C:\\Users\\User\\Desktop\\TestRec\\Pic\\KinectCapture";

            filename = filename + this.skeletonDetectedCount.ToString();
            filename = filename + ".png";
            using (var stream = File.OpenRead(filename))
            {
                System.Guid projectID = new Guid("8267e789-cff6-4c76-a901-782c6dfc3f04"); //เอาจากlinkของ Project ใน customvision.ai/projects/<ProjectID>#/manage
                Console.WriteLine("Making a prediction:");
                var result = predictionApi.ClassifyImage(projectID, "lightdark", stream);

                // Loop over each prediction and write out the results
                foreach (var c in result.Predictions)
                {
                    Console.WriteLine($"\t{c.TagName}: {c.Probability:P1}");
                    if (c.Probability > 0.6 && c.TagName == "dark")
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
コード例 #17
0
        private Boolean DetectionTest(CustomVisionPredictionClient predictionApi)
        {
            Console.WriteLine("Making a prediction:");
            String filename = "C:\\Users\\User\\Desktop\\TestRec\\Pic\\KinectCapture";

            filename = filename + this.skeletonDetectedCount.ToString();
            filename = filename + ".png";
            using (var stream = File.OpenRead(filename))
            {
                System.Guid projectID = new Guid("22a12a4d-2c2d-49f7-a6c3-4ff7bee6b15b"); //เอาจากlinkของ Project ใน customvision.ai/projects/<ProjectID>#/manage
                var         result    = predictionApi.DetectImage(projectID, "ObjDetection", stream);
                foreach (var c in result.Predictions)
                {
                    Console.WriteLine($"\t{c.TagName}: {c.Probability:P1} [ Left:{c.BoundingBox.Left}, Top:{c.BoundingBox.Top}, Width:{c.BoundingBox.Width}, Height:{c.BoundingBox.Height} ]");
                    if (c.Probability > 0.5)
                    {
                        if (c.BoundingBox.Left < 0.35 || c.BoundingBox.Top < 0.1 || c.BoundingBox.Left > 0.61 || c.BoundingBox.Top > 0.4)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
        }
コード例 #18
0
        public CustomVisionAnalyzer(IOptions <CustomVisionSettings> settings)
        {
            this.settings = settings.Value;

            this.customVisionApi          = new CustomVisionPredictionClient();
            this.customVisionApi.Endpoint = this.settings.Endpoint;
            this.customVisionApi.ApiKey   = this.settings.PredictionKey;
        }
コード例 #19
0
        private async Task <Boolean> callDetectDarknessServices()
        {
            string ENDPOINT      = "https://southcentralus.api.cognitive.microsoft.com";
            string predictionKey = "2d24f7776af445939b7612cb8f1c2e64";
            CustomVisionPredictionClient predictionApi = AuthenticatePrediction(ENDPOINT, predictionKey);

            return(ClassificationTest(predictionApi));
        }
コード例 #20
0
 public PredictVision()
 {
     customVisionPredictionClient = new CustomVisionPredictionClient()
     {
         ApiKey   = Configuration.PredictKey,
         Endpoint = Configuration.CustomVisionEndpoint
     };
 }
コード例 #21
0
 public void Initialize(string predictionKey)
 {
     if (string.IsNullOrWhiteSpace(predictionKey))
     {
         throw new ArgumentNullException($"{nameof(predictionKey)} cannot be null or empty");
     }
     _endpoint = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(predictionKey));
 }
コード例 #22
0
 public ImageCustomVisionAnalyzer(string customVisionPredictionKey, string customVisionEndpoint, IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory            = httpClientFactory;
     _customVisionPredictionClient = new CustomVisionPredictionClient(new ApiKeyServiceClientCredentials(customVisionPredictionKey))
     {
         Endpoint = customVisionEndpoint
     };
 }
コード例 #23
0
        //public void OnGet()
        //{

        //}

        public async Task <IActionResult> OnPostAsync()
        {
            // Show image on web page
            var imageFilePath = Path.Combine(_host.WebRootPath, "images\\uploadedImage.png");

            using (var fileStream = new FileStream(imageFilePath, FileMode.OpenOrCreate))
            {
                await ImageFile.CopyToAsync(fileStream);
            }
            ImageFileUrl = "/images/uploadedImage.png";

            // Post image to Custom Vision, get resut and show on web page
            var cvClient = new CustomVisionPredictionClient()
            {
                Endpoint = cvEndpoint,
                ApiKey   = cvPredictionKey
            };

            try
            {
                var cvResult = await cvClient.DetectImageAsync(
                    Guid.Parse(cvProjectId), cvPublishName, ImageFile.OpenReadStream());

                if (cvResult.Predictions.Count > 0)
                {
                    Result      = "結果:";
                    Predictions = cvResult.Predictions;

                    // Draw rectangle on detected image
                    var detectedImagePath  = Path.Combine(_host.WebRootPath, "images\\detectedImage.png");
                    var rectangleImagePath = Path.Combine(_host.WebRootPath, "images\\rectangle.png");

                    using (var detectedImage = new Bitmap(imageFilePath))
                        using (var graphics = Graphics.FromImage(detectedImage))
                        {
                            graphics.DrawImage(new Bitmap(rectangleImagePath),
                                               (int)(cvResult.Predictions[0].BoundingBox.Left * detectedImage.Width),
                                               (int)(cvResult.Predictions[0].BoundingBox.Top * detectedImage.Height),
                                               (int)(cvResult.Predictions[0].BoundingBox.Width * detectedImage.Width),
                                               (int)(cvResult.Predictions[0].BoundingBox.Height * detectedImage.Height));

                            detectedImage.Save(detectedImagePath, ImageFormat.Png);
                        }

                    ImageFileUrl = "/images/detectedImage.png";
                }
                else
                {
                    Result = "判定できませんでした";
                }
            }
            catch (CustomVisionErrorException e)
            {
                Result = "エラー: " + e.Message;
            }

            return(Page());
        }
コード例 #24
0
        private CustomVisionPredictionClient AuthenticatePrediction(string endpoint, string predictionKey)
        {
            CustomVisionPredictionClient predictionApi = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(predictionKey))
            {
                Endpoint = endpoint
            };

            return(predictionApi);
        }
コード例 #25
0
        private static CustomVisionPredictionClient AuthenticatePrediction(string endpoint, string predictionKey)
        {
            var predictionApi = new CustomVisionPredictionClient(new ApiKeyServiceClientCredentials(predictionKey))
            {
                Endpoint = endpoint
            };

            return(predictionApi);
        }
コード例 #26
0
        async Task Ok()
        {
            IsEnabled = false;
            try
            {
                var client = new CustomVisionPredictionClient
                {
                    ApiKey   = PredictionKey,
                    Endpoint = Endpoint
                };

                if (Guid.TryParse(ProjectId, out var pId))
                {
                    var imagePath = "ObjectDetector.Images.single.png";
                    var assembly  = typeof(SettingsViewModel).GetTypeInfo().Assembly;

                    using (var stream = assembly.GetManifestResourceStream(imagePath))
                    {
                        await client.DetectImageWithNoStoreAsync(pId, publishName, stream);
                    }

                    await KeyService.SetPredictionKey(PredictionKey);

                    await KeyService.SetProjectId(ProjectId);

                    await KeyService.SetPublishName(PublishName);

                    await KeyService.SetEndpoint(Endpoint);

                    Analytics.TrackEvent("Updating keys");

                    await Application.Current.MainPage.Navigation.PopModalAsync();
                }
                else
                {
                    Analytics.TrackEvent("Failed updating keys", new Dictionary <string, string> {
                        { "Error", "The project Id is not a valid GUID" }
                    });
                    await Application.Current.MainPage.DisplayAlert("Error", "The project Id is not a valid GUID", "OK");
                }
            }
            catch (Exception ex)
            {
                Analytics.TrackEvent("Failed updating keys", new Dictionary <string, string> {
                    { "Error", "The project Id and prediction key don't match an existing project" }
                });
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "Action", "Testing key and project id" }
                });
                await Application.Current.MainPage.DisplayAlert("Error", "The project Id and prediction key don't match an existing project", "OK");
            }
            finally
            {
                IsEnabled = true;
            }
        }
コード例 #27
0
        public async Task <IActionResult> Post(List <IFormFile> img)
        {
            var requestStream = Request.HttpContext.Items;

            const string scue        = "https://southcentralus.api.cognitive.microsoft.com";
            string       trainingKey = "4f473807b7434dd5a1bdb45cb9104b38";

            CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient()
            {
                ApiKey   = trainingKey,
                Endpoint = scue
            };

            // Find the object detection domain
            var domains = trainingApi.GetDomainsAsync();
            //var objDetectionDomain = domains.FirstOrDefault(d => d.Type == "ObjectDetection");
            var project = trainingApi.GetProject(Guid.Parse("b911d77a-ef25-47fd-86ed-87db4500ef7b"));


            const string southcentralus = "https://southcentralus.api.cognitive.microsoft.com";

            string predictionKey = "a58f3ca5856c491db0b73b87cb1118cf";

            CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
            {
                ApiKey   = predictionKey,
                Endpoint = southcentralus
            };

            var c      = new List <PredictionModel>();
            var result = endpoint.PredictImage(Guid.Parse("cbfa66a3-9815-47d6-a389-7438e468ac15"), img[0].OpenReadStream());

            ImageUrl imgUrl = new ImageUrl();

            imgUrl.Url = "https://http2.mlstatic.com/guitarra-tagima-pr-200-special-pr200-sunburst-D_NQ_NP_894387-MLB26271081482_112017-F.jpg";



            var resultImageUrl = endpoint.PredictImageUrl(Guid.Parse("cbfa66a3-9815-47d6-a389-7438e468ac15"), imgUrl);

            foreach (var item in result.Predictions.OrderBy(x => x.Probability))
            {
                var pm = new PredictionModel(Math.Round(item.Probability * 100), item.TagId, item.TagName, item.BoundingBox);

                if (pm.Probability > 70)
                {
                    pm.BoundingBox.Top    = Convert.ToInt32(pm.BoundingBox.Top * 380);
                    pm.BoundingBox.Height = Convert.ToInt32(pm.BoundingBox.Height * 380);
                    pm.BoundingBox.Left   = Convert.ToInt32(pm.BoundingBox.Left * 700);
                    pm.BoundingBox.Width  = Convert.ToInt32(pm.BoundingBox.Width * 700);
                    c.Add(pm);
                }
            }

            return(Ok(c));
        }
コード例 #28
0
        protected ICustomVisionPredictionClient GetPredictionClientClient()
        {
            ICustomVisionPredictionClient client = new CustomVisionPredictionClient(handlers: HttpMockServer.CreateInstance())
            {
                ApiKey   = PredictionKey,
                Endpoint = Endpoint
            };

            return(client);
        }
コード例 #29
0
ファイル: CustomVision.cs プロジェクト: eriksty/Custom-Vision
        public CustomVisionPredictionClient InitializeServe()
        {
            CustomVisionPredictionClient ed = new CustomVisionPredictionClient()
            {
                ApiKey   = predictionKey,
                Endpoint = southcentralus
            };

            return(ed);
        }
コード例 #30
0
        private static CustomVisionPredictionClient AuthenticatePrediction(string endpoint, string predictionKey)
        {
            // Create a prediction endpoint, passing in the obtained prediction key
            CustomVisionPredictionClient predictionApi = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(predictionKey))
            {
                Endpoint = endpoint
            };

            return(predictionApi);
        }