Exemplo n.º 1
0
        private void ProcessOcrImage(Image image)
        {
            var lang   = (string)mnuLanguageCombo.SelectedItem == "Spanish" ? "spa" : "eng";
            var ocr    = OcrFactory.GetOcr(mnuEngine.SelectedItem.ToString());
            var result = ocr.Process(image, lang);

            notifyIcon.Visible = true; // hide balloon tip (if any)
            OcrResultForm.ShowOcr(result);
        }
Exemplo n.º 2
0
        private void ProcessOcrImage(Image image)
        {
            var lang   = (string)mnuLanguageCombo.SelectedItem == "Spanish" ? "spa" : "eng";
            var ocr    = OcrFactory.GetOcr(mnuEngine.SelectedItem.ToString());
            var result = ocr.Process(image, lang);

            notifyIcon.Visible = true; // hide balloon tip (if any)
            if (String.IsNullOrEmpty(processingProgram))
            {
                OcrResultForm.ShowOcr(result);
            }
            else
            {
                var filename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString();
                image.Save(filename + ".png");
                File.WriteAllText(filename + ".txt", result.Text);

                Process process = new Process();
                // Stop the process from opening a new window
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;

                // Setup executable and parameters
                process.StartInfo.FileName  = processingProgram.Split(' ')[0];
                process.StartInfo.Arguments = (
                    String.Join(" ", processingProgram.Split(' ').Skip(1)) +
                    " --text=" + filename + ".txt --img=" + filename + ".png");
                process.Start();
                process.WaitForExit();
                string showError = "";
                string line;
                while ((line = process.StandardError.ReadLine()) != null)
                {
                    // process and print
                    showError += line;
                }
                if (showError.Length > 0)
                {
                    result.Text = showError;
                    OcrResultForm.ShowOcr(result);
                }
            }
        }