private void LoadOcrFixEngine(string threeLetterISOLanguageName, string hunspellName) { if (string.IsNullOrEmpty(threeLetterISOLanguageName) && comboBoxTesseractLanguages.SelectedItem != null) { _languageId = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Id; threeLetterISOLanguageName = _languageId; } _ocrFixEngine = new OcrFixEngine(threeLetterISOLanguageName, hunspellName, this); if (_ocrFixEngine.IsDictionaryLoaded) { string loadedDictionaryName = _ocrFixEngine.SpellCheckDictionaryName; int i = 0; comboBoxDictionaries.SelectedIndexChanged -= comboBoxDictionaries_SelectedIndexChanged; foreach (string item in comboBoxDictionaries.Items) { if (item.Contains("[" + loadedDictionaryName + "]")) comboBoxDictionaries.SelectedIndex = i; i++; } comboBoxDictionaries.SelectedIndexChanged += comboBoxDictionaries_SelectedIndexChanged; comboBoxDictionaries.Left = labelDictionaryLoaded.Left + labelDictionaryLoaded.Width; comboBoxDictionaries.Width = groupBoxOcrAutoFix.Width - (comboBoxDictionaries.Left + 10 + buttonSpellCheckDownload.Width); } else { comboBoxDictionaries.SelectedIndex = 0; } if (_modiEnabled && checkBoxUseModiInTesseractForUnknownWords.Checked) { string tesseractLanguageText = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Text; int i = 0; foreach (var modiLanguage in comboBoxModiLanguage.Items) { if ((modiLanguage as ModiLanguage).Text == tesseractLanguageText) comboBoxModiLanguage.SelectedIndex = i; i++; } } comboBoxModiLanguage.SelectedIndex = -1; }
private void comboBoxDictionaries_SelectedIndexChanged(object sender, EventArgs e) { Configuration.Settings.General.SpellCheckLanguage = LanguageString; string threeLetterISOLanguageName = string.Empty; if (LanguageString == null) { _ocrFixEngine = null; return; } try { _ocrFixEngine = null; var ci = new CultureInfo(LanguageString.Replace("_", "-")); threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName; } catch { } LoadOcrFixEngine(threeLetterISOLanguageName, LanguageString); }
private void ComboBoxTesseractLanguagesSelectedIndexChanged(object sender, EventArgs e) { Configuration.Settings.VobSubOcr.TesseractLastLanguage = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Id; _ocrFixEngine = null; LoadOcrFixEngine(null, null); }
public void FixOcrErrorsViaReplaceList(string threeLetterISOLanguageName) { var ocrFixEngine = new OcrFixEngine(threeLetterISOLanguageName, null, this); string fixAction = _language.FixCommonOcrErrors; int noOfFixes = 0; string lastLine = string.Empty; for (int i = 0; i < _subtitle.Paragraphs.Count; i++) { var p = _subtitle.Paragraphs[i]; string text = ocrFixEngine.FixOcrErrors(p.Text, i, lastLine, false, OcrFixEngine.AutoGuessLevel.Cautious); lastLine = text; if (p.Text != text) { if (AllowFix(p, fixAction)) { string oldText = p.Text; p.Text = text; noOfFixes++; _totalFixes++; AddFixToListView(p, fixAction, oldText, p.Text); } Application.DoEvents(); } } if (noOfFixes > 0) LogStatus(_language.FixCommonOcrErrors, string.Format(_language.CommonOcrErrorsFixed, noOfFixes)); }