Work on nOCR

This commit is contained in:
Nikolaj Olsson 2020-06-10 13:13:03 +02:00
parent 7d47e80bb6
commit 263f5e0938
3 changed files with 8 additions and 11 deletions

Binary file not shown.

View File

@ -67,7 +67,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
internal class NOcrThreadParameter internal class NOcrThreadParameter
{ {
public Bitmap Picture { get; set; }
public int Index { get; set; } public int Index { get; set; }
public int Increment { get; set; } public int Increment { get; set; }
public string ResultText { get; set; } public string ResultText { get; set; }
@ -81,10 +80,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public int NumberOfPixelsIsSpace; public int NumberOfPixelsIsSpace;
public bool RightToLeft; public bool RightToLeft;
public NOcrThreadParameter(Bitmap picture, int index, NOcrDb nOcrDb, BackgroundWorker self, int increment, double unItalicFactor, bool advancedItalicDetection, int numberOfPixelsIsSpace, bool rightToLeft) public NOcrThreadParameter(int index, NOcrDb nOcrDb, BackgroundWorker self, int increment, double unItalicFactor, bool advancedItalicDetection, int numberOfPixelsIsSpace, bool rightToLeft)
{ {
Self = self; Self = self;
Picture = picture;
Index = index; Index = index;
NOcrDb = nOcrDb; NOcrDb = nOcrDb;
Increment = increment; Increment = increment;
@ -105,7 +103,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public NOcrThreadResult(NOcrThreadParameter p) public NOcrThreadResult(NOcrThreadParameter p)
{ {
ResultMatches = p.ResultMatches; ResultMatches = new List<CompareMatch>(p.ResultMatches);
ResultText = p.ResultText; ResultText = p.ResultText;
} }
} }
@ -4881,7 +4879,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (start + i < max) if (start + i < max)
{ {
var bw = new BackgroundWorker(); var bw = new BackgroundWorker();
var p = new NOcrThreadParameter(null, start + i, _nOcrDbThread, bw, noOfThreads, _unItalicFactor, checkBoxNOcrItalic.Checked, _numericUpDownPixelsIsSpace, checkBoxRightToLeftNOCR.Checked) var p = new NOcrThreadParameter(start + i, _nOcrDbThread, bw, noOfThreads, _unItalicFactor, checkBoxNOcrItalic.Checked, _numericUpDownPixelsIsSpace, checkBoxRightToLeftNOCR.Checked)
{ {
NOcrLastLowercaseHeight = GetLastBinOcrLowercaseHeight(), NOcrLastLowercaseHeight = GetLastBinOcrLowercaseHeight(),
NOcrLastUppercaseHeight = GetLastBinOcrUppercaseHeight(), NOcrLastUppercaseHeight = GetLastBinOcrUppercaseHeight(),
@ -4911,8 +4909,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
p.Index += p.Increment; p.Index += p.Increment;
if (p.Index < _subtitle.Paragraphs.Count) if (p.Index < _subtitle.Paragraphs.Count)
{ {
p.ResultMatches = new List<CompareMatch>();
p.ResultText = string.Empty;
p.Self.RunWorkerAsync(p); p.Self.RunWorkerAsync(p);
} }
} }
@ -4921,12 +4917,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
var p = (NOcrThreadParameter)e.Argument; var p = (NOcrThreadParameter)e.Argument;
e.Result = p; e.Result = p;
p.Picture = GetSubtitleBitmap(p.Index); var bmp = GetSubtitleBitmap(p.Index);
var parentBitmap = new NikseBitmap(p.Picture); var parentBitmap = new NikseBitmap(bmp);
bmp.Dispose();
parentBitmap.ReplaceNonWhiteWithTransparent(); parentBitmap.ReplaceNonWhiteWithTransparent();
var minLineHeight = GetMinLineHeight(); var minLineHeight = GetMinLineHeight();
var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(parentBitmap, p.NumberOfPixelsIsSpace, p.RightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight); var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(parentBitmap, p.NumberOfPixelsIsSpace, p.RightToLeft, Configuration.Settings.VobSubOcr.TopToBottom, minLineHeight);
UpdateLineHeights(list); UpdateLineHeights(list);
p.ResultMatches = new List<CompareMatch>();
int index = 0; int index = 0;
while (index < list.Count) while (index < list.Count)
{ {
@ -4953,7 +4951,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
index++; index++;
} }
p.ResultText = MatchesToItalicStringConverter.GetStringWithItalicTags(p.ResultMatches); p.ResultText = MatchesToItalicStringConverter.GetStringWithItalicTags(p.ResultMatches);
p.Picture.Dispose();
} }
private void CleanLogsGreaterThanOrEqualTo(decimal value) private void CleanLogsGreaterThanOrEqualTo(decimal value)

View File

@ -1244,7 +1244,7 @@ namespace Nikse.SubtitleEdit.Forms
AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Italic, nameof(Configuration.Settings.Shortcuts.MainListViewItalic), true); AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Italic, nameof(Configuration.Settings.Shortcuts.MainListViewItalic), true);
AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Bold, nameof(Configuration.Settings.Shortcuts.MainListViewBold), true); AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Bold, nameof(Configuration.Settings.Shortcuts.MainListViewBold), true);
AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Underline, nameof(Configuration.Settings.Shortcuts.MainListViewUnderline), true); AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.Underline, nameof(Configuration.Settings.Shortcuts.MainListViewUnderline), true);
AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.SplitLine, nameof(Configuration.Settings.Shortcuts.MainListViewSplit), true); AddNode(listViewAndTextBoxNode, Configuration.Settings.Language.General.SplitLine.Replace("!", string.Empty), nameof(Configuration.Settings.Shortcuts.MainListViewSplit), true);
AddNode(listViewAndTextBoxNode, language.ToggleMusicSymbols, nameof(Configuration.Settings.Shortcuts.MainListViewToggleMusicSymbols), true); AddNode(listViewAndTextBoxNode, language.ToggleMusicSymbols, nameof(Configuration.Settings.Shortcuts.MainListViewToggleMusicSymbols), true);
AddNode(listViewAndTextBoxNode, language.AlignmentN1, nameof(Configuration.Settings.Shortcuts.MainListViewAlignmentN1)); AddNode(listViewAndTextBoxNode, language.AlignmentN1, nameof(Configuration.Settings.Shortcuts.MainListViewAlignmentN1));
AddNode(listViewAndTextBoxNode, language.AlignmentN2, nameof(Configuration.Settings.Shortcuts.MainListViewAlignmentN2)); AddNode(listViewAndTextBoxNode, language.AlignmentN2, nameof(Configuration.Settings.Shortcuts.MainListViewAlignmentN2));