private void AddToListBox(LicensePlateModel licensePlate)
        {
            //if (MemoryDictionaryHelper.Count() > 0 &&
            //    MemoryDictionaryHelper.LastIndex < MemoryDictionaryHelper.AddedLastIndex)
            //{
            //    var itmBox = new ListBoxItem();
            //    itmBox.Content = MemoryDictionaryHelper.GetLatLicensePlate().LicensePlate;

            //    if (!LicensePlateList.Items.Contains(itmBox))
            //    {
            //        LicensePlateList.Items.Add(itmBox);
            //        MemoryDictionaryHelper.LastIndex = MemoryDictionaryHelper.AddedLastIndex;
            //    }
            //}

            licensePlate.LicensePlate = CleaningLicensePlate.Cleaning(licensePlate.LicensePlate);
            var user = _userManagement.GetUser(licensePlate.LicensePlate);

            if (user != null)
            {
                LicensePlateList.Items.Add(UserHelper.ConverToLicensePlateUserModel(user));
            }
            else
            {
                user = new UserModel
                {
                    LicensePlate = licensePlate.LicensePlate
                };

                LicensePlateList.Items.Add(UserHelper.ConverToLicensePlateUserModel(user));
            }

            TaskScheduler.FromCurrentSynchronizationContext();
        }
        private LicensePlateModel ProcessImage(IInputOutputArray image)
        {
            List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
            List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
            List <RotatedRect>       licenseBoxList = new List <RotatedRect>();
            List <string>            plates         = _licensePlateDetectorInVideo.DetectLicensePlate(
                image,
                licensePlateImagesList,
                filteredLicensePlateImagesList,
                licenseBoxList);

            LicensePlateModel licensePlateModel = new LicensePlateModel();

            foreach (var plate in plates)
            {
                Debug.WriteLine($"Sosurce string: {plate}");
                var cleanPlate = CleaningLicensePlate.Cleaning(plate);
                if (cleanPlate != null)
                {
                    Debug.WriteLine($"Definit string: {plate}");

                    licensePlateModel.LicensePlate = cleanPlate;
                    licensePlateModel.CountFindItemLicensePlate = plates.Count;

                    return(licensePlateModel);
                }
            }

            return(null);
        }
 public static void AddLicensePlate(LicensePlateModel licensePlate)
 {
     licensePlate.LicensePlate = CleaningLicensePlate.Cleaning(licensePlate.LicensePlate);
     if (!string.IsNullOrEmpty(licensePlate.LicensePlate))
     {
         _infoLicensePlateModels[licensePlate.LicensePlate] = licensePlate;
     }
 }
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "Select a picture";
            openFileDialog.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                    "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                    "Portable Network Graphic (*.png)|*.png";
            if (openFileDialog.ShowDialog() == true)
            {
                FileNameTextBox.Text = openFileDialog.FileName;
                CarImage.Source      = new BitmapImage(new Uri(openFileDialog.FileName));
            }

            if (!string.IsNullOrEmpty(openFileDialog.FileName))
            {
                LicensePlateModel licensePlate = GetLicensePlate(openFileDialog.FileName);

                if (!string.IsNullOrEmpty(licensePlate.LicensePlate))
                {
                    Dispatcher.Invoke((Action)(() =>
                    {
                        licensePlate.LicensePlate = CleaningLicensePlate.Cleaning(licensePlate.LicensePlate);
                        var user = _userManagement.GetUser(licensePlate.LicensePlate);

                        if (user != null)
                        {
                            InfoNumberListBox.Items.Add(UserHelper.ConverToLicensePlateUserModel(user));
                        }
                        else
                        {
                            user = new UserModel
                            {
                                LicensePlate = licensePlate.LicensePlate
                            };

                            InfoNumberListBox.Items.Add(UserHelper.ConverToLicensePlateUserModel(user));
                        }

                        TimaLabel.Content = licensePlate.Timer;
                        GuantityPlateLable.Content = licensePlate.GuantityPlateResult;

                        CarImage.Source = licensePlate.Image;
                        ImageOriginal.Source = licensePlate.ImageLicensePlate;

                        MemoryDictionaryHelper.AddLicensePlate(licensePlate);
                    }));
                }
            }
        }
        private void InfoNumberListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LicensePlateUserModel listBoxItem = (LicensePlateUserModel)InfoNumberListBox.SelectedItem;

            if (listBoxItem != null)
            {
                LicensePlateModel licensePlate = MemoryDictionaryHelper.GetLicensePlate(listBoxItem.LicensePlate);
                if (licensePlate != null)
                {
                    CarImage.Source      = licensePlate.Image;
                    ImageOriginal.Source = licensePlate.ImageLicensePlate;
                }
            }
        }
        private LicensePlateModel ProcessImage(IInputOutputArray image)
        {
            LicensePlateModel licensePlateModel = new LicensePlateModel();

            Stopwatch watch = Stopwatch.StartNew();

            List <IInputOutputArray> licensePlateImagesList         = new List <IInputOutputArray>();
            List <IInputOutputArray> filteredLicensePlateImagesList = new List <IInputOutputArray>();
            List <RotatedRect>       licenseBoxList = new List <RotatedRect>();
            List <string>            words          = _licensePlateDetector.DetectLicensePlate(
                image,
                licensePlateImagesList,
                filteredLicensePlateImagesList,
                licenseBoxList);

            watch.Stop();

            licensePlateModel.Timer = watch.Elapsed.TotalMilliseconds.ToString();
            licensePlateModel.GuantityPlateResult = words.Count;
            Point  startPoint    = new Point(10, 10);
            string numberLicense = string.Empty;

            for (int i = 0; i < words.Count; i++)
            {
                numberLicense = words[i].Replace(" ", string.Empty);

                numberLicense = new string(numberLicense.Where(c => !char.IsPunctuation(c)).ToArray());

                Mat dest = new Mat();
                CvInvoke.VConcat(licensePlateImagesList[i], filteredLicensePlateImagesList[i], dest);
                BitmapSource bso = ToBitmapSource(dest);
                licensePlateModel.ImageLicensePlate = bso;

                PointF[] verticesF = licenseBoxList[i].GetVertices();
                Point[]  vertices  = Array.ConvertAll(verticesF, Point.Round);
                licensePlateModel.Points = vertices;

                if (numberLicense.Length >= 8)
                {
                    licensePlateModel.LicensePlate = numberLicense;
                    return(licensePlateModel);
                }
            }
            return(licensePlateModel);
        }
        private LicensePlateModel GetLicensePlate(string imageRoute)
        {
            Mat  mate = new Mat(imageRoute);
            UMat uMat = mate.GetUMat(AccessType.ReadWrite);

            LicensePlateModel processResult = ProcessImage(mate);

            if (processResult.Points != null)
            {
                Bgra bgra = new Bgra(200, 200, 200, 200);
                Image <Bgra, Byte> newImg = new Image <Bgra, byte>(uMat.Bitmap);
                newImg.Draw(processResult.Points, bgra, 10);

                BitmapSource bs = ToBitmapSource(newImg);
                processResult.Image = bs;

                return(processResult);
            }

            return(new LicensePlateModel());
        }