mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Minor ocr improvements
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1025 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
479014e609
commit
be027f0ef3
16
src/Forms/OCRSpellCheck.Designer.cs
generated
16
src/Forms/OCRSpellCheck.Designer.cs
generated
@ -43,6 +43,7 @@
|
|||||||
this.buttonSkipOnce = new System.Windows.Forms.Button();
|
this.buttonSkipOnce = new System.Windows.Forms.Button();
|
||||||
this.buttonAddToNames = new System.Windows.Forms.Button();
|
this.buttonAddToNames = new System.Windows.Forms.Button();
|
||||||
this.groupBoxEditWholeText = new System.Windows.Forms.GroupBox();
|
this.groupBoxEditWholeText = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonChangeAllWholeText = new System.Windows.Forms.Button();
|
||||||
this.buttonSkipText = new System.Windows.Forms.Button();
|
this.buttonSkipText = new System.Windows.Forms.Button();
|
||||||
this.buttonChangeWholeText = new System.Windows.Forms.Button();
|
this.buttonChangeWholeText = new System.Windows.Forms.Button();
|
||||||
this.textBoxWholeText = new System.Windows.Forms.TextBox();
|
this.textBoxWholeText = new System.Windows.Forms.TextBox();
|
||||||
@ -215,6 +216,7 @@
|
|||||||
// groupBoxEditWholeText
|
// groupBoxEditWholeText
|
||||||
//
|
//
|
||||||
this.groupBoxEditWholeText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.groupBoxEditWholeText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.groupBoxEditWholeText.Controls.Add(this.buttonChangeAllWholeText);
|
||||||
this.groupBoxEditWholeText.Controls.Add(this.buttonSkipText);
|
this.groupBoxEditWholeText.Controls.Add(this.buttonSkipText);
|
||||||
this.groupBoxEditWholeText.Controls.Add(this.buttonChangeWholeText);
|
this.groupBoxEditWholeText.Controls.Add(this.buttonChangeWholeText);
|
||||||
this.groupBoxEditWholeText.Controls.Add(this.textBoxWholeText);
|
this.groupBoxEditWholeText.Controls.Add(this.textBoxWholeText);
|
||||||
@ -225,6 +227,16 @@
|
|||||||
this.groupBoxEditWholeText.TabStop = false;
|
this.groupBoxEditWholeText.TabStop = false;
|
||||||
this.groupBoxEditWholeText.Text = "Edit whole text";
|
this.groupBoxEditWholeText.Text = "Edit whole text";
|
||||||
//
|
//
|
||||||
|
// buttonChangeAllWholeText
|
||||||
|
//
|
||||||
|
this.buttonChangeAllWholeText.Location = new System.Drawing.Point(6, 115);
|
||||||
|
this.buttonChangeAllWholeText.Name = "buttonChangeAllWholeText";
|
||||||
|
this.buttonChangeAllWholeText.Size = new System.Drawing.Size(141, 21);
|
||||||
|
this.buttonChangeAllWholeText.TabIndex = 36;
|
||||||
|
this.buttonChangeAllWholeText.Text = "Change all";
|
||||||
|
this.buttonChangeAllWholeText.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonChangeAllWholeText.Click += new System.EventHandler(this.buttonChangeAllWholeText_Click);
|
||||||
|
//
|
||||||
// buttonSkipText
|
// buttonSkipText
|
||||||
//
|
//
|
||||||
this.buttonSkipText.Location = new System.Drawing.Point(156, 88);
|
this.buttonSkipText.Location = new System.Drawing.Point(156, 88);
|
||||||
@ -253,6 +265,7 @@
|
|||||||
this.textBoxWholeText.Name = "textBoxWholeText";
|
this.textBoxWholeText.Name = "textBoxWholeText";
|
||||||
this.textBoxWholeText.Size = new System.Drawing.Size(290, 63);
|
this.textBoxWholeText.Size = new System.Drawing.Size(290, 63);
|
||||||
this.textBoxWholeText.TabIndex = 31;
|
this.textBoxWholeText.TabIndex = 31;
|
||||||
|
this.textBoxWholeText.TextChanged += new System.EventHandler(this.textBoxWholeText_TextChanged);
|
||||||
//
|
//
|
||||||
// groupBoxTextAsImage
|
// groupBoxTextAsImage
|
||||||
//
|
//
|
||||||
@ -333,8 +346,8 @@
|
|||||||
this.Controls.Add(this.buttonAbort);
|
this.Controls.Add(this.buttonAbort);
|
||||||
this.Controls.Add(this.labelWordNotFound);
|
this.Controls.Add(this.labelWordNotFound);
|
||||||
this.Controls.Add(this.groupBoxSuggestions);
|
this.Controls.Add(this.groupBoxSuggestions);
|
||||||
this.Controls.Add(this.GroupBoxEditWord);
|
|
||||||
this.Controls.Add(this.groupBoxEditWholeText);
|
this.Controls.Add(this.groupBoxEditWholeText);
|
||||||
|
this.Controls.Add(this.GroupBoxEditWord);
|
||||||
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Name = "OcrSpellCheck";
|
this.Name = "OcrSpellCheck";
|
||||||
this.ShowIcon = false;
|
this.ShowIcon = false;
|
||||||
@ -379,5 +392,6 @@
|
|||||||
private System.Windows.Forms.RichTextBox richTextBoxParagraph;
|
private System.Windows.Forms.RichTextBox richTextBoxParagraph;
|
||||||
private System.Windows.Forms.Button buttonAddToDictionary;
|
private System.Windows.Forms.Button buttonAddToDictionary;
|
||||||
private System.Windows.Forms.Button buttonSkipText;
|
private System.Windows.Forms.Button buttonSkipText;
|
||||||
|
private System.Windows.Forms.Button buttonChangeAllWholeText;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,15 +17,17 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
ChangeAndSave,
|
ChangeAndSave,
|
||||||
ChangeOnce,
|
ChangeOnce,
|
||||||
ChangeWholeText,
|
ChangeWholeText,
|
||||||
|
ChangeAllWholeText,
|
||||||
SkipAll,
|
SkipAll,
|
||||||
SkipWholeText,
|
SkipWholeText,
|
||||||
SkipOnce,
|
SkipOnce,
|
||||||
UseSuggestion,
|
UseSuggestion,
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action ActionResult { get; private set; }
|
public Action ActionResult { get; private set; }
|
||||||
public string Word { get; private set; }
|
public string Word { get; private set; }
|
||||||
public string Paragraph { get; private set; }
|
public string Paragraph { get; private set; }
|
||||||
|
public string OriginalWholeText { get; private set; }
|
||||||
|
|
||||||
private string _originalWord;
|
private string _originalWord;
|
||||||
|
|
||||||
@ -75,6 +77,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
internal void Initialize(string word, List<string> suggestions, string line, string[] words, int i, Bitmap bitmap)
|
internal void Initialize(string word, List<string> suggestions, string line, string[] words, int i, Bitmap bitmap)
|
||||||
{
|
{
|
||||||
_originalWord = word;
|
_originalWord = word;
|
||||||
|
OriginalWholeText = line;
|
||||||
pictureBoxText.Image = bitmap;
|
pictureBoxText.Image = bitmap;
|
||||||
textBoxWord.Text = word;
|
textBoxWord.Text = word;
|
||||||
richTextBoxParagraph.Text = line;
|
richTextBoxParagraph.Text = line;
|
||||||
@ -210,6 +213,13 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonChangeAllWholeText_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Paragraph = textBoxWholeText.Text.Trim();
|
||||||
|
ActionResult = Action.ChangeAllWholeText;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonAddToNamesClick(object sender, EventArgs e)
|
private void ButtonAddToNamesClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Word = textBoxWord.Text.Trim();
|
Word = textBoxWord.Text.Trim();
|
||||||
@ -256,5 +266,11 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
buttonChangeAll.Enabled = buttonChange.Enabled;
|
buttonChangeAll.Enabled = buttonChange.Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void textBoxWholeText_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
buttonChangeWholeText.Enabled = textBoxWholeText.Text != OriginalWholeText;
|
||||||
|
buttonChangeAllWholeText.Enabled = buttonChangeWholeText.Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -946,6 +946,9 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
|||||||
if (input.StartsWith("<i>... "))
|
if (input.StartsWith("<i>... "))
|
||||||
input = input.Remove(6, 1);
|
input = input.Remove(6, 1);
|
||||||
|
|
||||||
|
if (input.StartsWith("...<i>") && (input.IndexOf("</i>") > input.IndexOf(" ")))
|
||||||
|
input = "<i>..." + input.Remove(0, 6);
|
||||||
|
|
||||||
if (input.EndsWith(". .."))
|
if (input.EndsWith(". .."))
|
||||||
input = input.Remove(input.Length - 4, 4) + "...";
|
input = input.Remove(input.Length - 4, 4) + "...";
|
||||||
if (input.EndsWith(".. ."))
|
if (input.EndsWith(".. ."))
|
||||||
@ -964,6 +967,12 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
|||||||
if (input.EndsWith(". ...</i>"))
|
if (input.EndsWith(". ...</i>"))
|
||||||
input = input.Remove(input.Length - 9, 9) + "...</i>";
|
input = input.Remove(input.Length - 9, 9) + "...</i>";
|
||||||
|
|
||||||
|
if (input.EndsWith(".</i> . ."))
|
||||||
|
input = input.Remove(input.Length - 9, 9) + "...</i>";
|
||||||
|
if (input.EndsWith(".</i>.."))
|
||||||
|
input = input.Remove(input.Length - 7, 7) + "...</i>";
|
||||||
|
input = input.Replace(".</i> . ." + Environment.NewLine, "...</i>" + Environment.NewLine);
|
||||||
|
|
||||||
input = input.Replace(".. ?", "..?");
|
input = input.Replace(".. ?", "..?");
|
||||||
input = input.Replace("..?", "...?");
|
input = input.Replace("..?", "...?");
|
||||||
input = input.Replace("....?", "...?");
|
input = input.Replace("....?", "...?");
|
||||||
@ -1218,7 +1227,7 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] words = tempLine.Split((Environment.NewLine + " ¡¿,.!?:;()[]{}+-£\"”“#&%…—♪/").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
string[] words = tempLine.Replace("</i>", string.Empty).Split((Environment.NewLine + " ¡¿,.!?:;()[]{}+-£\"”“#&%…—♪/").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||||
for (int i = 0; i < words.Length; i++)
|
for (int i = 0; i < words.Length; i++)
|
||||||
{
|
{
|
||||||
string word = words[i].TrimStart('\'');
|
string word = words[i].TrimStart('\'');
|
||||||
@ -1470,6 +1479,11 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
|||||||
result.Line = _spellCheck.Paragraph;
|
result.Line = _spellCheck.Paragraph;
|
||||||
result.FixedWholeLine = true;
|
result.FixedWholeLine = true;
|
||||||
break;
|
break;
|
||||||
|
case OcrSpellCheck.Action.ChangeAllWholeText:
|
||||||
|
SaveWordToWholeLineList(_spellCheck.OriginalWholeText);
|
||||||
|
result.Line = _spellCheck.Paragraph;
|
||||||
|
result.FixedWholeLine = true;
|
||||||
|
break;
|
||||||
case OcrSpellCheck.Action.SkipAll:
|
case OcrSpellCheck.Action.SkipAll:
|
||||||
_wordSkipList.Add(_spellCheck.Word);
|
_wordSkipList.Add(_spellCheck.Word);
|
||||||
_wordSkipList.Add(_spellCheck.Word.ToUpper());
|
_wordSkipList.Add(_spellCheck.Word.ToUpper());
|
||||||
@ -1578,6 +1592,51 @@ namespace Nikse.SubtitleEdit.Logic.OCR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SaveWordToWholeLineList(string line)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_replaceListXmlFileName != null)
|
||||||
|
{
|
||||||
|
var doc = new XmlDocument();
|
||||||
|
if (File.Exists(_replaceListXmlFileName))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
doc.Load(_replaceListXmlFileName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
doc.LoadXml("<ReplaceList><WholeWords/><PartialLines/><BeginLines/><EndLines/><WholeLines/></ReplaceList>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
doc.LoadXml("<ReplaceList><WholeWords/><PartialLines/><BeginLines/><EndLines/><WholeLines/></ReplaceList>");
|
||||||
|
}
|
||||||
|
if (!_wholeLineReplaceList.ContainsKey(line))
|
||||||
|
_wholeLineReplaceList.Add(line, _spellCheck.Paragraph);
|
||||||
|
XmlNode wholeWordsNode = doc.DocumentElement.SelectSingleNode("WholeLines");
|
||||||
|
if (wholeWordsNode != null)
|
||||||
|
{
|
||||||
|
XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Line", null);
|
||||||
|
XmlAttribute aFrom = doc.CreateAttribute("from");
|
||||||
|
XmlAttribute aTo = doc.CreateAttribute("to");
|
||||||
|
aFrom.InnerText = line;
|
||||||
|
aTo.InnerText = _spellCheck.Paragraph;
|
||||||
|
newNode.Attributes.Append(aFrom);
|
||||||
|
newNode.Attributes.Append(aTo);
|
||||||
|
wholeWordsNode.AppendChild(newNode);
|
||||||
|
doc.Save(_replaceListXmlFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(exception + Environment.NewLine + exception.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool DoSpell(string word)
|
public bool DoSpell(string word)
|
||||||
{
|
{
|
||||||
return _hunspell.Spell(word);
|
return _hunspell.Spell(word);
|
||||||
|
@ -181,6 +181,8 @@ namespace Nikse.SubtitleEdit.Logic.VobSub
|
|||||||
VobSubMergedPack pack = list[i];
|
VobSubMergedPack pack = list[i];
|
||||||
if (pack.SubPicture == null || pack.SubPicture.ImageDisplayArea.Width <= 3 || pack.SubPicture.ImageDisplayArea.Height <= 2)
|
if (pack.SubPicture == null || pack.SubPicture.ImageDisplayArea.Width <= 3 || pack.SubPicture.ImageDisplayArea.Height <= 2)
|
||||||
list.RemoveAt(i);
|
list.RemoveAt(i);
|
||||||
|
if (pack.EndTime.TotalSeconds - pack.StartTime.TotalSeconds < 0.1 && pack.SubPicture.ImageDisplayArea.Width <= 10 && pack.SubPicture.ImageDisplayArea.Height <= 10)
|
||||||
|
list.RemoveAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix subs with no duration (completely normal) or negative duration or duration > 10 seconds
|
// Fix subs with no duration (completely normal) or negative duration or duration > 10 seconds
|
||||||
|
Loading…
Reference in New Issue
Block a user