private void DetectText_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image|*.jpg;*.png"; if (ofd.ShowDialog() == true) { var fileBytes = File.ReadAllBytes(ofd.FileName); var sw = Stopwatch.StartNew(); byte[] debugBytes; ResultText.Text = _sceneText.NaturalSceneDetect(fileBytes, out debugBytes).Trim(); sw.Stop(); TimeText.Text = String.Format("{0}ms", sw.ElapsedMilliseconds); MemoryStream ms = new MemoryStream(debugBytes); var imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = ms; imageSource.EndInit(); Image.Source = imageSource; } }
private void Bulk_Click(object sender, RoutedEventArgs e) { var progress = new ProgressWindow(); progress.Owner = this; progress.Show(); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += (s, ev) => { ImageTextExtractor extractor = new ImageTextExtractor(); var folder = @"C:\Users\michaelha\Desktop\SuburbDownload"; var files = Directory.EnumerateFiles(folder).ToList(); int count = 0; foreach (var file in files) { var b = File.ReadAllBytes(file); byte[] debug; var text = extractor.NaturalSceneDetect(b, out debug); if (!String.IsNullOrEmpty(text)) { File.WriteAllBytes(Path.Combine(@"C:\Users\michaelha\Desktop\OUTPUT", Path.GetFileName(file)), debug); } count++; var p = ((double)count / (double)files.Count) * 100; worker.ReportProgress((int)p, p); } }; worker.RunWorkerCompleted += (s, ev) => { progress.Close(); }; worker.ProgressChanged += (s, ev) => { var p = (double)ev.UserState; progress.UpdateProgress(p); }; worker.RunWorkerAsync(); }