From 9481a5b3479cb0c62f6274d248c52c7060d345a4 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 7 Jun 2020 22:36:46 +0200 Subject: [PATCH] Work on nOCR --- src/Forms/Ocr/AddBetterMultiMatchNOcr.cs | 2 +- .../VobSubNOcrCharacterInspect.Designer.cs | 12 ++++++++++ src/Forms/Ocr/VobSubNOcrCharacterInspect.cs | 22 +++++++++++++------ src/Forms/Ocr/VobSubOcr.cs | 4 ++-- src/Forms/Ocr/VobSubOcrNOcrCharacter.cs | 3 ++- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/Forms/Ocr/AddBetterMultiMatchNOcr.cs b/src/Forms/Ocr/AddBetterMultiMatchNOcr.cs index 78f076f68..8b1ca331c 100644 --- a/src/Forms/Ocr/AddBetterMultiMatchNOcr.cs +++ b/src/Forms/Ocr/AddBetterMultiMatchNOcr.cs @@ -114,7 +114,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr { using (var form = new VobSubOcrNOcrCharacter()) { - form.Initialize(_expandItem.NikseBitmap.GetBitmap(), _expandItem, new Point(0, 0), checkBoxItalic.Checked, false, textBoxText.Text); + form.Initialize(_expandItem.NikseBitmap.GetBitmap(), _expandItem, new Point(0, 0), checkBoxItalic.Checked, false, false, textBoxText.Text); var result = form.ShowDialog(this); NOcrChar = form.NOcrChar; NOcrChar.ExpandCount = (int)numericUpDownExpandCount.Value; diff --git a/src/Forms/Ocr/VobSubNOcrCharacterInspect.Designer.cs b/src/Forms/Ocr/VobSubNOcrCharacterInspect.Designer.cs index 5adbd5b54..68a20ff1d 100644 --- a/src/Forms/Ocr/VobSubNOcrCharacterInspect.Designer.cs +++ b/src/Forms/Ocr/VobSubNOcrCharacterInspect.Designer.cs @@ -167,6 +167,7 @@ this.toolStripMenuItemMusicSymbol1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemMusicSymbol2 = new System.Windows.Forms.ToolStripMenuItem(); this.labelStatus = new System.Windows.Forms.Label(); + this.labelExpandCount = new System.Windows.Forms.Label(); this.groupBoxInspectItems.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxInspectItem)).BeginInit(); this.contextMenuStripAddBetterMultiMatch.SuspendLayout(); @@ -203,6 +204,7 @@ // this.groupBoxInspectItems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); + this.groupBoxInspectItems.Controls.Add(this.labelExpandCount); this.groupBoxInspectItems.Controls.Add(this.labelImageSize); this.groupBoxInspectItems.Controls.Add(this.pictureBoxInspectItem); this.groupBoxInspectItems.Controls.Add(this.listBoxInspectItems); @@ -1227,6 +1229,15 @@ this.labelStatus.TabIndex = 38; this.labelStatus.Text = "labelStatus"; // + // labelExpandCount + // + this.labelExpandCount.AutoSize = true; + this.labelExpandCount.Location = new System.Drawing.Point(252, 96); + this.labelExpandCount.Name = "labelExpandCount"; + this.labelExpandCount.Size = new System.Drawing.Size(93, 13); + this.labelExpandCount.TabIndex = 32; + this.labelExpandCount.Text = "labelExpandCount"; + // // VobSubNOcrCharacterInspect // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1398,5 +1409,6 @@ private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemMusicSymbol1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemMusicSymbol2; private System.Windows.Forms.Label labelStatus; + private System.Windows.Forms.Label labelExpandCount; } } \ No newline at end of file diff --git a/src/Forms/Ocr/VobSubNOcrCharacterInspect.cs b/src/Forms/Ocr/VobSubNOcrCharacterInspect.cs index 4966cc89e..95f5a1c9f 100644 --- a/src/Forms/Ocr/VobSubNOcrCharacterInspect.cs +++ b/src/Forms/Ocr/VobSubNOcrCharacterInspect.cs @@ -28,6 +28,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr UiUtil.FixFonts(this); labelImageSize.Text = string.Empty; labelStatus.Text = string.Empty; + labelExpandCount.Text = string.Empty; foreach (ToolStripItem toolStripItem in contextMenuStripLetters.Items) { @@ -116,6 +117,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e) { labelImageSize.Text = string.Empty; + labelExpandCount.Text = string.Empty; if (listBoxInspectItems.SelectedIndex < 0) { return; @@ -129,7 +131,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr { pictureBoxInspectItem.Width = img.NikseBitmap.Width; pictureBoxInspectItem.Height = img.NikseBitmap.Height; - labelImageSize.Top = pictureBoxInspectItem.Top + img.NikseBitmap.Height + 17; + labelImageSize.Top = pictureBoxInspectItem.Top + img.NikseBitmap.Height + 7; labelImageSize.Text = img.NikseBitmap.Width + "x" + img.NikseBitmap.Height; if (match != null && match.ExpandCount > 1) { @@ -145,7 +147,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr pictureBoxCharacter.Image = old; pictureBoxInspectItem.Width = old.Width; pictureBoxInspectItem.Height = old.Height; - + labelExpandCount.Text = $"Expand count: {match.ExpandCount}"; } else { @@ -313,14 +315,17 @@ namespace Nikse.SubtitleEdit.Forms.Ocr text = textBoxText.Text; } - vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(0, 0), checkBoxItalic.Checked, expandSelectionList.Count > 1, text); + vobSubOcrNOcrCharacter.Initialize(_bitmap, img, new Point(0, 0), checkBoxItalic.Checked, true, expandSelectionList.Count > 1, text); DialogResult result = vobSubOcrNOcrCharacter.ShowDialog(this); bool expandSelection = false; bool shrinkSelection = false; if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection) { expandSelection = true; - expandSelectionList.Add(img); + if (img.NikseBitmap != null) + { + expandSelectionList.Add(img); + } } while (result == DialogResult.OK && (vobSubOcrNOcrCharacter.ShrinkSelection || vobSubOcrNOcrCharacter.ExpandSelection)) { @@ -339,7 +344,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr img = VobSubOcr.GetExpandedSelectionNew(new NikseBitmap(_bitmap), expandSelectionList); // true } - vobSubOcrNOcrCharacter.Initialize(_bitmap2, img, new Point(0, 0), checkBoxItalic.Checked, expandSelectionList.Count > 1, string.Empty); + vobSubOcrNOcrCharacter.Initialize(_bitmap2, img, new Point(0, 0), checkBoxItalic.Checked, true,expandSelectionList.Count > 1, string.Empty); result = vobSubOcrNOcrCharacter.ShowDialog(this); if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ShrinkSelection) @@ -354,8 +359,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr else if (result == DialogResult.OK && vobSubOcrNOcrCharacter.ExpandSelection) { expandSelection = true; - index++; - expandSelectionList.Add(_imageList[index]); + if (_imageList[index+1].NikseBitmap != null) + { + index++; + expandSelectionList.Add(_imageList[index]); + } } } if (result == DialogResult.OK) diff --git a/src/Forms/Ocr/VobSubOcr.cs b/src/Forms/Ocr/VobSubOcr.cs index 30cc02ec2..3a32de318 100644 --- a/src/Forms/Ocr/VobSubOcr.cs +++ b/src/Forms/Ocr/VobSubOcr.cs @@ -4029,7 +4029,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr } item = GetExpandedSelectionNew(nbmpInput, expandSelectionList); - _vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, _italicCheckedLast, expandSelectionList.Count > 1, string.Empty); + _vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, _italicCheckedLast, true, expandSelectionList.Count > 1, string.Empty); var result = _vobSubOcrNOcrCharacter.ShowDialog(this); _manualOcrDialogPosition = _vobSubOcrNOcrCharacter.FormPosition; if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ShrinkSelection) @@ -4079,7 +4079,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr var match = GetNOcrCompareMatchNew(item, nbmpInput, _nOcrDb, checkBoxNOcrItalic.Checked, !checkBoxNOcrDrawUnknownLetters.Checked, index, list); if (match == null) { - _vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, _italicCheckedLast, false, string.Empty); + _vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, _italicCheckedLast, true, false, string.Empty); var result = _vobSubOcrNOcrCharacter.ShowDialog(this); _manualOcrDialogPosition = _vobSubOcrNOcrCharacter.FormPosition; if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ExpandSelection) diff --git a/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs b/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs index 2d8449601..f5d527e86 100644 --- a/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs +++ b/src/Forms/Ocr/VobSubOcrNOcrCharacter.cs @@ -70,7 +70,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr public bool IsItalic => checkBoxItalic.Checked; - internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, string text) + internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showExpand, bool showShrink, string text) { listBoxLinesForeground.Items.Clear(); listBoxlinesBackground.Items.Clear(); @@ -88,6 +88,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr _drawLineOn = false; _warningNoNotForegroundLinesShown = false; + buttonExpandSelection.Visible = showExpand; buttonShrinkSelection.Visible = showShrink; if (position.X != -1 && position.Y != -1)