internal void InitializeBatch(List<BluRaySupParser.PcsData> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName) { Initialize(subtitles, vobSubOcrSettings, fileName); FormVobSubOcr_Shown(null, null); checkBoxPromptForUnknownWords.Checked = false; int max = GetSubtitleCount(); if (_ocrMethodIndex == _ocrMethodTesseract && _tesseractAsyncStrings == null) { _tesseractAsyncStrings = new string[max]; _tesseractAsyncIndex = (int)numericUpDownStartNumber.Value + 5; _tesseractThread = new BackgroundWorker(); _tesseractThread.DoWork += TesseractThreadDoWork; _tesseractThread.RunWorkerCompleted += TesseractThreadRunWorkerCompleted; _tesseractThread.WorkerSupportsCancellation = true; if (_tesseractAsyncIndex >= 0 && _tesseractAsyncIndex < max) _tesseractThread.RunWorkerAsync(GetSubtitleBitmap(_tesseractAsyncIndex)); } System.Threading.Thread.Sleep(1000); subtitleListView1.SelectedIndexChanged -= SubtitleListView1SelectedIndexChanged; for (int i = 0; i < max; i++) { Application.DoEvents(); if (_abort) { SetButtonsEnabledAfterOcrDone(); return; } subtitleListView1.SelectIndexAndEnsureVisible(i); string text = OcrViaTesseract(GetSubtitleBitmap(i), i); _lastLine = text; text = text.Replace("<i>-</i>", "-"); text = text.Replace("<i>a</i>", "a"); text = text.Replace(" ", " "); text = text.Trim(); text = text.Replace(" " + Environment.NewLine, Environment.NewLine); text = text.Replace(Environment.NewLine + " ", Environment.NewLine); // max allow 2 lines if (checkBoxAutoBreakLines.Checked && text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length) { text = text.Replace(" " + Environment.NewLine, Environment.NewLine); text = text.Replace(Environment.NewLine + " ", Environment.NewLine); while (text.Contains(Environment.NewLine + Environment.NewLine)) text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); if (text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length) text = Utilities.AutoBreakLine(text); } Application.DoEvents(); if (_abort) { textBoxCurrentText.Text = text; SetButtonsEnabledAfterOcrDone(); return; } text = text.Trim(); text = text.Replace(" ", " "); text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); text = text.Replace(" ", " "); text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); Paragraph p = _subtitle.GetParagraphOrDefault(i); if (p != null) p.Text = text; if (subtitleListView1.SelectedItems.Count == 1 && subtitleListView1.SelectedItems[0].Index == i) textBoxCurrentText.Text = text; else subtitleListView1.SetText(i, text); } SetButtonsEnabledAfterOcrDone(); }
internal void InitializeQuick(List<VobSubMergedPack> vobSubMergedPackist, List<Color> palette, VobSubOcrSettings vobSubOcrSettings, string languageString) { buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; _vobSubMergedPackist = vobSubMergedPackist; _palette = palette; if (_palette == null) checkBoxCustomFourColors.Checked = true; _importLanguageString = languageString; if (_importLanguageString != null && _importLanguageString.Contains('(') && !_importLanguageString.StartsWith('(')) _importLanguageString = _importLanguageString.Substring(0, languageString.IndexOf('(') - 1).Trim(); }
internal void Initialize(List<XSub> subPictures, VobSubOcrSettings vobSubOcrSettings, string fileName) { _xSubList = subPictures; buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); checkBoxCustomFourColors.Enabled = true; checkBoxCustomFourColors.Checked = true; checkBoxAutoTransparentBackground.Enabled = true; checkBoxAutoTransparentBackground.Enabled = false; SetOcrMethod(); FileName = fileName; Text += " - " + Path.GetFileName(FileName); foreach (XSub subItem in _xSubList) { var p = new Paragraph(string.Empty, subItem.Start.TotalMilliseconds, subItem.End.TotalMilliseconds); _subtitle.Paragraphs.Add(p); } _subtitle.Renumber(); subtitleListView1.Fill(_subtitle); subtitleListView1.SelectIndexAndEnsureVisible(0); }
// TODO: Get language from ts file internal void Initialize(List<TransportStreamSubtitle> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName) { buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); _dvbSubtitles = subtitles; ShowDvbSubs(); FileName = fileName; Text += " - " + Path.GetFileName(fileName); groupBoxImagePalette.Visible = false; groupBoxTransportStream.Left = groupBoxImagePalette.Left; groupBoxTransportStream.Top = groupBoxImagePalette.Top; groupBoxTransportStream.Visible = true; checkBoxTransportStreamGetColorAndSplit.Visible = subtitles.Count > 0 && subtitles[0].IsDvbSub; }
internal void Initialize(Subtitle bdnSubtitle, VobSubOcrSettings vobSubOcrSettings, bool isSon) { _bdnXmlOriginal = bdnSubtitle; _bdnFileName = bdnSubtitle.FileName; _isSon = isSon; if (_isSon) { checkBoxCustomFourColors.Checked = true; pictureBoxBackground.BackColor = Color.Transparent; pictureBoxPattern.BackColor = Color.DarkGray; pictureBoxEmphasis1.BackColor = Color.Black; pictureBoxEmphasis2.BackColor = Color.White; } buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = 11; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); groupBoxImagePalette.Visible = isSon; Text = Configuration.Settings.Language.VobSubOcr.TitleBluRay; Text += " - " + Path.GetFileName(_bdnFileName); checkBoxAutoTransparentBackground.Checked = true; }
internal void Initialize(string fileName, List<Color> palette, VobSubOcrSettings vobSubOcrSettings, List<SpHeader> spList) { _spList = spList; buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); _palette = palette; if (_palette == null) checkBoxCustomFourColors.Checked = true; SetOcrMethod(); FileName = fileName; Text += " - " + Path.GetFileName(FileName); foreach (SpHeader header in _spList) { Paragraph p = new Paragraph(string.Empty, header.StartTime.TotalMilliseconds, header.StartTime.TotalMilliseconds + header.Picture.Delay.TotalMilliseconds); _subtitle.Paragraphs.Add(p); } _subtitle.Renumber(); subtitleListView1.Fill(_subtitle); subtitleListView1.SelectIndexAndEnsureVisible(0); }
internal void Initialize(Subtitle subtitle, List<DvbSubPes> subtitleImages, VobSubOcrSettings vobSubOcrSettings, object p) { buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); groupBoxImagePalette.Visible = false; _dvbPesSubtitles = subtitleImages; _subtitle = subtitle; _subtitle.Renumber(); subtitleListView1.Fill(_subtitle); subtitleListView1.SelectIndexAndEnsureVisible(0); checkBoxAutoTransparentBackground.Visible = false; }
internal void Initialize(List<BluRaySupParser.PcsData> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName) { buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = 11; // vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = 11; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); _bluRaySubtitlesOriginal = subtitles; groupBoxImagePalette.Visible = false; Text = Configuration.Settings.Language.VobSubOcr.TitleBluRay; if (!string.IsNullOrEmpty(fileName)) { if (fileName.Length > 40) fileName = Path.GetFileName(fileName); Text += " - " + fileName; } checkBoxAutoTransparentBackground.Checked = false; checkBoxAutoTransparentBackground.Visible = false; }
internal void Initialize(List<VobSubMergedPack> vobSubMergedPackist, List<Color> palette, VobSubOcrSettings vobSubOcrSettings, string languageString) { buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); _vobSubMergedPackist = vobSubMergedPackist; _palette = palette; if (_palette == null) checkBoxCustomFourColors.Checked = true; SetTesseractLanguageFromLanguageString(languageString); _importLanguageString = languageString; }
internal bool Initialize(string vobSubFileName, VobSubOcrSettings vobSubOcrSettings, Main main) { _main = main; buttonOK.Enabled = false; buttonCancel.Enabled = false; buttonStartOcr.Enabled = false; buttonStop.Enabled = false; buttonNewCharacterDatabase.Enabled = false; buttonEditCharacterDatabase.Enabled = false; labelStatus.Text = string.Empty; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Value = 0; numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; _vobSubOcrSettings = vobSubOcrSettings; InitializeModi(); InitializeTesseract(); LoadImageCompareCharacterDatabaseList(); SetOcrMethod(); FileName = vobSubFileName; Text += " - " + Path.GetFileName(FileName); return InitializeSubIdx(vobSubFileName); }
/// <summary> /// The initialize batch. /// </summary> /// <param name="vobSubFileName"> /// The vob sub file name. /// </param> /// <param name="vobSubOcrSettings"> /// The vob sub ocr settings. /// </param> internal void InitializeBatch(string vobSubFileName, VobSubOcrSettings vobSubOcrSettings) { this.Initialize(vobSubFileName, vobSubOcrSettings, null); this.FormVobSubOcr_Shown(null, null); this.checkBoxPromptForUnknownWords.Checked = false; int max = this.GetSubtitleCount(); if (this.comboBoxOcrMethod.SelectedIndex == 0 && this._tesseractAsyncStrings == null) { this._tesseractAsyncStrings = new string[max]; this._tesseractAsyncIndex = (int)this.numericUpDownStartNumber.Value + 5; this._tesseractThread = new BackgroundWorker(); this._tesseractThread.DoWork += this.TesseractThreadDoWork; this._tesseractThread.RunWorkerCompleted += this.TesseractThreadRunWorkerCompleted; this._tesseractThread.WorkerSupportsCancellation = true; if (this._tesseractAsyncIndex >= 0 && this._tesseractAsyncIndex < max) { this._tesseractThread.RunWorkerAsync(this.GetSubtitleBitmap(this._tesseractAsyncIndex)); } } System.Threading.Thread.Sleep(1000); this.subtitleListView1.SelectedIndexChanged -= this.SubtitleListView1SelectedIndexChanged; for (int i = 0; i < max; i++) { Application.DoEvents(); if (this._abort) { this.SetButtonsEnabledAfterOcrDone(); return; } this.subtitleListView1.SelectIndexAndEnsureVisible(i); string text = this.OcrViaTesseract(this.GetSubtitleBitmap(i), i); this._lastLine = text; text = text.Replace("<i>-</i>", "-"); text = text.Replace("<i>a</i>", "a"); text = text.Replace("<i>.</i>", "."); text = text.Replace(" ", " "); text = text.Trim(); text = text.Replace(" " + Environment.NewLine, Environment.NewLine); text = text.Replace(Environment.NewLine + " ", Environment.NewLine); // max allow 2 lines if (this.checkBoxAutoBreakLines.Checked && text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length) { text = text.Replace(" " + Environment.NewLine, Environment.NewLine); text = text.Replace(Environment.NewLine + " ", Environment.NewLine); while (text.Contains(Environment.NewLine + Environment.NewLine)) { text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); } if (text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length) { text = Utilities.AutoBreakLine(text); } } Application.DoEvents(); if (this._abort) { this.textBoxCurrentText.Text = text; this.SetButtonsEnabledAfterOcrDone(); return; } text = text.Trim(); text = text.Replace(" ", " "); text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); text = text.Replace(" ", " "); text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine); Paragraph p = this._subtitle.GetParagraphOrDefault(i); if (p != null) { p.Text = text; } if (this.subtitleListView1.SelectedItems.Count == 1 && this.subtitleListView1.SelectedItems[0].Index == i) { this.textBoxCurrentText.Text = text; } else { this.subtitleListView1.SetText(i, text); } } this.SetButtonsEnabledAfterOcrDone(); }
// TODO: Get language from ts file /// <summary> /// The initialize. /// </summary> /// <param name="subtitles"> /// The subtitles. /// </param> /// <param name="vobSubOcrSettings"> /// The vob sub ocr settings. /// </param> /// <param name="fileName"> /// The file name. /// </param> internal void Initialize(List<TransportStreamSubtitle> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName) { this.buttonOK.Enabled = false; this.buttonCancel.Enabled = false; this.buttonStartOcr.Enabled = false; this.buttonStop.Enabled = false; this.buttonNewCharacterDatabase.Enabled = false; this.buttonEditCharacterDatabase.Enabled = false; this.labelStatus.Text = string.Empty; this.progressBar1.Visible = false; this.progressBar1.Maximum = 100; this.progressBar1.Value = 0; this.numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; this.numericUpDownNumberOfPixelsIsSpaceNOCR.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; this._vobSubOcrSettings = vobSubOcrSettings; this.InitializeModi(); this.InitializeTesseract(); this.LoadImageCompareCharacterDatabaseList(); this.SetOcrMethod(); this._dvbSubtitles = subtitles; this.ShowDvbSubs(); this.FileName = fileName; this.Text += " - " + Path.GetFileName(fileName); this.groupBoxImagePalette.Visible = false; this.groupBoxTransportStream.Left = this.groupBoxImagePalette.Left; this.groupBoxTransportStream.Top = this.groupBoxImagePalette.Top; this.groupBoxTransportStream.Visible = true; this.checkBoxTransportStreamGetColorAndSplit.Visible = subtitles.Count > 0 && subtitles[0].IsDvbSub; // SetTesseractLanguageFromLanguageString(languageString); // _importLanguageString = languageString; }
/// <summary> /// The initialize. /// </summary> /// <param name="subPicturesWithTimeCodes"> /// The sub pictures with time codes. /// </param> /// <param name="vobSubOcrSettings"> /// The vob sub ocr settings. /// </param> /// <param name="fileName"> /// The file name. /// </param> internal void Initialize(List<SubPicturesWithSeparateTimeCodes> subPicturesWithTimeCodes, VobSubOcrSettings vobSubOcrSettings, string fileName) { this._mp4List = subPicturesWithTimeCodes; this.buttonOK.Enabled = false; this.buttonCancel.Enabled = false; this.buttonStartOcr.Enabled = false; this.buttonStop.Enabled = false; this.buttonNewCharacterDatabase.Enabled = false; this.buttonEditCharacterDatabase.Enabled = false; this.labelStatus.Text = string.Empty; this.progressBar1.Visible = false; this.progressBar1.Maximum = 100; this.progressBar1.Value = 0; this.numericUpDownPixelsIsSpace.Value = vobSubOcrSettings.XOrMorePixelsMakesSpace; this._vobSubOcrSettings = vobSubOcrSettings; this.InitializeModi(); this.InitializeTesseract(); this.LoadImageCompareCharacterDatabaseList(); if (this._palette == null) { this.checkBoxCustomFourColors.Checked = true; } this.SetOcrMethod(); this.FileName = fileName; this.Text += " - " + Path.GetFileName(this.FileName); foreach (SubPicturesWithSeparateTimeCodes subItem in this._mp4List) { var p = new Paragraph(string.Empty, subItem.Start.TotalMilliseconds, subItem.End.TotalMilliseconds); this._subtitle.Paragraphs.Add(p); } this.subtitleListView1.Fill(this._subtitle); this.subtitleListView1.SelectIndexAndEnsureVisible(0); }