private void Startup() { Properties.Settings settings = new Properties.Settings(); string engineType = settings.OcrEngineType; // Show the engine selection dialog using (OcrEngineSelectDialog dlg = new OcrEngineSelectDialog(Messager.Caption, engineType, true)) { if (dlg.ShowDialog(this) == DialogResult.OK) { _ocrEngine = dlg.OcrEngine; _ocrEngineType = dlg.SelectedOcrEngineType; _ocrEngineSettings.SetEngine(_ocrEngine); // Add the selected engine name to the demo caption Text = Text + " [" + _ocrEngineType.ToString() + " Engine]"; } else { // Close the demo Close(); } } }
public static OcrResult Load(OcrImage image, string language, OcrEngineType targetType) { try { string ip = null; foreach (KeyValuePair <string, Dictionary <OcrEngineType, List <string> > > remoteType in RemoteTypes) { if (remoteType.Value.ContainsKey(targetType)) { ip = remoteType.Key; break; } } if (string.IsNullOrWhiteSpace(ip)) { return(OcrResult.Create(OcrResultType.NotInstalled)); } using (WebClient webClient = new WebClient()) { string url = "http://" + ip + ":" + port + "/" + RunOcrCommand; webClient.Proxy = null; webClient.Encoding = Encoding.UTF8; string response = webClient.UploadString(url, string.Format("type={0}&language={1}&data={2}", targetType.ToString(), language, HttpUtility.UrlEncode(Convert.ToBase64String(image.ToBinary())))); return(OcrResult.FromBinary(Convert.FromBase64String(HttpUtility.UrlDecode(response)))); } } catch (Exception e) { return(OcrResult.Create(OcrResultType.Exception, e.ToString())); } }
private void Startup() { Properties.Settings settings = new Properties.Settings(); string engineType = settings.OcrEngineType; // Show the engine selection dialog using (OcrEngineSelectDialog dlg = new OcrEngineSelectDialog(Messager.Caption, engineType, true)) { dlg.RasterCodecsInstance = _codecs; if (dlg.ShowDialog(this) == DialogResult.OK) { _ocrEngine = dlg.OcrEngine; _ocrEngineType = dlg.SelectedOcrEngineType; // Add the selected engine name to the demo caption Text = Text + " [" + _ocrEngineType.ToString() + " Engine]"; StartupEngine(); //load default image LoadImage(true); string message = String.Format(@"To use this demo: {0} 1) Load an image with text on it. {0} 2) Draw a rectangle using the mouse around the portion of text you want to recognize.", Environment.NewLine); MessageBox.Show(message, "Instructions"); UpdateMyControls(); } else { // Close the demo Close(); } } }
protected override void OnFormClosed(FormClosedEventArgs e) { // Save the last setting Properties.Settings settings = new Properties.Settings(); settings.OcrEngineType = _ocrEngineType.ToString(); settings.Save(); // Dispose the engine (this will call Shutdown as well) if (_ocrEngine != null) { _ocrEngine.Dispose(); } base.OnFormClosed(e); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { Properties.Settings settings = new Properties.Settings(); settings.OcrEngineType = _ocrEngineType.ToString(); settings.Save(); if (_ocrPage != null) { _ocrPage.Dispose(); } if (_ocrEngine != null) { _ocrEngine.Dispose(); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
void InitEngines() { _documentFormatSelector.SetDocumentWriter(_ocrEngine.DocumentWriterInstance, false); StartupEngine(); _documentFormatSelector.SetOcrEngineType(_ocrEngineType); if (_ocrEngineType == OcrEngineType.OmniPageArabic) { _autoOcrImageName = "ArabicSample.Tif"; } else { _autoOcrImageName = "OCR1.Tif"; } // Add the selected engine name to the demo caption Text = Text + " [" + _ocrEngineType.ToString() + " Engine]"; UpdateSupportedOcrModulesList(); UpdateMyControls(); Properties.Settings settings = new Properties.Settings(); // If user provided a command line argument then forget about the saved OCR Module // otherwise use the saved OCR module (if there is any). if (Environment.GetCommandLineArgs().Length > 1) { String[] arguments = Environment.GetCommandLineArgs(); if (arguments[1].Equals("Auto")) { _cmbOcrModules.SelectedIndex = 1; } else if (arguments[1].Equals("Omr")) { _cmbOcrModules.SelectedIndex = 2; } else if (arguments[1].Equals("HnrText")) { _cmbOcrModules.SelectedIndex = 3; } else if (arguments[1].Equals("HnrNum")) { _cmbOcrModules.SelectedIndex = 4; } else { _cmbOcrModules.SelectedIndex = 0; } } else { if (!String.IsNullOrEmpty(settings.OCRModule)) { for (int i = 0; i < _cmbOcrModules.Items.Count; i++) { MyItemData itemData = (MyItemData)_cmbOcrModules.Items[i]; if (itemData.ZoneType == (int)Enum.Parse(typeof(OcrZoneType), settings.OCRModule)) { _cmbOcrModules.SelectedIndex = i; break; } } if (_cmbOcrModules.SelectedIndex < 0) // No match found { _cmbOcrModules.SelectedIndex = 0; } } else { _cmbOcrModules.SelectedIndex = 0; } } if (_ocrEngine != null && _ocrEngine.IsStarted) { DocumentFormat format = DocumentFormat.Pdf; /* Load settings for the selected Document Format */ if (!String.IsNullOrEmpty(settings.DocumentFormat)) { try { format = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), settings.DocumentFormat); } catch { } } _documentFormatSelector.SelectedFormat = format; } /* Load settings for user selected View Final Document check box status */ _cbViewFinalDocument.Checked = settings.ViewFinalDocument; }