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; } } }
void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs) { try { System.Drawing.Image img = (Bitmap)eventArgs.Frame.Clone(); MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); bi.Freeze(); Dispatcher.BeginInvoke(new ThreadStart(delegate { VideoImage.Source = bi; Image <Bgr, Byte> imageCV = new Image <Bgr, Byte>(BitmapImage2Bitmap(bi)); Rectangle[] rectangles = cascadeClassifier.DetectMultiScale(imageCV, 1.4, 0, new System.Drawing.Size(100, 100), new System.Drawing.Size(800, 800)); if (rectangles.Length > 0) { var rectanles = rectangles[0]; var diferentRectangels = DifferenceBetweenRectangles(rectanles, _rectangleOriginal); if ((diferentRectangels.X != 0 || diferentRectangels.Y != 0) && diferentRectangels.X > 40 && diferentRectangels.Y > 40 || (_rectangleOriginal.X == 0 && _rectangleOriginal.Y == 0)) { _rectangleOriginal = rectanles; imageCV.Draw(rectangles[0], new Bgr(0, 0, 255), 3); VideoImage.Source = ToBitmapSource(imageCV); imageCV.ROI = rectangles[0]; RecognizedPlateImage.Source = ToBitmapSource(imageCV); Task.Run(() => { lock (_lock) { var licensePlate = ProcessImage(imageCV); if (licensePlate != null) { MemoryDictionaryHelper.AddLicensePlate(licensePlate); LicensePlateList.Dispatcher.BeginInvoke((Action)(() => { AddToListBox(licensePlate); })); } else { _rectangleOriginal = new Rectangle(); } } }); } } })); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }