public void CollectionFilter(AllClassLabels classLabelElement)
 {
     foreach (ImagePathClassLabelProbability element in ImageCollection.Where(image => image.ClassLabel == classLabelElement.ClassLabel))
     {
         SingleClassLabelCollection.Add(new SingleClassLabel()
         {
             Image = element.Image
         });
     }
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SingleClassLabelCollection"));
 }
        private void ImageRecognitionInWPF()
        {
            RecognitionStatus = true;

            List <StringPathAndImage> strings = new List <StringPathAndImage>();

            foreach (var path in Directory.GetFiles(ChosenDirectoryPath, "*.jpg"))
            {
                StringPathAndImage str = new StringPathAndImage
                {
                    Path  = path,
                    Image = Convert.ToBase64String(File.ReadAllBytes(path))
                };
                strings.Add(str);
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(async MagicParameter =>
            {
                try
                {
                    var content = new StringContent(JsonConvert.SerializeObject(strings), Encoding.UTF8, "application/json");
                    HttpResponseMessage httpResponse;
                    try
                    {
                        httpResponse = await client.PostAsync(url, content, cts.Token);
                    }
                    catch (HttpRequestException)
                    {
                        await dispatcher.BeginInvoke(new Action(() =>
                        {
                            MessageBox.Show("The connection with server is lost...");
                            Stop();
                        }));

                        return;
                    }

                    if (httpResponse.IsSuccessStatusCode)
                    {
                        var item = JsonConvert.DeserializeObject <List <RecognizedImage> >(httpResponse.Content.ReadAsStringAsync().Result);
                        foreach (var image in item)
                        {
                            await dispatcher.BeginInvoke(new Action(() =>
                            {
                                ImageCollection.Add(new ImagePathClassLabelProbability()
                                {
                                    Image       = LoadImage(Convert.FromBase64String(image.Image)),
                                    Path        = image.Path,
                                    ClassLabel  = image.ClassLabel,
                                    Probability = image.Probability
                                });
                                AllClassLabels label = AllClassLabelsCollection.First(element => element.ClassLabel == Convert.ToString(image.ClassLabel));
                                label.NumberOfTimes++;
                            }));
                        }
                        RecognitionStatus = false;
                    }
                }

                catch (OperationCanceledException)
                {
                    await dispatcher.BeginInvoke(new Action(() =>
                    {
                        MessageBox.Show("The recognition process was stopped.");
                    }));
                }
            }));
        }