Work on nOCR

This commit is contained in:
Nikolaj Olsson 2020-06-07 22:36:46 +02:00
parent c791fff443
commit 9481a5b347
5 changed files with 32 additions and 11 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)