Add nOCR as fallback for "Binary image compare"

This commit is contained in:
Nikolaj Olsson 2020-05-30 14:22:08 +02:00
parent 811a521092
commit 553f1ac643
22 changed files with 3438 additions and 1335 deletions

Binary file not shown.

View File

@ -1398,6 +1398,7 @@ $HorzAlign = Center
public int LineOcrLinesToAutoGuess { get; set; } public int LineOcrLinesToAutoGuess { get; set; }
public int LineOcrMinLineHeight { get; set; } public int LineOcrMinLineHeight { get; set; }
public int LineOcrMaxLineHeight { get; set; } public int LineOcrMaxLineHeight { get; set; }
public int LineOcrMaxErrorPixels { get; set; }
public string LastBinaryImageCompareDb { get; set; } public string LastBinaryImageCompareDb { get; set; }
public string LastBinaryImageSpellCheck { get; set; } public string LastBinaryImageSpellCheck { get; set; }
public bool BinaryAutoDetectBestDb { get; set; } public bool BinaryAutoDetectBestDb { get; set; }
@ -1427,6 +1428,7 @@ $HorzAlign = Center
AutoBreakSubtitleIfMoreThanTwoLines = true; AutoBreakSubtitleIfMoreThanTwoLines = true;
ItalicFactor = 0.2f; ItalicFactor = 0.2f;
LineOcrLinesToAutoGuess = 100; LineOcrLinesToAutoGuess = 100;
LineOcrMaxErrorPixels = 45;
BinaryAutoDetectBestDb = true; BinaryAutoDetectBestDb = true;
CaptureTopAlign = false; CaptureTopAlign = false;
UnfocusedAttentionBlinkCount = 50; UnfocusedAttentionBlinkCount = 50;
@ -5292,6 +5294,12 @@ $HorzAlign = Center
settings.VobSubOcr.LineOcrMaxLineHeight = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture); settings.VobSubOcr.LineOcrMaxLineHeight = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
} }
subNode = node.SelectSingleNode("LineOcrMaxErrorPixels");
if (subNode != null)
{
settings.VobSubOcr.LineOcrMaxErrorPixels = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("LastBinaryImageCompareDb"); subNode = node.SelectSingleNode("LastBinaryImageCompareDb");
if (subNode != null) if (subNode != null)
{ {
@ -7507,6 +7515,7 @@ $HorzAlign = Center
textWriter.WriteElementString("LineOcrLinesToAutoGuess", settings.VobSubOcr.LineOcrLinesToAutoGuess.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("LineOcrLinesToAutoGuess", settings.VobSubOcr.LineOcrLinesToAutoGuess.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("LineOcrMinLineHeight", settings.VobSubOcr.LineOcrMinLineHeight.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("LineOcrMinLineHeight", settings.VobSubOcr.LineOcrMinLineHeight.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("LineOcrMaxLineHeight", settings.VobSubOcr.LineOcrMaxLineHeight.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("LineOcrMaxLineHeight", settings.VobSubOcr.LineOcrMaxLineHeight.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("LineOcrMaxErrorPixels", settings.VobSubOcr.LineOcrMaxErrorPixels.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("LastBinaryImageCompareDb", settings.VobSubOcr.LastBinaryImageCompareDb); textWriter.WriteElementString("LastBinaryImageCompareDb", settings.VobSubOcr.LastBinaryImageCompareDb);
textWriter.WriteElementString("LastBinaryImageSpellCheck", settings.VobSubOcr.LastBinaryImageSpellCheck); textWriter.WriteElementString("LastBinaryImageSpellCheck", settings.VobSubOcr.LastBinaryImageSpellCheck);
textWriter.WriteElementString("BinaryAutoDetectBestDb", settings.VobSubOcr.BinaryAutoDetectBestDb.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("BinaryAutoDetectBestDb", settings.VobSubOcr.BinaryAutoDetectBestDb.ToString(CultureInfo.InvariantCulture));

View File

@ -0,0 +1,217 @@
namespace Nikse.SubtitleEdit.Forms.Ocr
{
partial class AddBetterMultiMatchNOcr
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBoxInspectItems = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.checkBoxItalic = new System.Windows.Forms.CheckBox();
this.labelText = new System.Windows.Forms.Label();
this.textBoxText = new System.Windows.Forms.TextBox();
this.numericUpDownExpandCount = new System.Windows.Forms.NumericUpDown();
this.labelImageInfo = new System.Windows.Forms.Label();
this.pictureBoxInspectItem = new System.Windows.Forms.PictureBox();
this.listBoxInspectItems = new System.Windows.Forms.ListBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.groupBoxInspectItems.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExpandCount)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxInspectItem)).BeginInit();
this.SuspendLayout();
//
// groupBoxInspectItems
//
this.groupBoxInspectItems.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxInspectItems.Controls.Add(this.label1);
this.groupBoxInspectItems.Controls.Add(this.checkBoxItalic);
this.groupBoxInspectItems.Controls.Add(this.labelText);
this.groupBoxInspectItems.Controls.Add(this.textBoxText);
this.groupBoxInspectItems.Controls.Add(this.numericUpDownExpandCount);
this.groupBoxInspectItems.Controls.Add(this.labelImageInfo);
this.groupBoxInspectItems.Controls.Add(this.pictureBoxInspectItem);
this.groupBoxInspectItems.Controls.Add(this.listBoxInspectItems);
this.groupBoxInspectItems.Location = new System.Drawing.Point(12, 12);
this.groupBoxInspectItems.Name = "groupBoxInspectItems";
this.groupBoxInspectItems.Size = new System.Drawing.Size(569, 381);
this.groupBoxInspectItems.TabIndex = 4;
this.groupBoxInspectItems.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(253, 19);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(73, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Expand count";
//
// checkBoxItalic
//
this.checkBoxItalic.AutoSize = true;
this.checkBoxItalic.Location = new System.Drawing.Point(253, 130);
this.checkBoxItalic.Name = "checkBoxItalic";
this.checkBoxItalic.Size = new System.Drawing.Size(58, 17);
this.checkBoxItalic.TabIndex = 4;
this.checkBoxItalic.Text = "Is &italic";
this.checkBoxItalic.UseVisualStyleBackColor = true;
//
// labelText
//
this.labelText.AutoSize = true;
this.labelText.Location = new System.Drawing.Point(252, 86);
this.labelText.Name = "labelText";
this.labelText.Size = new System.Drawing.Size(28, 13);
this.labelText.TabIndex = 31;
this.labelText.Text = "Text";
//
// textBoxText
//
this.textBoxText.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBoxText.Location = new System.Drawing.Point(252, 102);
this.textBoxText.Name = "textBoxText";
this.textBoxText.Size = new System.Drawing.Size(100, 23);
this.textBoxText.TabIndex = 3;
//
// numericUpDownExpandCount
//
this.numericUpDownExpandCount.Location = new System.Drawing.Point(252, 38);
this.numericUpDownExpandCount.Maximum = new decimal(new int[] {
3,
0,
0,
0});
this.numericUpDownExpandCount.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDownExpandCount.Name = "numericUpDownExpandCount";
this.numericUpDownExpandCount.Size = new System.Drawing.Size(63, 20);
this.numericUpDownExpandCount.TabIndex = 2;
this.numericUpDownExpandCount.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// labelImageInfo
//
this.labelImageInfo.AutoSize = true;
this.labelImageInfo.Location = new System.Drawing.Point(253, 168);
this.labelImageInfo.Name = "labelImageInfo";
this.labelImageInfo.Size = new System.Drawing.Size(45, 13);
this.labelImageInfo.TabIndex = 5;
this.labelImageInfo.Text = "Preview";
//
// pictureBoxInspectItem
//
this.pictureBoxInspectItem.BackColor = System.Drawing.Color.Red;
this.pictureBoxInspectItem.Location = new System.Drawing.Point(253, 184);
this.pictureBoxInspectItem.Name = "pictureBoxInspectItem";
this.pictureBoxInspectItem.Size = new System.Drawing.Size(52, 52);
this.pictureBoxInspectItem.TabIndex = 23;
this.pictureBoxInspectItem.TabStop = false;
//
// listBoxInspectItems
//
this.listBoxInspectItems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.listBoxInspectItems.Enabled = false;
this.listBoxInspectItems.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listBoxInspectItems.FormattingEnabled = true;
this.listBoxInspectItems.Location = new System.Drawing.Point(6, 19);
this.listBoxInspectItems.Name = "listBoxInspectItems";
this.listBoxInspectItems.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.listBoxInspectItems.Size = new System.Drawing.Size(240, 342);
this.listBoxInspectItems.TabIndex = 0;
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(506, 399);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(425, 399);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 5;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
//
// AddBetterMultiMatchNOcr
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(593, 434);
this.Controls.Add(this.groupBoxInspectItems);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AddBetterMultiMatchNOcr";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AddBetterMultiMatchNOcr";
this.groupBoxInspectItems.ResumeLayout(false);
this.groupBoxInspectItems.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExpandCount)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxInspectItem)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBoxInspectItems;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox checkBoxItalic;
private System.Windows.Forms.Label labelText;
private System.Windows.Forms.TextBox textBoxText;
private System.Windows.Forms.NumericUpDown numericUpDownExpandCount;
private System.Windows.Forms.Label labelImageInfo;
private System.Windows.Forms.PictureBox pictureBoxInspectItem;
private System.Windows.Forms.ListBox listBoxInspectItems;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.Ocr
{
public partial class AddBetterMultiMatchNOcr : Form
{
public AddBetterMultiMatchNOcr()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,160 @@
namespace Nikse.SubtitleEdit.Forms.Ocr
{
sealed partial class BinaryOcrChooseEditDb
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonEditCharacterDatabase = new System.Windows.Forms.Button();
this.buttonNewCharacterDatabase = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxNOcrLanguage = new System.Windows.Forms.ComboBox();
this.comboBoxCharacterDatabase = new System.Windows.Forms.ComboBox();
this.labelImageDatabase = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonEditCharacterDatabase
//
this.buttonEditCharacterDatabase.Location = new System.Drawing.Point(215, 51);
this.buttonEditCharacterDatabase.Name = "buttonEditCharacterDatabase";
this.buttonEditCharacterDatabase.Size = new System.Drawing.Size(86, 23);
this.buttonEditCharacterDatabase.TabIndex = 5;
this.buttonEditCharacterDatabase.Text = "Edit";
this.buttonEditCharacterDatabase.UseVisualStyleBackColor = true;
this.buttonEditCharacterDatabase.Click += new System.EventHandler(this.buttonEditCharacterDatabase_Click);
//
// buttonNewCharacterDatabase
//
this.buttonNewCharacterDatabase.Location = new System.Drawing.Point(307, 51);
this.buttonNewCharacterDatabase.Name = "buttonNewCharacterDatabase";
this.buttonNewCharacterDatabase.Size = new System.Drawing.Size(86, 23);
this.buttonNewCharacterDatabase.TabIndex = 4;
this.buttonNewCharacterDatabase.Text = "New";
this.buttonNewCharacterDatabase.UseVisualStyleBackColor = true;
this.buttonNewCharacterDatabase.Click += new System.EventHandler(this.buttonNewCharacterDatabase_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 108);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(124, 13);
this.label2.TabIndex = 37;
this.label2.Text = "nOCR fallback dictionary";
//
// comboBoxNOcrLanguage
//
this.comboBoxNOcrLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxNOcrLanguage.FormattingEnabled = true;
this.comboBoxNOcrLanguage.Location = new System.Drawing.Point(21, 124);
this.comboBoxNOcrLanguage.Name = "comboBoxNOcrLanguage";
this.comboBoxNOcrLanguage.Size = new System.Drawing.Size(188, 21);
this.comboBoxNOcrLanguage.TabIndex = 36;
//
// comboBoxCharacterDatabase
//
this.comboBoxCharacterDatabase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCharacterDatabase.FormattingEnabled = true;
this.comboBoxCharacterDatabase.Location = new System.Drawing.Point(21, 51);
this.comboBoxCharacterDatabase.Name = "comboBoxCharacterDatabase";
this.comboBoxCharacterDatabase.Size = new System.Drawing.Size(188, 21);
this.comboBoxCharacterDatabase.TabIndex = 39;
//
// labelImageDatabase
//
this.labelImageDatabase.AutoSize = true;
this.labelImageDatabase.Location = new System.Drawing.Point(18, 35);
this.labelImageDatabase.Name = "labelImageDatabase";
this.labelImageDatabase.Size = new System.Drawing.Size(83, 13);
this.labelImageDatabase.TabIndex = 38;
this.labelImageDatabase.Text = "Image database";
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(320, 171);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 41;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(239, 171);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 40;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// BinaryOcrChooseEditDb
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(407, 206);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.comboBoxCharacterDatabase);
this.Controls.Add(this.labelImageDatabase);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboBoxNOcrLanguage);
this.Controls.Add(this.buttonEditCharacterDatabase);
this.Controls.Add(this.buttonNewCharacterDatabase);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "BinaryOcrChooseEditDb";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "BinaryOcrChooseEditDb";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.BinaryOcrChooseEditDb_KeyDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonEditCharacterDatabase;
private System.Windows.Forms.Button buttonNewCharacterDatabase;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBoxNOcrLanguage;
private System.Windows.Forms.ComboBox comboBoxCharacterDatabase;
private System.Windows.Forms.Label labelImageDatabase;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;
}
}

View File

@ -0,0 +1,136 @@
using System;
using Nikse.SubtitleEdit.Core;
using System.IO;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic.Ocr.Binary;
namespace Nikse.SubtitleEdit.Forms.Ocr
{
public sealed partial class BinaryOcrChooseEditDb : Form
{
public string ImageCompareDatabaseName { get; private set; }
public BinaryOcrChooseEditDb(string binaryImageDb)
{
InitializeComponent();
buttonNewCharacterDatabase.Text = Configuration.Settings.Language.VobSubOcr.New;
buttonEditCharacterDatabase.Text = Configuration.Settings.Language.VobSubOcr.Edit;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
labelImageDatabase.Text = Configuration.Settings.Language.VobSubOcr.ImageDatabase;
Text = Configuration.Settings.Language.VobSubOcr.ImageDatabase;
var imageCompareDbName = string.Empty;
var nOcrDbName = string.Empty;
ImageCompareDatabaseName = binaryImageDb;
if (!string.IsNullOrEmpty(binaryImageDb))
{
var parts = binaryImageDb.Split('+');
if (parts.Length > 0)
{
imageCompareDbName = parts[0];
if (parts.Length > 1)
{
nOcrDbName = parts[1];
}
}
}
comboBoxNOcrLanguage.Items.Clear();
comboBoxNOcrLanguage.Items.Add(string.Empty);
foreach (string fileName in Directory.GetFiles(Configuration.OcrDirectory, "*.nocr"))
{
string s = Path.GetFileNameWithoutExtension(fileName);
comboBoxNOcrLanguage.Items.Add(s);
if (s == nOcrDbName)
{
comboBoxNOcrLanguage.SelectedIndex = comboBoxNOcrLanguage.Items.Count - 1;
}
}
comboBoxCharacterDatabase.Items.Clear();
foreach (string s in BinaryOcrDb.GetDatabases())
{
comboBoxCharacterDatabase.Items.Add(s);
if (s == imageCompareDbName)
{
comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1;
}
}
}
private void BinaryOcrChooseEditDb_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
e.SuppressKeyPress = true;
DialogResult = DialogResult.Cancel;
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
ImageCompareDatabaseName = comboBoxCharacterDatabase.Text;
if (string.IsNullOrEmpty(ImageCompareDatabaseName))
{
return;
}
var nOcrDatabase = comboBoxNOcrLanguage.Text;
if (!string.IsNullOrEmpty(nOcrDatabase))
{
ImageCompareDatabaseName += "+" + nOcrDatabase;
}
DialogResult = DialogResult.OK;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void buttonNewCharacterDatabase_Click(object sender, EventArgs e)
{
using (var newFolder = new VobSubOcrNewFolder(false))
{
if (newFolder.ShowDialog(this) == DialogResult.OK)
{
try
{
string fileName = Path.Combine(Configuration.OcrDirectory, newFolder.FolderName + ".db");
if (File.Exists(fileName))
{
MessageBox.Show("OCR db already exists!");
return;
}
comboBoxCharacterDatabase.Items.Add(newFolder.FolderName);
comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1;
var binaryOcrDb = new BinaryOcrDb(fileName);
binaryOcrDb.Save();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
}
private void buttonEditCharacterDatabase_Click(object sender, EventArgs e)
{
var fileName = Path.Combine(Configuration.OcrDirectory, comboBoxCharacterDatabase.SelectedItem + ".db");
var binaryOcrDb = new BinaryOcrDb(fileName);
binaryOcrDb.LoadCompareImages();
using (var formVobSubEditCharacters = new VobSubEditCharacters( null, binaryOcrDb))
{
if (formVobSubEditCharacters.ShowDialog() == DialogResult.OK)
{
binaryOcrDb.Save();
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -4,23 +4,17 @@ using Nikse.SubtitleEdit.Logic.Ocr.Binary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml;
namespace Nikse.SubtitleEdit.Forms.Ocr namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
public sealed partial class VobSubEditCharacters : Form public sealed partial class VobSubEditCharacters : Form
{ {
private readonly XmlDocument _compareDoc = new XmlDocument();
private readonly string _directoryPath;
private List<bool> _italics = new List<bool>(); private List<bool> _italics = new List<bool>();
internal List<VobSubOcr.ImageCompareAddition> Additions { get; } internal List<VobSubOcr.ImageCompareAddition> Additions { get; }
private readonly BinaryOcrDb _binOcrDb; private readonly BinaryOcrDb _binOcrDb;
public XmlDocument ImageCompareDocument => _compareDoc; internal VobSubEditCharacters(List<VobSubOcr.ImageCompareAddition> additions, BinaryOcrDb binOcrDb)
internal VobSubEditCharacters(string databaseFolderName, List<VobSubOcr.ImageCompareAddition> additions, BinaryOcrDb binOcrDb)
{ {
UiUtil.PreInitialize(this); UiUtil.PreInitialize(this);
InitializeComponent(); InitializeComponent();
@ -47,17 +41,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
labelImageInfo.Text = string.Empty; labelImageInfo.Text = string.Empty;
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
_directoryPath = Configuration.VobSubCompareDirectory + databaseFolderName + Path.DirectorySeparatorChar;
if (!File.Exists(_directoryPath + "Images.xml"))
{
_compareDoc.LoadXml("<OcrBitmaps></OcrBitmaps>");
}
else
{
_compareDoc.Load(_directoryPath + "Images.xml");
}
Refill(Additions); Refill(Additions);
Text = Configuration.Settings.Language.VobSubEditCharacters.Title; Text = Configuration.Settings.Language.VobSubEditCharacters.Title;
@ -137,25 +120,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
} }
else
{
foreach (XmlNode node in _compareDoc.DocumentElement.ChildNodes)
{
if (node.Attributes["Text"] != null)
{
string text = node.Attributes["Text"].InnerText;
string name = node.InnerText;
foreach (VobSubOcr.ImageCompareAddition a in additions)
{
if (name == a.Name)
{
listBoxFileNames.Items.Add("[" + text + "] " + node.InnerText);
_italics.Add(node.Attributes["Italic"] != null);
}
}
}
}
}
if (listBoxFileNames.Items.Count > 0) if (listBoxFileNames.Items.Count > 0)
{ {
@ -191,22 +155,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
count++; count++;
} }
} }
else
{
foreach (XmlNode node in _compareDoc.DocumentElement.SelectNodes("Item"))
{
if (node.Attributes.Count >= 1)
{
string text = node.Attributes["Text"].InnerText;
if (!texts.Contains(text))
{
texts.Add(text);
}
count++;
}
}
}
texts.Sort(); texts.Sort();
labelCount.Text = $"{count:#,##0}"; labelCount.Text = $"{count:#,##0}";
@ -250,21 +199,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
} }
else
{
foreach (XmlNode node in _compareDoc.DocumentElement.ChildNodes)
{
if (node.Attributes["Text"] != null)
{
string text = node.Attributes["Text"].InnerText;
if (text == target)
{
listBoxFileNames.Items.Add(node.InnerText);
_italics.Add(node.Attributes["Italic"] != null);
}
}
}
}
if (listBoxFileNames.Items.Count > 0) if (listBoxFileNames.Items.Count > 0)
{ {
@ -308,8 +242,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void ListBoxFileNamesSelectedIndexChanged(object sender, EventArgs e) private void ListBoxFileNamesSelectedIndexChanged(object sender, EventArgs e)
{ {
checkBoxItalic.Checked = _italics[listBoxFileNames.SelectedIndex]; checkBoxItalic.Checked = _italics[listBoxFileNames.SelectedIndex];
string name = listBoxFileNames.Items[listBoxFileNames.SelectedIndex].ToString();
string databaseName = _directoryPath + "Images.db";
Bitmap bmp = null; Bitmap bmp = null;
labelExpandCount.Text = string.Empty; labelExpandCount.Text = string.Empty;
labelImageInfo.Text = string.Empty; labelImageInfo.Text = string.Empty;
@ -326,19 +258,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
} }
else if (File.Exists(databaseName))
{
using (var f = new FileStream(databaseName, FileMode.Open))
{
if (name.Contains(']'))
{
name = name.Substring(name.IndexOf(']') + 1).Trim();
}
f.Position = Convert.ToInt64(name);
bmp = new ManagedBitmap(f).ToOldBitmap();
}
}
if (bmp == null) if (bmp == null)
{ {
@ -402,7 +321,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
return; return;
} }
string target = GetSelectedFileName();
string newText = textBoxText.Text; string newText = textBoxText.Text;
int oldTextItem = comboBoxTexts.SelectedIndex; int oldTextItem = comboBoxTexts.SelectedIndex;
int oldListBoxFileNamesIndex = listBoxFileNames.SelectedIndex; int oldListBoxFileNamesIndex = listBoxFileNames.SelectedIndex;
@ -472,74 +390,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
listBoxFileNames.Focus(); listBoxFileNames.Focus();
return;
}
XmlNode node = _compareDoc.DocumentElement.SelectSingleNode("Item[.='" + target + "']");
if (node != null)
{
node.Attributes["Text"].InnerText = newText;
if (Additions != null && Additions.Count > 0)
{
foreach (var a in Additions)
{
if (target.StartsWith(a.Name, StringComparison.Ordinal))
{
a.Text = newText;
a.Italic = checkBoxItalic.Checked;
break;
}
}
}
if (checkBoxItalic.Checked)
{
if (node.Attributes["Italic"] == null)
{
XmlAttribute italic = node.OwnerDocument.CreateAttribute("Italic");
italic.InnerText = "true";
node.Attributes.Append(italic);
}
}
else
{
if (node.Attributes["Italic"] != null)
{
node.Attributes.RemoveNamedItem("Italic");
}
}
Refill(Additions);
if (Additions == null || Additions.Count == 0)
{
for (int i = 0; i < comboBoxTexts.Items.Count; i++)
{
if (comboBoxTexts.Items[i].ToString() == newText)
{
comboBoxTexts.SelectedIndex = i;
for (int j = 0; j < listBoxFileNames.Items.Count; j++)
{
if (GetFileName(j).StartsWith(target, StringComparison.Ordinal))
{
listBoxFileNames.SelectedIndex = j;
}
}
return;
}
}
}
else
{
for (int i = 0; i < listBoxFileNames.Items.Count; i++)
{
if (listBoxFileNames.Items[i].ToString().Contains(target))
{
listBoxFileNames.SelectedIndex = i;
return;
}
}
}
} }
} }
@ -551,7 +401,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
int oldComboBoxIndex = comboBoxTexts.SelectedIndex; int oldComboBoxIndex = comboBoxTexts.SelectedIndex;
string target = GetSelectedFileName();
if (_binOcrDb != null) if (_binOcrDb != null)
{ {
@ -585,35 +434,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
comboBoxTexts.SelectedIndex = oldComboBoxIndex; comboBoxTexts.SelectedIndex = oldComboBoxIndex;
} }
return;
}
XmlNode node = _compareDoc.DocumentElement.SelectSingleNode("Item[.='" + target + "']");
if (node != null)
{
_compareDoc.DocumentElement.RemoveChild(node);
if (Additions != null && Additions.Count > 0)
{
for (int i = Additions.Count - 1; i >= 0; i--)
{
if (Additions[i].Name == target)
{
Additions.RemoveAt(i);
Refill(Additions);
break;
}
}
}
Refill(Additions);
if (Additions == null || Additions.Count == 0)
{
if (oldComboBoxIndex < comboBoxTexts.Items.Count)
{
comboBoxTexts.SelectedIndex = oldComboBoxIndex;
}
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private List<VobSubOcr.CompareMatch> _matchList; private List<VobSubOcr.CompareMatch> _matchList;
private List<NOcrChar> _nocrChars; private List<NOcrChar> _nocrChars;
private NOcrChar _nocrChar; private NOcrChar _nocrChar;
private NOcrDb _nocrDb;
private VobSubOcr _vobSubOcr; private VobSubOcr _vobSubOcr;
private Bitmap _bitmap; private Bitmap _bitmap;
private Bitmap _bitmap2; private Bitmap _bitmap2;
@ -25,6 +26,32 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
InitializeComponent(); InitializeComponent();
UiUtil.FixFonts(this); UiUtil.FixFonts(this);
labelImageSize.Text = string.Empty; labelImageSize.Text = string.Empty;
foreach (ToolStripItem toolStripItem in contextMenuStripLetters.Items)
{
if (toolStripItem is ToolStripDropDownItem i && i.HasDropDownItems)
{
foreach (ToolStripItem item in i.DropDownItems)
{
item.Click += InsertLanguageCharacter;
}
}
else
{
toolStripItem.Click += InsertLanguageCharacter;
}
}
}
private void InsertLanguageCharacter(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem toolStripMenuItem)
{
var start = textBoxText.SelectionStart;
textBoxText.SelectedText = toolStripMenuItem.Text;
textBoxText.SelectionLength = 0;
textBoxText.SelectionStart = start + toolStripMenuItem.Text.Length;
}
} }
private void VobSubNOcrCharacterInspect_KeyDown(object sender, KeyEventArgs e) private void VobSubNOcrCharacterInspect_KeyDown(object sender, KeyEventArgs e)
@ -43,6 +70,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
bitmap = nbmp.GetBitmap(); bitmap = nbmp.GetBitmap();
_bitmap2 = bitmap; _bitmap2 = bitmap;
_nocrChars = nOcrDb.OcrCharacters; _nocrChars = nOcrDb.OcrCharacters;
_nocrDb = nOcrDb;
_matchList = new List<VobSubOcr.CompareMatch>(); _matchList = new List<VobSubOcr.CompareMatch>();
_vobSubOcr = vobSubOcr; _vobSubOcr = vobSubOcr;
@ -309,8 +337,21 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonEditDB_Click(object sender, EventArgs e) private void buttonEditDB_Click(object sender, EventArgs e)
{ {
var form = new VobSubNOcrEdit(_nocrChars, pictureBoxInspectItem.Image as Bitmap, null); var form = new VobSubNOcrEdit(_nocrDb, pictureBoxInspectItem.Image as Bitmap, null);
form.ShowDialog(this); form.ShowDialog(this);
} }
private void addBetterMultiMatchToolStripMenuItem_Click(object sender, EventArgs e)
{
using (var form = new AddBetterMultiMatchNOcr())
{
// form.Initialize(listBoxInspectItems.SelectedIndex, _matches, _splitterItems);
if (form.ShowDialog(this) == DialogResult.OK)
{
//_binOcrDb.Add(form.ExpandedMatch);
DialogResult = DialogResult.OK;
}
}
}
} }
} }

View File

@ -117,4 +117,10 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="contextMenuStripAddBetterMultiMatch.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="contextMenuStripLetters.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>202, 17</value>
</metadata>
</root> </root>

View File

@ -191,6 +191,7 @@
this.listBoxlinesBackground.Size = new System.Drawing.Size(151, 95); this.listBoxlinesBackground.Size = new System.Drawing.Size(151, 95);
this.listBoxlinesBackground.TabIndex = 40; this.listBoxlinesBackground.TabIndex = 40;
this.listBoxlinesBackground.SelectedIndexChanged += new System.EventHandler(this.listBoxlinesBackground_SelectedIndexChanged); this.listBoxlinesBackground.SelectedIndexChanged += new System.EventHandler(this.listBoxlinesBackground_SelectedIndexChanged);
this.listBoxlinesBackground.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listBoxlinesBackground_KeyDown);
// //
// contextMenuStripLinesBackground // contextMenuStripLinesBackground
// //
@ -224,6 +225,7 @@
this.listBoxLinesForeground.Size = new System.Drawing.Size(151, 95); this.listBoxLinesForeground.Size = new System.Drawing.Size(151, 95);
this.listBoxLinesForeground.TabIndex = 38; this.listBoxLinesForeground.TabIndex = 38;
this.listBoxLinesForeground.SelectedIndexChanged += new System.EventHandler(this.listBoxLinesForeground_SelectedIndexChanged); this.listBoxLinesForeground.SelectedIndexChanged += new System.EventHandler(this.listBoxLinesForeground_SelectedIndexChanged);
this.listBoxLinesForeground.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listBoxLinesForeground_KeyDown);
// //
// contextMenuLinesForeground // contextMenuLinesForeground
// //
@ -387,7 +389,7 @@
this.ShowIcon = false; this.ShowIcon = false;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "VobSubNOcrEdit"; this.Text = "nOCR DB";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.VobSubNOcrEdit_KeyDown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.VobSubNOcrEdit_KeyDown);
this.groupBoxCurrentCompareImage.ResumeLayout(false); this.groupBoxCurrentCompareImage.ResumeLayout(false);
this.groupBoxCurrentCompareImage.PerformLayout(); this.groupBoxCurrentCompareImage.PerformLayout();

View File

@ -24,13 +24,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private int _historyIndex = -1; private int _historyIndex = -1;
public bool Changed { get; private set; } public bool Changed { get; private set; }
public VobSubNOcrEdit(List<NOcrChar> nocrChars, Bitmap bitmap, string fileName) public VobSubNOcrEdit(NOcrDb nOcrDb, Bitmap bitmap, string fileName)
{ {
UiUtil.PreInitialize(this); UiUtil.PreInitialize(this);
InitializeComponent(); InitializeComponent();
UiUtil.FixFonts(this); UiUtil.FixFonts(this);
_nocrChars = nocrChars; _nocrChars = nOcrDb.OcrCharacters;
_bitmap = bitmap; _bitmap = bitmap;
FillComboBox(); FillComboBox();
@ -41,7 +41,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
SizePictureBox(); SizePictureBox();
} }
labelInfo.Text = $"{nocrChars.Count:#,###,##0} elements in database"; labelInfo.Text = $"{_nocrChars.Count:#,###,##0} elements in database";
labelNOcrCharInfo.Text = string.Empty; labelNOcrCharInfo.Text = string.Empty;
if (!string.IsNullOrEmpty(fileName)) if (!string.IsNullOrEmpty(fileName))
{ {
@ -575,5 +575,22 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
private void listBoxLinesForeground_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
e.SuppressKeyPress = true;
removeForegroundToolStripMenuItem_Click(null, null);
}
}
private void listBoxlinesBackground_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
e.SuppressKeyPress = true;
removeBackToolStripMenuItem_Click(null, null);
}
}
} }
} }

View File

@ -64,7 +64,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void buttonTrain_Click(object sender, EventArgs e) private void buttonTrain_Click(object sender, EventArgs e)
{ {
if (buttonTrain.Text == "Abort") if (buttonTrain.Text == Configuration.Settings.Language.SpellCheck.Abort)
{ {
_abort = true; _abort = true;
return; return;
@ -76,7 +76,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
_abort = false; _abort = false;
buttonTrain.Text = "Abort"; buttonTrain.Text = Configuration.Settings.Language.SpellCheck.Abort;
buttonOK.Enabled = false; buttonOK.Enabled = false;
int numberOfCharactersLeaned = 0; int numberOfCharactersLeaned = 0;
@ -155,14 +155,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void TrainLetter(ref int numberOfCharactersLeaned, ref int numberOfCharactersSkipped, NOcrDb nOcrD, List<string> charactersLearned, string s, bool bold) private void TrainLetter(ref int numberOfCharactersLeaned, ref int numberOfCharactersSkipped, NOcrDb nOcrD, List<string> charactersLearned, string s, bool bold)
{ {
Bitmap bmp = GenerateImageFromTextWithStyle("H " + s, bold); Bitmap bmp = GenerateImageFromTextWithStyle("H " + s, bold);
var nbmp = new NikseBitmap(bmp); var nikseBitmap = new NikseBitmap(bmp);
nbmp.MakeTwoColor(280); nikseBitmap.MakeTwoColor(280);
nbmp.CropTop(0, Color.FromArgb(0, 0, 0, 0)); nikseBitmap.CropTop(0, Color.FromArgb(0, 0, 0, 0));
var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nbmp, 10, false, false, 25); var list = NikseBitmapImageSplitter.SplitBitmapToLettersNew(nikseBitmap, 10, false, false, 25);
if (list.Count == 3) if (list.Count == 3)
{ {
var item = list[2]; var item = list[2];
NOcrChar match = nOcrD.GetMatch(item.NikseBitmap, item.Top, false, false, 0); var match = nOcrD.GetMatch(item.NikseBitmap, item.Top, false, false, 0, 25);
if (match == null || match.Text != s) if (match == null || match.Text != s)
{ {
labelInfo.Refresh(); labelInfo.Refresh();
@ -186,6 +186,57 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
numberOfCharactersSkipped++; numberOfCharactersSkipped++;
} }
} }
else
{
if (list.Count == 4)
{
// e.g. quote (")
var expandItem = VobSubOcr.GetExpandedSelectionNew(nikseBitmap, new List<ImageSplitterItem> { list[2], list[3] });
var match = nOcrD.GetMatchExpanded(nikseBitmap, expandItem);
if (match != null && match.Text == s)
{
numberOfCharactersSkipped++;
return;
}
var nOcrChar = new NOcrChar(s)
{
Width = expandItem.NikseBitmap.Width,
Height = expandItem.NikseBitmap.Height,
MarginTop = expandItem.Top,
ExpandCount = 2,
};
VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value + 5, checkBoxVeryAccurate.Checked, nOcrChar, expandItem.NikseBitmap);
nOcrD.Add(nOcrChar);
return;
}
if (list.Count == 5)
{
// e.g. "%"
var expandItem = VobSubOcr.GetExpandedSelectionNew(nikseBitmap, new List<ImageSplitterItem> { list[2], list[3], list[4] });
var match = nOcrD.GetMatchExpanded(nikseBitmap, expandItem);
if (match != null && match.Text == s)
{
numberOfCharactersSkipped++;
return;
}
var nOcrChar = new NOcrChar(s)
{
Width = expandItem.NikseBitmap.Width,
Height = expandItem.NikseBitmap.Height,
MarginTop = expandItem.Top,
ExpandCount = 3,
};
nOcrD.Add(nOcrChar);
VobSubOcrNOcrCharacter.GenerateLineSegments((int)numericUpDownSegmentsPerCharacter.Value + 10, checkBoxVeryAccurate.Checked, nOcrChar, expandItem.NikseBitmap);
return;
}
numberOfCharactersSkipped++;
}
} }
private Bitmap GenerateImageFromTextWithStyle(string text, bool bold) private Bitmap GenerateImageFromTextWithStyle(string text, bool bold)

View File

@ -51,28 +51,17 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxOcrMethod = new System.Windows.Forms.GroupBox(); this.groupBoxOcrMethod = new System.Windows.Forms.GroupBox();
this.comboBoxOcrMethod = new System.Windows.Forms.ComboBox(); this.comboBoxOcrMethod = new System.Windows.Forms.ComboBox();
this.groupBoxNOCR = new System.Windows.Forms.GroupBox();
this.buttonLineOcrEditLanguage = new System.Windows.Forms.Button();
this.buttonLineOcrNewLanguage = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxNOcrLanguage = new System.Windows.Forms.ComboBox();
this.checkBoxNOcrItalic = new System.Windows.Forms.CheckBox();
this.checkBoxNOcrCorrect = new System.Windows.Forms.CheckBox();
this.checkBoxRightToLeftNOCR = new System.Windows.Forms.CheckBox();
this.numericUpDownNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.NumericUpDown();
this.labelNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.Label();
this.groupBoxImageCompareMethod = new System.Windows.Forms.GroupBox(); this.groupBoxImageCompareMethod = new System.Windows.Forms.GroupBox();
this.buttonChooseEditBinaryImageCompareDb = new System.Windows.Forms.Button();
this.labelMinLineSplitHeight = new System.Windows.Forms.Label(); this.labelMinLineSplitHeight = new System.Windows.Forms.Label();
this.comboBoxLineSplitMinLineHeight = new System.Windows.Forms.ComboBox(); this.comboBoxLineSplitMinLineHeight = new System.Windows.Forms.ComboBox();
this.labelMaxErrorPercent = new System.Windows.Forms.Label(); this.labelMaxErrorPercent = new System.Windows.Forms.Label();
this.numericUpDownMaxErrorPct = new System.Windows.Forms.NumericUpDown(); this.numericUpDownMaxErrorPct = new System.Windows.Forms.NumericUpDown();
this.checkBoxRightToLeft = new System.Windows.Forms.CheckBox(); this.checkBoxRightToLeft = new System.Windows.Forms.CheckBox();
this.numericUpDownPixelsIsSpace = new System.Windows.Forms.NumericUpDown(); this.numericUpDownPixelsIsSpace = new System.Windows.Forms.NumericUpDown();
this.buttonEditCharacterDatabase = new System.Windows.Forms.Button();
this.labelNoOfPixelsIsSpace = new System.Windows.Forms.Label(); this.labelNoOfPixelsIsSpace = new System.Windows.Forms.Label();
this.comboBoxCharacterDatabase = new System.Windows.Forms.ComboBox(); this.comboBoxCharacterDatabase = new System.Windows.Forms.ComboBox();
this.labelImageDatabase = new System.Windows.Forms.Label(); this.labelImageDatabase = new System.Windows.Forms.Label();
this.buttonNewCharacterDatabase = new System.Windows.Forms.Button();
this.GroupBoxTesseractMethod = new System.Windows.Forms.GroupBox(); this.GroupBoxTesseractMethod = new System.Windows.Forms.GroupBox();
this.checkBoxTesseractFallback = new System.Windows.Forms.CheckBox(); this.checkBoxTesseractFallback = new System.Windows.Forms.CheckBox();
this.labelTesseractEngineMode = new System.Windows.Forms.Label(); this.labelTesseractEngineMode = new System.Windows.Forms.Label();
@ -85,6 +74,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.groupBoxModiMethod = new System.Windows.Forms.GroupBox(); this.groupBoxModiMethod = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.comboBoxModiLanguage = new System.Windows.Forms.ComboBox(); this.comboBoxModiLanguage = new System.Windows.Forms.ComboBox();
this.groupBoxNOCR = new System.Windows.Forms.GroupBox();
this.numericUpDownNOcrMaxWrongPixels = new System.Windows.Forms.NumericUpDown();
this.labelNOcrMaxWrongPixels = new System.Windows.Forms.Label();
this.buttonLineOcrEditLanguage = new System.Windows.Forms.Button();
this.buttonLineOcrNewLanguage = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxNOcrLanguage = new System.Windows.Forms.ComboBox();
this.checkBoxNOcrItalic = new System.Windows.Forms.CheckBox();
this.checkBoxNOcrCorrect = new System.Windows.Forms.CheckBox();
this.checkBoxRightToLeftNOCR = new System.Windows.Forms.CheckBox();
this.numericUpDownNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.NumericUpDown();
this.labelNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.Label();
this.groupBoxOCRControls = new System.Windows.Forms.GroupBox(); this.groupBoxOCRControls = new System.Windows.Forms.GroupBox();
this.labelStartFrom = new System.Windows.Forms.Label(); this.labelStartFrom = new System.Windows.Forms.Label();
this.numericUpDownStartNumber = new System.Windows.Forms.NumericUpDown(); this.numericUpDownStartNumber = new System.Windows.Forms.NumericUpDown();
@ -153,13 +154,14 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.timerHideStatus = new System.Windows.Forms.Timer(this.components); this.timerHideStatus = new System.Windows.Forms.Timer(this.components);
this.contextMenuStripListview.SuspendLayout(); this.contextMenuStripListview.SuspendLayout();
this.groupBoxOcrMethod.SuspendLayout(); this.groupBoxOcrMethod.SuspendLayout();
this.groupBoxNOCR.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).BeginInit();
this.groupBoxImageCompareMethod.SuspendLayout(); this.groupBoxImageCompareMethod.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxErrorPct)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxErrorPct)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPixelsIsSpace)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPixelsIsSpace)).BeginInit();
this.GroupBoxTesseractMethod.SuspendLayout(); this.GroupBoxTesseractMethod.SuspendLayout();
this.groupBoxModiMethod.SuspendLayout(); this.groupBoxModiMethod.SuspendLayout();
this.groupBoxNOCR.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNOcrMaxWrongPixels)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).BeginInit();
this.groupBoxOCRControls.SuspendLayout(); this.groupBoxOCRControls.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownStartNumber)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownStartNumber)).BeginInit();
this.groupBoxOcrAutoFix.SuspendLayout(); this.groupBoxOcrAutoFix.SuspendLayout();
@ -466,137 +468,18 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.comboBoxOcrMethod.TabIndex = 0; this.comboBoxOcrMethod.TabIndex = 0;
this.comboBoxOcrMethod.SelectedIndexChanged += new System.EventHandler(this.ComboBoxOcrMethodSelectedIndexChanged); this.comboBoxOcrMethod.SelectedIndexChanged += new System.EventHandler(this.ComboBoxOcrMethodSelectedIndexChanged);
// //
// groupBoxNOCR
//
this.groupBoxNOCR.Controls.Add(this.buttonLineOcrEditLanguage);
this.groupBoxNOCR.Controls.Add(this.buttonLineOcrNewLanguage);
this.groupBoxNOCR.Controls.Add(this.label2);
this.groupBoxNOCR.Controls.Add(this.comboBoxNOcrLanguage);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrItalic);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrCorrect);
this.groupBoxNOCR.Controls.Add(this.checkBoxRightToLeftNOCR);
this.groupBoxNOCR.Controls.Add(this.numericUpDownNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Controls.Add(this.labelNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Location = new System.Drawing.Point(7, 38);
this.groupBoxNOCR.Name = "groupBoxNOCR";
this.groupBoxNOCR.Size = new System.Drawing.Size(366, 131);
this.groupBoxNOCR.TabIndex = 7;
this.groupBoxNOCR.TabStop = false;
this.groupBoxNOCR.Text = "nOCR";
//
// buttonLineOcrEditLanguage
//
this.buttonLineOcrEditLanguage.Location = new System.Drawing.Point(210, 97);
this.buttonLineOcrEditLanguage.Name = "buttonLineOcrEditLanguage";
this.buttonLineOcrEditLanguage.Size = new System.Drawing.Size(68, 23);
this.buttonLineOcrEditLanguage.TabIndex = 41;
this.buttonLineOcrEditLanguage.Text = "Edit";
this.buttonLineOcrEditLanguage.UseVisualStyleBackColor = true;
this.buttonLineOcrEditLanguage.Click += new System.EventHandler(this.buttonLineOcrEditLanguage_Click);
//
// buttonLineOcrNewLanguage
//
this.buttonLineOcrNewLanguage.Location = new System.Drawing.Point(283, 97);
this.buttonLineOcrNewLanguage.Name = "buttonLineOcrNewLanguage";
this.buttonLineOcrNewLanguage.Size = new System.Drawing.Size(68, 23);
this.buttonLineOcrNewLanguage.TabIndex = 40;
this.buttonLineOcrNewLanguage.Text = "New";
this.buttonLineOcrNewLanguage.UseVisualStyleBackColor = true;
this.buttonLineOcrNewLanguage.Click += new System.EventHandler(this.buttonLineOcrNewLanguage_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(11, 101);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 13);
this.label2.TabIndex = 35;
this.label2.Text = "Language";
//
// comboBoxNOcrLanguage
//
this.comboBoxNOcrLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxNOcrLanguage.FormattingEnabled = true;
this.comboBoxNOcrLanguage.Location = new System.Drawing.Point(74, 97);
this.comboBoxNOcrLanguage.Name = "comboBoxNOcrLanguage";
this.comboBoxNOcrLanguage.Size = new System.Drawing.Size(130, 21);
this.comboBoxNOcrLanguage.TabIndex = 34;
this.comboBoxNOcrLanguage.SelectedIndexChanged += new System.EventHandler(this.comboBoxNOcrLanguage_SelectedIndexChanged);
//
// checkBoxNOcrItalic
//
this.checkBoxNOcrItalic.AutoSize = true;
this.checkBoxNOcrItalic.Location = new System.Drawing.Point(15, 42);
this.checkBoxNOcrItalic.Name = "checkBoxNOcrItalic";
this.checkBoxNOcrItalic.Size = new System.Drawing.Size(92, 17);
this.checkBoxNOcrItalic.TabIndex = 8;
this.checkBoxNOcrItalic.Text = "Contains italic";
this.checkBoxNOcrItalic.UseVisualStyleBackColor = true;
//
// checkBoxNOcrCorrect
//
this.checkBoxNOcrCorrect.AutoSize = true;
this.checkBoxNOcrCorrect.Location = new System.Drawing.Point(235, 17);
this.checkBoxNOcrCorrect.Name = "checkBoxNOcrCorrect";
this.checkBoxNOcrCorrect.Size = new System.Drawing.Size(116, 17);
this.checkBoxNOcrCorrect.TabIndex = 7;
this.checkBoxNOcrCorrect.Text = "Draw missing texts";
this.checkBoxNOcrCorrect.UseVisualStyleBackColor = true;
//
// checkBoxRightToLeftNOCR
//
this.checkBoxRightToLeftNOCR.AutoSize = true;
this.checkBoxRightToLeftNOCR.Location = new System.Drawing.Point(235, 40);
this.checkBoxRightToLeftNOCR.Name = "checkBoxRightToLeftNOCR";
this.checkBoxRightToLeftNOCR.Size = new System.Drawing.Size(83, 17);
this.checkBoxRightToLeftNOCR.TabIndex = 6;
this.checkBoxRightToLeftNOCR.Text = "Right to left";
this.checkBoxRightToLeftNOCR.UseVisualStyleBackColor = true;
//
// numericUpDownNumberOfPixelsIsSpaceNOCR
//
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(122, 17);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Maximum = new decimal(new int[] {
50,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Name = "numericUpDownNumberOfPixelsIsSpaceNOCR";
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(50, 21);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.TabIndex = 5;
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Value = new decimal(new int[] {
12,
0,
0,
0});
//
// labelNumberOfPixelsIsSpaceNOCR
//
this.labelNumberOfPixelsIsSpaceNOCR.AutoSize = true;
this.labelNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(12, 20);
this.labelNumberOfPixelsIsSpaceNOCR.Name = "labelNumberOfPixelsIsSpaceNOCR";
this.labelNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(104, 13);
this.labelNumberOfPixelsIsSpaceNOCR.TabIndex = 4;
this.labelNumberOfPixelsIsSpaceNOCR.Text = "No of pixels is space";
//
// groupBoxImageCompareMethod // groupBoxImageCompareMethod
// //
this.groupBoxImageCompareMethod.Controls.Add(this.buttonChooseEditBinaryImageCompareDb);
this.groupBoxImageCompareMethod.Controls.Add(this.labelMinLineSplitHeight); this.groupBoxImageCompareMethod.Controls.Add(this.labelMinLineSplitHeight);
this.groupBoxImageCompareMethod.Controls.Add(this.comboBoxLineSplitMinLineHeight); this.groupBoxImageCompareMethod.Controls.Add(this.comboBoxLineSplitMinLineHeight);
this.groupBoxImageCompareMethod.Controls.Add(this.labelMaxErrorPercent); this.groupBoxImageCompareMethod.Controls.Add(this.labelMaxErrorPercent);
this.groupBoxImageCompareMethod.Controls.Add(this.numericUpDownMaxErrorPct); this.groupBoxImageCompareMethod.Controls.Add(this.numericUpDownMaxErrorPct);
this.groupBoxImageCompareMethod.Controls.Add(this.checkBoxRightToLeft); this.groupBoxImageCompareMethod.Controls.Add(this.checkBoxRightToLeft);
this.groupBoxImageCompareMethod.Controls.Add(this.numericUpDownPixelsIsSpace); this.groupBoxImageCompareMethod.Controls.Add(this.numericUpDownPixelsIsSpace);
this.groupBoxImageCompareMethod.Controls.Add(this.buttonEditCharacterDatabase);
this.groupBoxImageCompareMethod.Controls.Add(this.labelNoOfPixelsIsSpace); this.groupBoxImageCompareMethod.Controls.Add(this.labelNoOfPixelsIsSpace);
this.groupBoxImageCompareMethod.Controls.Add(this.comboBoxCharacterDatabase); this.groupBoxImageCompareMethod.Controls.Add(this.comboBoxCharacterDatabase);
this.groupBoxImageCompareMethod.Controls.Add(this.labelImageDatabase); this.groupBoxImageCompareMethod.Controls.Add(this.labelImageDatabase);
this.groupBoxImageCompareMethod.Controls.Add(this.buttonNewCharacterDatabase);
this.groupBoxImageCompareMethod.Location = new System.Drawing.Point(13, 38); this.groupBoxImageCompareMethod.Location = new System.Drawing.Point(13, 38);
this.groupBoxImageCompareMethod.Name = "groupBoxImageCompareMethod"; this.groupBoxImageCompareMethod.Name = "groupBoxImageCompareMethod";
this.groupBoxImageCompareMethod.Size = new System.Drawing.Size(366, 131); this.groupBoxImageCompareMethod.Size = new System.Drawing.Size(366, 131);
@ -604,6 +487,16 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.groupBoxImageCompareMethod.TabStop = false; this.groupBoxImageCompareMethod.TabStop = false;
this.groupBoxImageCompareMethod.Text = "Image compare"; this.groupBoxImageCompareMethod.Text = "Image compare";
// //
// buttonChooseEditBinaryImageCompareDb
//
this.buttonChooseEditBinaryImageCompareDb.Location = new System.Drawing.Point(318, 17);
this.buttonChooseEditBinaryImageCompareDb.Name = "buttonChooseEditBinaryImageCompareDb";
this.buttonChooseEditBinaryImageCompareDb.Size = new System.Drawing.Size(28, 23);
this.buttonChooseEditBinaryImageCompareDb.TabIndex = 48;
this.buttonChooseEditBinaryImageCompareDb.Text = "...";
this.buttonChooseEditBinaryImageCompareDb.UseVisualStyleBackColor = true;
this.buttonChooseEditBinaryImageCompareDb.Click += new System.EventHandler(this.buttonChooseEditBinaryImageCompareDb_Click);
//
// labelMinLineSplitHeight // labelMinLineSplitHeight
// //
this.labelMinLineSplitHeight.AutoSize = true; this.labelMinLineSplitHeight.AutoSize = true;
@ -759,16 +652,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
0}); 0});
this.numericUpDownPixelsIsSpace.ValueChanged += new System.EventHandler(this.numericUpDownPixelsIsSpace_ValueChanged); this.numericUpDownPixelsIsSpace.ValueChanged += new System.EventHandler(this.numericUpDownPixelsIsSpace_ValueChanged);
// //
// buttonEditCharacterDatabase
//
this.buttonEditCharacterDatabase.Location = new System.Drawing.Point(278, 48);
this.buttonEditCharacterDatabase.Name = "buttonEditCharacterDatabase";
this.buttonEditCharacterDatabase.Size = new System.Drawing.Size(76, 23);
this.buttonEditCharacterDatabase.TabIndex = 3;
this.buttonEditCharacterDatabase.Text = "Edit";
this.buttonEditCharacterDatabase.UseVisualStyleBackColor = true;
this.buttonEditCharacterDatabase.Click += new System.EventHandler(this.ButtonEditCharacterDatabaseClick);
//
// labelNoOfPixelsIsSpace // labelNoOfPixelsIsSpace
// //
this.labelNoOfPixelsIsSpace.AutoSize = true; this.labelNoOfPixelsIsSpace.AutoSize = true;
@ -784,7 +667,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.comboBoxCharacterDatabase.FormattingEnabled = true; this.comboBoxCharacterDatabase.FormattingEnabled = true;
this.comboBoxCharacterDatabase.Location = new System.Drawing.Point(130, 19); this.comboBoxCharacterDatabase.Location = new System.Drawing.Point(130, 19);
this.comboBoxCharacterDatabase.Name = "comboBoxCharacterDatabase"; this.comboBoxCharacterDatabase.Name = "comboBoxCharacterDatabase";
this.comboBoxCharacterDatabase.Size = new System.Drawing.Size(142, 21); this.comboBoxCharacterDatabase.Size = new System.Drawing.Size(182, 21);
this.comboBoxCharacterDatabase.TabIndex = 1; this.comboBoxCharacterDatabase.TabIndex = 1;
this.comboBoxCharacterDatabase.SelectedIndexChanged += new System.EventHandler(this.ComboBoxCharacterDatabaseSelectedIndexChanged); this.comboBoxCharacterDatabase.SelectedIndexChanged += new System.EventHandler(this.ComboBoxCharacterDatabaseSelectedIndexChanged);
// //
@ -797,16 +680,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.labelImageDatabase.TabIndex = 0; this.labelImageDatabase.TabIndex = 0;
this.labelImageDatabase.Text = "Image database"; this.labelImageDatabase.Text = "Image database";
// //
// buttonNewCharacterDatabase
//
this.buttonNewCharacterDatabase.Location = new System.Drawing.Point(278, 19);
this.buttonNewCharacterDatabase.Name = "buttonNewCharacterDatabase";
this.buttonNewCharacterDatabase.Size = new System.Drawing.Size(76, 23);
this.buttonNewCharacterDatabase.TabIndex = 2;
this.buttonNewCharacterDatabase.Text = "New";
this.buttonNewCharacterDatabase.UseVisualStyleBackColor = true;
this.buttonNewCharacterDatabase.Click += new System.EventHandler(this.ButtonNewCharacterDatabaseClick);
//
// GroupBoxTesseractMethod // GroupBoxTesseractMethod
// //
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractFallback); this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractFallback);
@ -941,6 +814,152 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.comboBoxModiLanguage.TabIndex = 0; this.comboBoxModiLanguage.TabIndex = 0;
this.comboBoxModiLanguage.SelectedIndexChanged += new System.EventHandler(this.ComboBoxModiLanguageSelectedIndexChanged); this.comboBoxModiLanguage.SelectedIndexChanged += new System.EventHandler(this.ComboBoxModiLanguageSelectedIndexChanged);
// //
// groupBoxNOCR
//
this.groupBoxNOCR.Controls.Add(this.numericUpDownNOcrMaxWrongPixels);
this.groupBoxNOCR.Controls.Add(this.labelNOcrMaxWrongPixels);
this.groupBoxNOCR.Controls.Add(this.buttonLineOcrEditLanguage);
this.groupBoxNOCR.Controls.Add(this.buttonLineOcrNewLanguage);
this.groupBoxNOCR.Controls.Add(this.label2);
this.groupBoxNOCR.Controls.Add(this.comboBoxNOcrLanguage);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrItalic);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrCorrect);
this.groupBoxNOCR.Controls.Add(this.checkBoxRightToLeftNOCR);
this.groupBoxNOCR.Controls.Add(this.numericUpDownNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Controls.Add(this.labelNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Location = new System.Drawing.Point(7, 38);
this.groupBoxNOCR.Name = "groupBoxNOCR";
this.groupBoxNOCR.Size = new System.Drawing.Size(366, 131);
this.groupBoxNOCR.TabIndex = 7;
this.groupBoxNOCR.TabStop = false;
this.groupBoxNOCR.Text = "nOCR";
//
// numericUpDownNOcrMaxWrongPixels
//
this.numericUpDownNOcrMaxWrongPixels.Location = new System.Drawing.Point(123, 45);
this.numericUpDownNOcrMaxWrongPixels.Maximum = new decimal(new int[] {
50,
0,
0,
0});
this.numericUpDownNOcrMaxWrongPixels.Name = "numericUpDownNOcrMaxWrongPixels";
this.numericUpDownNOcrMaxWrongPixels.Size = new System.Drawing.Size(50, 21);
this.numericUpDownNOcrMaxWrongPixels.TabIndex = 43;
this.numericUpDownNOcrMaxWrongPixels.Value = new decimal(new int[] {
45,
0,
0,
0});
//
// labelNOcrMaxWrongPixels
//
this.labelNOcrMaxWrongPixels.AutoSize = true;
this.labelNOcrMaxWrongPixels.Location = new System.Drawing.Point(13, 48);
this.labelNOcrMaxWrongPixels.Name = "labelNOcrMaxWrongPixels";
this.labelNOcrMaxWrongPixels.Size = new System.Drawing.Size(90, 13);
this.labelNOcrMaxWrongPixels.TabIndex = 42;
this.labelNOcrMaxWrongPixels.Text = "Max wrong pixels";
//
// buttonLineOcrEditLanguage
//
this.buttonLineOcrEditLanguage.Location = new System.Drawing.Point(210, 97);
this.buttonLineOcrEditLanguage.Name = "buttonLineOcrEditLanguage";
this.buttonLineOcrEditLanguage.Size = new System.Drawing.Size(68, 23);
this.buttonLineOcrEditLanguage.TabIndex = 41;
this.buttonLineOcrEditLanguage.Text = "Edit";
this.buttonLineOcrEditLanguage.UseVisualStyleBackColor = true;
this.buttonLineOcrEditLanguage.Click += new System.EventHandler(this.buttonLineOcrEditLanguage_Click);
//
// buttonLineOcrNewLanguage
//
this.buttonLineOcrNewLanguage.Location = new System.Drawing.Point(283, 97);
this.buttonLineOcrNewLanguage.Name = "buttonLineOcrNewLanguage";
this.buttonLineOcrNewLanguage.Size = new System.Drawing.Size(68, 23);
this.buttonLineOcrNewLanguage.TabIndex = 40;
this.buttonLineOcrNewLanguage.Text = "New";
this.buttonLineOcrNewLanguage.UseVisualStyleBackColor = true;
this.buttonLineOcrNewLanguage.Click += new System.EventHandler(this.buttonLineOcrNewLanguage_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(11, 101);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 13);
this.label2.TabIndex = 35;
this.label2.Text = "Language";
//
// comboBoxNOcrLanguage
//
this.comboBoxNOcrLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxNOcrLanguage.FormattingEnabled = true;
this.comboBoxNOcrLanguage.Location = new System.Drawing.Point(74, 97);
this.comboBoxNOcrLanguage.Name = "comboBoxNOcrLanguage";
this.comboBoxNOcrLanguage.Size = new System.Drawing.Size(130, 21);
this.comboBoxNOcrLanguage.TabIndex = 34;
this.comboBoxNOcrLanguage.SelectedIndexChanged += new System.EventHandler(this.comboBoxNOcrLanguage_SelectedIndexChanged);
//
// checkBoxNOcrItalic
//
this.checkBoxNOcrItalic.AutoSize = true;
this.checkBoxNOcrItalic.Location = new System.Drawing.Point(12, 67);
this.checkBoxNOcrItalic.Name = "checkBoxNOcrItalic";
this.checkBoxNOcrItalic.Size = new System.Drawing.Size(92, 17);
this.checkBoxNOcrItalic.TabIndex = 8;
this.checkBoxNOcrItalic.Text = "Contains italic";
this.checkBoxNOcrItalic.UseVisualStyleBackColor = true;
//
// checkBoxNOcrCorrect
//
this.checkBoxNOcrCorrect.AutoSize = true;
this.checkBoxNOcrCorrect.Location = new System.Drawing.Point(235, 17);
this.checkBoxNOcrCorrect.Name = "checkBoxNOcrCorrect";
this.checkBoxNOcrCorrect.Size = new System.Drawing.Size(116, 17);
this.checkBoxNOcrCorrect.TabIndex = 7;
this.checkBoxNOcrCorrect.Text = "Draw missing texts";
this.checkBoxNOcrCorrect.UseVisualStyleBackColor = true;
//
// checkBoxRightToLeftNOCR
//
this.checkBoxRightToLeftNOCR.AutoSize = true;
this.checkBoxRightToLeftNOCR.Location = new System.Drawing.Point(235, 40);
this.checkBoxRightToLeftNOCR.Name = "checkBoxRightToLeftNOCR";
this.checkBoxRightToLeftNOCR.Size = new System.Drawing.Size(83, 17);
this.checkBoxRightToLeftNOCR.TabIndex = 6;
this.checkBoxRightToLeftNOCR.Text = "Right to left";
this.checkBoxRightToLeftNOCR.UseVisualStyleBackColor = true;
//
// numericUpDownNumberOfPixelsIsSpaceNOCR
//
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(122, 17);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Maximum = new decimal(new int[] {
50,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Name = "numericUpDownNumberOfPixelsIsSpaceNOCR";
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(50, 21);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.TabIndex = 5;
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Value = new decimal(new int[] {
12,
0,
0,
0});
//
// labelNumberOfPixelsIsSpaceNOCR
//
this.labelNumberOfPixelsIsSpaceNOCR.AutoSize = true;
this.labelNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(12, 20);
this.labelNumberOfPixelsIsSpaceNOCR.Name = "labelNumberOfPixelsIsSpaceNOCR";
this.labelNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(104, 13);
this.labelNumberOfPixelsIsSpaceNOCR.TabIndex = 4;
this.labelNumberOfPixelsIsSpaceNOCR.Text = "No of pixels is space";
//
// groupBoxOCRControls // groupBoxOCRControls
// //
this.groupBoxOCRControls.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBoxOCRControls.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -1708,9 +1727,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.Resize += new System.EventHandler(this.VobSubOcr_Resize); this.Resize += new System.EventHandler(this.VobSubOcr_Resize);
this.contextMenuStripListview.ResumeLayout(false); this.contextMenuStripListview.ResumeLayout(false);
this.groupBoxOcrMethod.ResumeLayout(false); this.groupBoxOcrMethod.ResumeLayout(false);
this.groupBoxNOCR.ResumeLayout(false);
this.groupBoxNOCR.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).EndInit();
this.groupBoxImageCompareMethod.ResumeLayout(false); this.groupBoxImageCompareMethod.ResumeLayout(false);
this.groupBoxImageCompareMethod.PerformLayout(); this.groupBoxImageCompareMethod.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxErrorPct)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxErrorPct)).EndInit();
@ -1719,6 +1735,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
this.GroupBoxTesseractMethod.PerformLayout(); this.GroupBoxTesseractMethod.PerformLayout();
this.groupBoxModiMethod.ResumeLayout(false); this.groupBoxModiMethod.ResumeLayout(false);
this.groupBoxModiMethod.PerformLayout(); this.groupBoxModiMethod.PerformLayout();
this.groupBoxNOCR.ResumeLayout(false);
this.groupBoxNOCR.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNOcrMaxWrongPixels)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).EndInit();
this.groupBoxOCRControls.ResumeLayout(false); this.groupBoxOCRControls.ResumeLayout(false);
this.groupBoxOCRControls.PerformLayout(); this.groupBoxOCRControls.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownStartNumber)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownStartNumber)).EndInit();
@ -1781,11 +1801,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private System.Windows.Forms.ComboBox comboBoxOcrMethod; private System.Windows.Forms.ComboBox comboBoxOcrMethod;
private System.Windows.Forms.GroupBox groupBoxImageCompareMethod; private System.Windows.Forms.GroupBox groupBoxImageCompareMethod;
private System.Windows.Forms.NumericUpDown numericUpDownPixelsIsSpace; private System.Windows.Forms.NumericUpDown numericUpDownPixelsIsSpace;
private System.Windows.Forms.Button buttonEditCharacterDatabase;
private System.Windows.Forms.Label labelNoOfPixelsIsSpace; private System.Windows.Forms.Label labelNoOfPixelsIsSpace;
private System.Windows.Forms.ComboBox comboBoxCharacterDatabase; private System.Windows.Forms.ComboBox comboBoxCharacterDatabase;
private System.Windows.Forms.Label labelImageDatabase; private System.Windows.Forms.Label labelImageDatabase;
private System.Windows.Forms.Button buttonNewCharacterDatabase;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBoxModiMethod; private System.Windows.Forms.GroupBox groupBoxModiMethod;
private System.Windows.Forms.GroupBox GroupBoxTesseractMethod; private System.Windows.Forms.GroupBox GroupBoxTesseractMethod;
@ -1889,5 +1907,8 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private System.Windows.Forms.ToolStripMenuItem imagePreprocessingToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem imagePreprocessingToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem setItalicAngleToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem setItalicAngleToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem autoTransparentBackgroundToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem autoTransparentBackgroundToolStripMenuItem;
private System.Windows.Forms.NumericUpDown numericUpDownNOcrMaxWrongPixels;
private System.Windows.Forms.Label labelNOcrMaxWrongPixels;
private System.Windows.Forms.Button buttonChooseEditBinaryImageCompareDb;
} }
} }

View File

@ -71,6 +71,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public int Index { get; set; } public int Index { get; set; }
public int Increment { get; set; } public int Increment { get; set; }
public string Result { get; set; } public string Result { get; set; }
public NOcrDb NOcrDb { get; set; }
public NOcrChar[] NOcrChars { get; set; } public NOcrChar[] NOcrChars { get; set; }
public BackgroundWorker Self { get; set; } public BackgroundWorker Self { get; set; }
public double UnItalicFactor { get; set; } public double UnItalicFactor { get; set; }
@ -86,6 +87,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Picture = picture; Picture = picture;
Index = index; Index = index;
NOcrChars = nOcrDb.OcrCharacters.ToArray(); NOcrChars = nOcrDb.OcrCharacters.ToArray();
NOcrDb = nOcrDb;
Increment = increment; Increment = increment;
UnItalicFactor = unItalicFactor; UnItalicFactor = unItalicFactor;
AdvancedItalicDetection = advancedItalicDetection; AdvancedItalicDetection = advancedItalicDetection;
@ -249,7 +251,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private double _unItalicFactor = 0.33; private double _unItalicFactor = 0.33;
private BinaryOcrDb _binaryOcrDb; private BinaryOcrDb _binaryOcrDb;
private string _binaryOcrDbFileName;
private long _binOcrLowercaseHeightsTotal; private long _binOcrLowercaseHeightsTotal;
private int _binOcrLowercaseHeightsTotalCount; private int _binOcrLowercaseHeightsTotalCount;
private long _binOcrUppercaseHeightsTotal; private long _binOcrUppercaseHeightsTotal;
@ -327,7 +328,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private int _tesseractAsyncIndex; private int _tesseractAsyncIndex;
private int _tesseractEngineMode; private int _tesseractEngineMode;
private int _linesOcred;
private bool _okClicked; private bool _okClicked;
private readonly Dictionary<string, int> _unknownWordsDictionary; private readonly Dictionary<string, int> _unknownWordsDictionary;
@ -374,8 +374,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
labelImageDatabase.Text = language.ImageDatabase; labelImageDatabase.Text = language.ImageDatabase;
labelNoOfPixelsIsSpace.Text = language.NoOfPixelsIsSpace; labelNoOfPixelsIsSpace.Text = language.NoOfPixelsIsSpace;
labelMaxErrorPercent.Text = language.MaxErrorPercent; labelMaxErrorPercent.Text = language.MaxErrorPercent;
buttonNewCharacterDatabase.Text = language.New;
buttonEditCharacterDatabase.Text = language.Edit;
buttonStartOcr.Text = language.StartOcr; buttonStartOcr.Text = language.StartOcr;
buttonStop.Text = language.Stop; buttonStop.Text = language.Stop;
labelStartFrom.Text = language.StartOcrFrom; labelStartFrom.Text = language.StartOcrFrom;
@ -503,7 +501,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
numericUpDownPixelsIsSpace.Value = Configuration.Settings.VobSubOcr.XOrMorePixelsMakesSpace; numericUpDownPixelsIsSpace.Value = Configuration.Settings.VobSubOcr.XOrMorePixelsMakesSpace;
numericUpDownNumberOfPixelsIsSpaceNOCR.Value = Configuration.Settings.VobSubOcr.XOrMorePixelsMakesSpace; numericUpDownNumberOfPixelsIsSpaceNOCR.Value = Configuration.Settings.VobSubOcr.LineOcrMaxErrorPixels;
checkBoxShowOnlyForced.Text = language.ShowOnlyForcedSubtitles; checkBoxShowOnlyForced.Text = language.ShowOnlyForcedSubtitles;
checkBoxUseTimeCodesFromIdx.Text = language.UseTimeCodesFromIdx; checkBoxUseTimeCodesFromIdx.Text = language.UseTimeCodesFromIdx;
@ -550,13 +548,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
comboBoxModiLanguage.Left = label1.Left + label1.Width + 3; comboBoxModiLanguage.Left = label1.Left + label1.Width + 3;
comboBoxCharacterDatabase.Left = labelImageDatabase.Left + labelImageDatabase.Width + 3; comboBoxCharacterDatabase.Left = labelImageDatabase.Left + labelImageDatabase.Width + 3;
buttonNewCharacterDatabase.Left = comboBoxCharacterDatabase.Left + comboBoxCharacterDatabase.Width + 3; comboBoxCharacterDatabase.Width = buttonChooseEditBinaryImageCompareDb.Left - comboBoxCharacterDatabase.Left - 10;
buttonEditCharacterDatabase.Left = buttonNewCharacterDatabase.Left;
numericUpDownPixelsIsSpace.Left = labelNoOfPixelsIsSpace.Left + labelNoOfPixelsIsSpace.Width + 3; numericUpDownPixelsIsSpace.Left = labelNoOfPixelsIsSpace.Left + labelNoOfPixelsIsSpace.Width + 3;
checkBoxRightToLeft.Left = numericUpDownPixelsIsSpace.Left; checkBoxRightToLeft.Left = numericUpDownPixelsIsSpace.Left;
UiUtil.FixLargeFonts(this, buttonCancel); UiUtil.FixLargeFonts(this, buttonCancel);
buttonEditCharacterDatabase.Top = buttonNewCharacterDatabase.Top + buttonNewCharacterDatabase.Height + 3;
splitContainerBottom.Panel1MinSize = 400; splitContainerBottom.Panel1MinSize = 400;
splitContainerBottom.Panel2MinSize = 250; splitContainerBottom.Panel2MinSize = 250;
@ -968,10 +964,28 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
comboBoxCharacterDatabase.Items.Clear(); comboBoxCharacterDatabase.Items.Clear();
foreach (string s in BinaryOcrDb.GetDatabases()) var binaryOcrDbs = BinaryOcrDb.GetDatabases();
var imageCompareDbName = string.Empty;
if (!string.IsNullOrEmpty(Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb))
{
var parts = Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb.Split('+');
if (parts.Length > 0 && binaryOcrDbs.Contains(parts[0]))
{
imageCompareDbName = parts[0];
if (parts.Length > 1)
{
imageCompareDbName = Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb;
var nOcrDbName = parts[1];
_nOcrDb = new NOcrDb(Path.Combine(Configuration.OcrDirectory, nOcrDbName + ".nocr"));
binaryOcrDbs.Insert(0, Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb);
}
}
}
foreach (string s in binaryOcrDbs)
{ {
comboBoxCharacterDatabase.Items.Add(s); comboBoxCharacterDatabase.Items.Add(s);
if (s == Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb) if (s == imageCompareDbName)
{ {
comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1; comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1;
} }
@ -1007,11 +1021,24 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
DisposeImageCompareBitmaps(); DisposeImageCompareBitmaps();
_binaryOcrDb = null; _binaryOcrDb = null;
_nOcrDb = null;
if (_ocrMethodIndex == _ocrMethodBinaryImageCompare) if (_ocrMethodIndex == _ocrMethodBinaryImageCompare)
{ {
string db = Configuration.OcrDirectory + comboBoxCharacterDatabase.SelectedItem + ".db"; var binaryOcrDbs = BinaryOcrDb.GetDatabases();
_binaryOcrDb = new BinaryOcrDb(db, true); var parts = comboBoxCharacterDatabase.SelectedItem.ToString().Split('+');
if (parts.Length > 0 && binaryOcrDbs.Contains(parts[0]))
{
var imageCompareDbName = parts[0];
if (parts.Length > 1)
{
imageCompareDbName = Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb;
var nOcrDbName = parts[1];
_nOcrDb = new NOcrDb(Path.Combine(Configuration.OcrDirectory, nOcrDbName + ".nocr"));
}
var db = Path.Combine(Configuration.OcrDirectory, imageCompareDbName + ".db");
_binaryOcrDb = new BinaryOcrDb(db, true);
}
} }
} }
@ -2085,117 +2112,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
return new Point((int)Math.Round(p.X + (height - p.Y) * unItalicFactor - moveLeftPixels), p.Y); return new Point((int)Math.Round(p.X + (height - p.Y) * unItalicFactor - moveLeftPixels), p.Y);
} }
private static NOcrChar NOcrFindExpandedMatch(NikseBitmap nbmp, ImageSplitterItem targetItem, NOcrChar[] nOcrChars)
{
int w = targetItem.NikseBitmap.Width;
foreach (NOcrChar oc in nOcrChars)
{
if (oc.ExpandCount > 1 && oc.Width > w && targetItem.X + oc.Width < nbmp.Width)
{
bool ok = true;
var index = 0;
while (index < oc.LinesForeground.Count && ok)
{
NOcrPoint op = oc.LinesForeground[index];
foreach (Point point in op.GetPoints())
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nbmp.Width && p.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(p.X, p.Y);
if (c.A <= 150 || c.R + c.G + c.B <= NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
index = 0;
while (index < oc.LinesBackground.Count && ok)
{
NOcrPoint op = oc.LinesBackground[index];
foreach (Point point in op.GetPoints())
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nbmp.Width && p.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
if (ok)
{
return oc;
}
ok = true;
index = 0;
while (index < oc.LinesForeground.Count && ok)
{
NOcrPoint op = oc.LinesForeground[index];
foreach (Point point in op.ScaledGetPoints(oc, oc.Width, oc.Height - 1))
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nbmp.Width && p.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
{
}
else
{
ok = false;
break;
}
}
}
index++;
}
index = 0;
while (index < oc.LinesBackground.Count && ok)
{
NOcrPoint op = oc.LinesBackground[index];
foreach (Point point in op.ScaledGetPoints(oc, oc.Width, oc.Height - 1))
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nbmp.Width && p.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
if (ok)
{
return oc;
}
}
}
return null;
}
private static NOcrChar NOcrFindBestMatch(ImageSplitterItem targetItem, int topMargin, out bool italic, NOcrChar[] nOcrChars, double unItalicFactor, bool tryItalicScaling, bool deepSeek) private static NOcrChar NOcrFindBestMatch(ImageSplitterItem targetItem, int topMargin, out bool italic, NOcrChar[] nOcrChars, double unItalicFactor, bool tryItalicScaling, bool deepSeek)
{ {
italic = false; italic = false;
@ -2739,9 +2655,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
return null; return null;
} }
private static NOcrChar NOcrFindBestMatchNew(ImageSplitterItem targetItem, int topMargin, bool italic, NOcrDb nOcrDb, bool deepSeek, double italicAngle) private static NOcrChar NOcrFindBestMatchNew(ImageSplitterItem targetItem, int topMargin, bool italic, NOcrDb nOcrDb, bool deepSeek, double italicAngle, int maxWrongPixels)
{ {
return nOcrDb?.GetMatch(targetItem.NikseBitmap, targetItem.Top, deepSeek, italic, italicAngle); return nOcrDb?.GetMatch(targetItem.NikseBitmap, targetItem.Top, deepSeek, italic, italicAngle, maxWrongPixels);
} }
private static NOcrChar MakeItalicNOcrChar(NOcrChar oldChar, int movePixelsLeft, double unItalicFactor) private static NOcrChar MakeItalicNOcrChar(NOcrChar oldChar, int movePixelsLeft, double unItalicFactor)
@ -2767,13 +2683,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
internal CompareMatch GetNOcrCompareMatch(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrDb nOcrDb, bool tryItalicScaling, bool deepSeek) internal CompareMatch GetNOcrCompareMatch(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrDb nOcrDb, bool tryItalicScaling, bool deepSeek)
{ {
var expandedResult = NOcrFindExpandedMatch(parentBitmap, targetItem, nOcrDb.OcrCharacters.ToArray()); var expandedResult = nOcrDb.GetMatchExpanded(parentBitmap, targetItem);
if (expandedResult != null) if (expandedResult != null)
{ {
return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult); return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult);
} }
var result = NOcrFindBestMatchNew(targetItem, targetItem.Y - targetItem.ParentY, tryItalicScaling, nOcrDb, deepSeek, _unItalicFactor); var result = NOcrFindBestMatchNew(targetItem, targetItem.Y - targetItem.ParentY, tryItalicScaling, nOcrDb, deepSeek, _unItalicFactor, (int)numericUpDownNOcrMaxWrongPixels.Value);
if (result == null) if (result == null)
{ {
if (checkBoxNOcrCorrect.Checked) if (checkBoxNOcrCorrect.Checked)
@ -2805,7 +2721,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
_binOcrUppercaseHeightsTotal += targetItem.NikseBitmap.Height; _binOcrUppercaseHeightsTotal += targetItem.NikseBitmap.Height;
} }
if (result.Text == "V" || result.Text == "W" || result.Text == "U" || result.Text == "S" || result.Text == "Z" || result.Text == "O" || result.Text == "X" || result.Text == "Ø" || result.Text == "C") if (result.Text == "V" || result.Text == "W" || result.Text == "U" || result.Text == "S" ||
result.Text == "Z" || result.Text == "Ź" || result.Text == "Ż" || result.Text == "O" || result.Text == "Ó" ||
result.Text == "X" || result.Text == "Ø" || result.Text == "C" || result.Text == "Ć")
{ {
if (_binOcrLowercaseHeightsTotalCount > 3 && if (_binOcrLowercaseHeightsTotalCount > 3 &&
_binOcrUppercaseHeightsTotalCount > 3 && _binOcrUppercaseHeightsTotalCount > 3 &&
@ -2815,7 +2733,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
result.Text = result.Text.ToLowerInvariant(); result.Text = result.Text.ToLowerInvariant();
} }
} }
else if (result.Text == "v" || result.Text == "w" || result.Text == "u" || result.Text == "s" || result.Text == "z" || result.Text == "o" || result.Text == "x" || result.Text == "ø" || result.Text == "c") else if (result.Text == "v" || result.Text == "w" || result.Text == "u" || result.Text == "s" ||
result.Text == "z" || result.Text == "ź" || result.Text == "ż" || result.Text == "ó" ||
result.Text == "o" || result.Text == "x" || result.Text == "ø" || result.Text == "c" || result.Text == "ć")
{ {
if (_binOcrLowercaseHeightsTotalCount > 3 && if (_binOcrLowercaseHeightsTotalCount > 3 &&
_binOcrUppercaseHeightsTotalCount > 3 && _binOcrUppercaseHeightsTotalCount > 3 &&
@ -2829,13 +2749,13 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
internal CompareMatch GetNOcrCompareMatchNew(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrDb nOcrDb, bool tryItalicScaling, bool deepSeek) internal CompareMatch GetNOcrCompareMatchNew(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrDb nOcrDb, bool tryItalicScaling, bool deepSeek)
{ {
var expandedResult = NOcrFindExpandedMatch(parentBitmap, targetItem, nOcrDb.OcrCharactersExpanded.ToArray()); var expandedResult = nOcrDb.GetMatchExpanded(parentBitmap, targetItem);
if (expandedResult != null) if (expandedResult != null)
{ {
return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult) { ImageSplitterItem = targetItem }; return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult) { ImageSplitterItem = targetItem };
} }
var result = NOcrFindBestMatchNew(targetItem, targetItem.Y - targetItem.ParentY, tryItalicScaling, nOcrDb, deepSeek, _unItalicFactor); var result = NOcrFindBestMatchNew(targetItem, targetItem.Y - targetItem.ParentY, tryItalicScaling, nOcrDb, deepSeek, _unItalicFactor, (int)numericUpDownNOcrMaxWrongPixels.Value);
if (result == null) if (result == null)
{ {
if (checkBoxNOcrCorrect.Checked) if (checkBoxNOcrCorrect.Checked)
@ -2853,7 +2773,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
internal static CompareMatch GetNOcrCompareMatch(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrThreadParameter p) internal static CompareMatch GetNOcrCompareMatch(ImageSplitterItem targetItem, NikseBitmap parentBitmap, NOcrThreadParameter p)
{ {
var expandedResult = NOcrFindExpandedMatch(parentBitmap, targetItem, p.NOcrChars); var expandedResult = p.NOcrDb.GetMatchExpanded(parentBitmap, targetItem);
if (expandedResult != null) if (expandedResult != null)
{ {
return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult); return new CompareMatch(expandedResult.Text, expandedResult.Italic, expandedResult.ExpandCount, null, expandedResult);
@ -3752,7 +3672,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
var match = GetCompareMatchNew(item, out var bestGuess, list, index, _binaryOcrDb); var match = GetCompareMatchNew(item, out var bestGuess, list, index, _binaryOcrDb);
if (match == null) // Try nOCR (line OCR) if no image compare match if (match == null) // Try nOCR (line OCR) if no image compare match
{ {
if (_nOcrDb != null && _nOcrDb.OcrCharacters.Count > 0 && _numericUpDownMaxErrorPct > 1) if (_nOcrDb != null && _nOcrDb.OcrCharacters.Count > 0)
{ {
match = GetNOcrCompareMatchNew(item, parentBitmap, _nOcrDb, true, true); match = GetNOcrCompareMatchNew(item, parentBitmap, _nOcrDb, true, true);
} }
@ -4816,8 +4736,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
buttonCancel.Enabled = false; buttonCancel.Enabled = false;
buttonStartOcr.Enabled = false; buttonStartOcr.Enabled = false;
buttonStop.Enabled = true; buttonStop.Enabled = true;
buttonNewCharacterDatabase.Enabled = false; buttonChooseEditBinaryImageCompareDb.Enabled = false;
buttonEditCharacterDatabase.Enabled = false;
_mainOcrRunning = true; _mainOcrRunning = true;
progressBar1.Visible = true; progressBar1.Visible = true;
subtitleListView1.MultiSelect = false; subtitleListView1.MultiSelect = false;
@ -4832,8 +4751,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
buttonCancel.Enabled = true; buttonCancel.Enabled = true;
buttonStartOcr.Enabled = true; buttonStartOcr.Enabled = true;
buttonStop.Enabled = false; buttonStop.Enabled = false;
buttonNewCharacterDatabase.Enabled = true; buttonChooseEditBinaryImageCompareDb.Enabled = true;
buttonEditCharacterDatabase.Enabled = true;
_mainOcrRunning = false; _mainOcrRunning = false;
labelStatus.Text = string.Empty; labelStatus.Text = string.Empty;
progressBar1.Visible = false; progressBar1.Visible = false;
@ -5029,12 +4947,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
if (_binaryOcrDb == null) if (_binaryOcrDb == null)
{ {
_binaryOcrDbFileName = Configuration.OcrDirectory + "Latin.db"; _binaryOcrDb = new BinaryOcrDb(Configuration.OcrDirectory + "Latin.db", true);
_binaryOcrDb = new BinaryOcrDb(_binaryOcrDbFileName, true);
} }
_nOcrDb = new NOcrDb(_binaryOcrDb.FileName.Replace(".db", ".nocr")); checkBoxNOcrCorrect.Checked = false;
checkBoxNOcrCorrect.Checked = true;
_numericUpDownMaxErrorPct = (double)numericUpDownMaxErrorPct.Value; _numericUpDownMaxErrorPct = (double)numericUpDownMaxErrorPct.Value;
} }
@ -5153,8 +5069,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
_linesOcred++;
if (_abort) if (_abort)
{ {
textBoxCurrentText.Text = text; textBoxCurrentText.Text = text;
@ -5206,7 +5120,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
labelStatus.Refresh(); labelStatus.Refresh();
progressBar1.Refresh(); progressBar1.Refresh();
_linesOcred++;
job.Bitmap.Dispose(); job.Bitmap.Dispose();
if (index >= max - 1) if (index >= max - 1)
{ {
@ -5310,8 +5223,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
_linesOcred++;
if (_abort) if (_abort)
{ {
textBoxCurrentText.Text = text; textBoxCurrentText.Text = text;
@ -6676,48 +6587,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void ButtonNewCharacterDatabaseClick(object sender, EventArgs e) private void ButtonNewCharacterDatabaseClick(object sender, EventArgs e)
{ {
using (var newFolder = new VobSubOcrNewFolder(false))
{
if (newFolder.ShowDialog(this) == DialogResult.OK)
{
if (_ocrMethodIndex == _ocrMethodBinaryImageCompare)
{
try
{
string fileName = Path.Combine(Configuration.OcrDirectory, newFolder.FolderName + ".db");
if (File.Exists(fileName))
{
MessageBox.Show("OCR db already exists!");
return;
}
comboBoxCharacterDatabase.Items.Add(newFolder.FolderName);
comboBoxCharacterDatabase.SelectedIndex = comboBoxCharacterDatabase.Items.Count - 1;
_binaryOcrDb = new BinaryOcrDb(fileName);
_binaryOcrDb.Save();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
else
{
_vobSubOcrSettings.LastImageCompareFolder = newFolder.FolderName;
LoadImageCompareCharacterDatabaseList();
LoadImageCompareBitmaps();
}
}
}
} }
private void ComboBoxCharacterDatabaseSelectedIndexChanged(object sender, EventArgs e) private void ComboBoxCharacterDatabaseSelectedIndexChanged(object sender, EventArgs e)
{ {
if (_ocrMethodIndex == _ocrMethodBinaryImageCompare)
{
_binaryOcrDbFileName = Configuration.OcrDirectory + comboBoxCharacterDatabase.SelectedItem + ".db";
}
LoadImageCompareBitmaps(); LoadImageCompareBitmaps();
if (_vobSubOcrSettings != null) if (_vobSubOcrSettings != null)
{ {
@ -6741,7 +6615,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
public DialogResult EditImageCompareCharacters(string name, string text) public DialogResult EditImageCompareCharacters(string name, string text)
{ {
using (var formVobSubEditCharacters = new VobSubEditCharacters(comboBoxCharacterDatabase.SelectedItem.ToString(), null, _binaryOcrDb)) using (var formVobSubEditCharacters = new VobSubEditCharacters(null, _binaryOcrDb))
{ {
formVobSubEditCharacters.Initialize(name, text); formVobSubEditCharacters.Initialize(name, text);
DialogResult result = formVobSubEditCharacters.ShowDialog(); DialogResult result = formVobSubEditCharacters.ShowDialog();
@ -6751,19 +6625,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
_binaryOcrDb.Save(); _binaryOcrDb.Save();
} }
else
{
_compareDoc = formVobSubEditCharacters.ImageCompareDocument;
string path = Configuration.VobSubCompareDirectory + comboBoxCharacterDatabase.SelectedItem + Path.DirectorySeparatorChar;
_compareDoc.Save(path + "Images.xml");
Cursor = Cursors.WaitCursor;
if (formVobSubEditCharacters.ChangesMade)
{
_binaryOcrDb.LoadCompareImages();
}
Cursor = Cursors.Default;
}
return result; return result;
} }
@ -7137,7 +6998,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
ShowOcrMethodGroupBox(groupBoxImageCompareMethod); ShowOcrMethodGroupBox(groupBoxImageCompareMethod);
Configuration.Settings.VobSubOcr.LastOcrMethod = "BinaryImageCompare"; Configuration.Settings.VobSubOcr.LastOcrMethod = "BinaryImageCompare";
numericUpDownMaxErrorPct.Minimum = 0; numericUpDownMaxErrorPct.Minimum = 0;
_binaryOcrDb = new BinaryOcrDb(_binaryOcrDbFileName, true);
LoadImageCompareCharacterDatabaseList(); LoadImageCompareCharacterDatabaseList();
} }
else if (_ocrMethodIndex == _ocrMethodModi) else if (_ocrMethodIndex == _ocrMethodModi)
@ -7869,7 +7729,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void inspectLastAdditionsToolStripMenuItem_Click(object sender, EventArgs e) private void inspectLastAdditionsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
using (var formVobSubEditCharacters = new VobSubEditCharacters(comboBoxCharacterDatabase.SelectedItem.ToString(), _lastAdditions, _binaryOcrDb)) using (var formVobSubEditCharacters = new VobSubEditCharacters(_lastAdditions, _binaryOcrDb))
{ {
if (formVobSubEditCharacters.ShowDialog(this) == DialogResult.OK) if (formVobSubEditCharacters.ShowDialog(this) == DialogResult.OK)
{ {
@ -7878,12 +7738,6 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
_binaryOcrDb.Save(); _binaryOcrDb.Save();
} }
else
{
_compareDoc = formVobSubEditCharacters.ImageCompareDocument;
string path = Configuration.VobSubCompareDirectory + comboBoxCharacterDatabase.SelectedItem + Path.DirectorySeparatorChar;
_compareDoc.Save(path + "Images.xml");
}
} }
} }
} }
@ -8076,6 +7930,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
Configuration.Settings.VobSubOcr.XOrMorePixelsMakesSpace = (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value; Configuration.Settings.VobSubOcr.XOrMorePixelsMakesSpace = (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value;
} }
Configuration.Settings.VobSubOcr.LineOcrMaxErrorPixels = (int)numericUpDownNumberOfPixelsIsSpaceNOCR.Value;
Configuration.Settings.VobSubOcr.UseTesseractFallback = checkBoxTesseractFallback.Checked; Configuration.Settings.VobSubOcr.UseTesseractFallback = checkBoxTesseractFallback.Checked;
Configuration.Settings.VobSubOcr.CaptureTopAlign = toolStripMenuItemCaptureTopAlign.Checked; Configuration.Settings.VobSubOcr.CaptureTopAlign = toolStripMenuItemCaptureTopAlign.Checked;
@ -8638,7 +8493,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
LoadNOcrWithCurrentLanguage(); LoadNOcrWithCurrentLanguage();
} }
using (var form = new VobSubNOcrEdit(_nOcrDb.OcrCharacters, null, _nOcrDb.FileName)) using (var form = new VobSubNOcrEdit(_nOcrDb, null, _nOcrDb.FileName))
{ {
if (form.ShowDialog(this) == DialogResult.OK && form.Changed) if (form.ShowDialog(this) == DialogResult.OK && form.Changed)
{ {
@ -9055,18 +8910,28 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (_ocrMethodIndex == _ocrMethodBinaryImageCompare) if (_ocrMethodIndex == _ocrMethodBinaryImageCompare)
{ {
var s = FindBestImageCompareDatabase(); var s = FindBestImageCompareDatabase();
if (!string.IsNullOrEmpty(s) && s != Configuration.Settings.VobSubOcr.LastBinaryImageSpellCheck) if (string.IsNullOrEmpty(s))
{ {
Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb = s; return;
for (int i = 0; i < comboBoxCharacterDatabase.Items.Count; i++) }
if (Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb.Contains("+"))
{
s += "+" + Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb.Split('+')[1];
}
Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb = s;
for (int i = 0; i < comboBoxCharacterDatabase.Items.Count; i++)
{
if (comboBoxCharacterDatabase.Items[i].ToString() == Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb)
{ {
if (comboBoxCharacterDatabase.Items[i].ToString() == Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb) comboBoxCharacterDatabase.SelectedIndex = i;
{ return;
comboBoxCharacterDatabase.SelectedIndex = i;
break;
}
} }
} }
comboBoxCharacterDatabase.Items.Insert(0, s);
comboBoxCharacterDatabase.SelectedIndex = 0;
} }
} }
@ -9209,5 +9074,19 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
toolStripMenuItemSetUnItalicFactor_Click(null, null); toolStripMenuItemSetUnItalicFactor_Click(null, null);
} }
private void buttonChooseEditBinaryImageCompareDb_Click(object sender, EventArgs e)
{
using (var form = new BinaryOcrChooseEditDb(comboBoxCharacterDatabase.Text))
{
if (form.ShowDialog(this) != DialogResult.OK)
{
return;
}
Configuration.Settings.VobSubOcr.LastBinaryImageCompareDb = form.ImageCompareDatabaseName;
LoadImageCompareCharacterDatabaseList();
}
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,32 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
UiUtil.FixLargeFonts(this, buttonCancel); UiUtil.FixLargeFonts(this, buttonCancel);
checkBoxAutoSubmitOfFirstChar.Text = Configuration.Settings.Language.VobSubOcrCharacter.AutoSubmitOnFirstChar; checkBoxAutoSubmitOfFirstChar.Text = Configuration.Settings.Language.VobSubOcrCharacter.AutoSubmitOnFirstChar;
labelItalicOn.Visible = false; labelItalicOn.Visible = false;
foreach (ToolStripItem toolStripItem in contextMenuStripLetters.Items)
{
if (toolStripItem is ToolStripDropDownItem i && i.HasDropDownItems)
{
foreach (ToolStripItem item in i.DropDownItems)
{
item.Click += InsertLanguageCharacter;
}
}
else
{
toolStripItem.Click += InsertLanguageCharacter;
}
}
}
private void InsertLanguageCharacter(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem toolStripMenuItem)
{
var start = textBoxCharacters.SelectionStart;
textBoxCharacters.SelectedText = toolStripMenuItem.Text;
textBoxCharacters.SelectionLength = 0;
textBoxCharacters.SelectionStart = start + toolStripMenuItem.Text.Length;
}
} }
public NOcrChar NOcrChar { get; private set; } public NOcrChar NOcrChar { get; private set; }
@ -760,7 +786,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
} }
} }
private void removeForegroundToolStripMenuItem_Click(object sender, EventArgs e) private void removeBackgroundLineToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (listBoxlinesBackground.SelectedItems.Count == 1) if (listBoxlinesBackground.SelectedItems.Count == 1)
{ {
@ -770,7 +796,7 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
ShowOcrPoints(); ShowOcrPoints();
} }
private void removeForegroundToolStripMenuItem_Click_1(object sender, EventArgs e) private void removeForegroundToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (listBoxLinesForeground.SelectedItems.Count == 1) if (listBoxLinesForeground.SelectedItems.Count == 1)
{ {
@ -878,5 +904,25 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
{ {
DialogResult = DialogResult.Abort; DialogResult = DialogResult.Abort;
} }
private void listBoxLinesForeground_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void listBoxLinesForeground_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
removeForegroundToolStripMenuItem_Click(null, null);
}
}
private void listBoxLinesBackground_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
removeBackgroundLineToolStripMenuItem_Click(null, null);
}
}
} }
} }

View File

@ -2319,7 +2319,7 @@
// //
this.buttonDownloadFfmpeg.Location = new System.Drawing.Point(274, 17); this.buttonDownloadFfmpeg.Location = new System.Drawing.Point(274, 17);
this.buttonDownloadFfmpeg.Name = "buttonDownloadFfmpeg"; this.buttonDownloadFfmpeg.Name = "buttonDownloadFfmpeg";
this.buttonDownloadFfmpeg.Size = new System.Drawing.Size(136, 21); this.buttonDownloadFfmpeg.Size = new System.Drawing.Size(136, 23);
this.buttonDownloadFfmpeg.TabIndex = 2; this.buttonDownloadFfmpeg.TabIndex = 2;
this.buttonDownloadFfmpeg.Text = "Download ffmpeg"; this.buttonDownloadFfmpeg.Text = "Download ffmpeg";
this.buttonDownloadFfmpeg.UseVisualStyleBackColor = true; this.buttonDownloadFfmpeg.UseVisualStyleBackColor = true;
@ -2480,7 +2480,7 @@
// panelWaveformCursorColor // panelWaveformCursorColor
// //
this.panelWaveformCursorColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelWaveformCursorColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWaveformCursorColor.Location = new System.Drawing.Point(138, 136); this.panelWaveformCursorColor.Location = new System.Drawing.Point(138, 142);
this.panelWaveformCursorColor.Name = "panelWaveformCursorColor"; this.panelWaveformCursorColor.Name = "panelWaveformCursorColor";
this.panelWaveformCursorColor.Size = new System.Drawing.Size(21, 20); this.panelWaveformCursorColor.Size = new System.Drawing.Size(21, 20);
this.panelWaveformCursorColor.TabIndex = 34; this.panelWaveformCursorColor.TabIndex = 34;
@ -2488,9 +2488,9 @@
// //
// buttonWaveformCursorColor // buttonWaveformCursorColor
// //
this.buttonWaveformCursorColor.Location = new System.Drawing.Point(16, 135); this.buttonWaveformCursorColor.Location = new System.Drawing.Point(14, 141);
this.buttonWaveformCursorColor.Name = "buttonWaveformCursorColor"; this.buttonWaveformCursorColor.Name = "buttonWaveformCursorColor";
this.buttonWaveformCursorColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformCursorColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformCursorColor.TabIndex = 4; this.buttonWaveformCursorColor.TabIndex = 4;
this.buttonWaveformCursorColor.Text = "Cursor color"; this.buttonWaveformCursorColor.Text = "Cursor color";
this.buttonWaveformCursorColor.UseVisualStyleBackColor = true; this.buttonWaveformCursorColor.UseVisualStyleBackColor = true;
@ -2519,7 +2519,7 @@
// checkBoxWaveformShowWpm // checkBoxWaveformShowWpm
// //
this.checkBoxWaveformShowWpm.AutoSize = true; this.checkBoxWaveformShowWpm.AutoSize = true;
this.checkBoxWaveformShowWpm.Location = new System.Drawing.Point(16, 248); this.checkBoxWaveformShowWpm.Location = new System.Drawing.Point(16, 256);
this.checkBoxWaveformShowWpm.Name = "checkBoxWaveformShowWpm"; this.checkBoxWaveformShowWpm.Name = "checkBoxWaveformShowWpm";
this.checkBoxWaveformShowWpm.Size = new System.Drawing.Size(104, 17); this.checkBoxWaveformShowWpm.Size = new System.Drawing.Size(104, 17);
this.checkBoxWaveformShowWpm.TabIndex = 8; this.checkBoxWaveformShowWpm.TabIndex = 8;
@ -2529,7 +2529,7 @@
// checkBoxWaveformShowCps // checkBoxWaveformShowCps
// //
this.checkBoxWaveformShowCps.AutoSize = true; this.checkBoxWaveformShowCps.AutoSize = true;
this.checkBoxWaveformShowCps.Location = new System.Drawing.Point(16, 225); this.checkBoxWaveformShowCps.Location = new System.Drawing.Point(16, 233);
this.checkBoxWaveformShowCps.Name = "checkBoxWaveformShowCps"; this.checkBoxWaveformShowCps.Name = "checkBoxWaveformShowCps";
this.checkBoxWaveformShowCps.Size = new System.Drawing.Size(96, 17); this.checkBoxWaveformShowCps.Size = new System.Drawing.Size(96, 17);
this.checkBoxWaveformShowCps.TabIndex = 7; this.checkBoxWaveformShowCps.TabIndex = 7;
@ -2668,7 +2668,7 @@
// panelWaveformTextColor // panelWaveformTextColor
// //
this.panelWaveformTextColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelWaveformTextColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWaveformTextColor.Location = new System.Drawing.Point(138, 109); this.panelWaveformTextColor.Location = new System.Drawing.Point(138, 113);
this.panelWaveformTextColor.Name = "panelWaveformTextColor"; this.panelWaveformTextColor.Name = "panelWaveformTextColor";
this.panelWaveformTextColor.Size = new System.Drawing.Size(21, 20); this.panelWaveformTextColor.Size = new System.Drawing.Size(21, 20);
this.panelWaveformTextColor.TabIndex = 7; this.panelWaveformTextColor.TabIndex = 7;
@ -2676,9 +2676,9 @@
// //
// buttonWaveformTextColor // buttonWaveformTextColor
// //
this.buttonWaveformTextColor.Location = new System.Drawing.Point(16, 108); this.buttonWaveformTextColor.Location = new System.Drawing.Point(14, 112);
this.buttonWaveformTextColor.Name = "buttonWaveformTextColor"; this.buttonWaveformTextColor.Name = "buttonWaveformTextColor";
this.buttonWaveformTextColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformTextColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformTextColor.TabIndex = 3; this.buttonWaveformTextColor.TabIndex = 3;
this.buttonWaveformTextColor.Text = "Text color"; this.buttonWaveformTextColor.Text = "Text color";
this.buttonWaveformTextColor.UseVisualStyleBackColor = true; this.buttonWaveformTextColor.UseVisualStyleBackColor = true;
@ -2687,7 +2687,7 @@
// panelWaveformGridColor // panelWaveformGridColor
// //
this.panelWaveformGridColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelWaveformGridColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWaveformGridColor.Location = new System.Drawing.Point(138, 163); this.panelWaveformGridColor.Location = new System.Drawing.Point(138, 171);
this.panelWaveformGridColor.Name = "panelWaveformGridColor"; this.panelWaveformGridColor.Name = "panelWaveformGridColor";
this.panelWaveformGridColor.Size = new System.Drawing.Size(21, 20); this.panelWaveformGridColor.Size = new System.Drawing.Size(21, 20);
this.panelWaveformGridColor.TabIndex = 9; this.panelWaveformGridColor.TabIndex = 9;
@ -2695,9 +2695,9 @@
// //
// buttonWaveformGridColor // buttonWaveformGridColor
// //
this.buttonWaveformGridColor.Location = new System.Drawing.Point(16, 162); this.buttonWaveformGridColor.Location = new System.Drawing.Point(14, 170);
this.buttonWaveformGridColor.Name = "buttonWaveformGridColor"; this.buttonWaveformGridColor.Name = "buttonWaveformGridColor";
this.buttonWaveformGridColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformGridColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformGridColor.TabIndex = 5; this.buttonWaveformGridColor.TabIndex = 5;
this.buttonWaveformGridColor.Text = "Grid color"; this.buttonWaveformGridColor.Text = "Grid color";
this.buttonWaveformGridColor.UseVisualStyleBackColor = true; this.buttonWaveformGridColor.UseVisualStyleBackColor = true;
@ -2706,7 +2706,7 @@
// panelWaveformBackgroundColor // panelWaveformBackgroundColor
// //
this.panelWaveformBackgroundColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelWaveformBackgroundColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWaveformBackgroundColor.Location = new System.Drawing.Point(138, 82); this.panelWaveformBackgroundColor.Location = new System.Drawing.Point(138, 84);
this.panelWaveformBackgroundColor.Name = "panelWaveformBackgroundColor"; this.panelWaveformBackgroundColor.Name = "panelWaveformBackgroundColor";
this.panelWaveformBackgroundColor.Size = new System.Drawing.Size(21, 20); this.panelWaveformBackgroundColor.Size = new System.Drawing.Size(21, 20);
this.panelWaveformBackgroundColor.TabIndex = 5; this.panelWaveformBackgroundColor.TabIndex = 5;
@ -2714,9 +2714,9 @@
// //
// buttonWaveformBackgroundColor // buttonWaveformBackgroundColor
// //
this.buttonWaveformBackgroundColor.Location = new System.Drawing.Point(16, 81); this.buttonWaveformBackgroundColor.Location = new System.Drawing.Point(14, 83);
this.buttonWaveformBackgroundColor.Name = "buttonWaveformBackgroundColor"; this.buttonWaveformBackgroundColor.Name = "buttonWaveformBackgroundColor";
this.buttonWaveformBackgroundColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformBackgroundColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformBackgroundColor.TabIndex = 2; this.buttonWaveformBackgroundColor.TabIndex = 2;
this.buttonWaveformBackgroundColor.Text = "Back color"; this.buttonWaveformBackgroundColor.Text = "Back color";
this.buttonWaveformBackgroundColor.UseVisualStyleBackColor = true; this.buttonWaveformBackgroundColor.UseVisualStyleBackColor = true;
@ -2733,9 +2733,9 @@
// //
// buttonWaveformColor // buttonWaveformColor
// //
this.buttonWaveformColor.Location = new System.Drawing.Point(16, 54); this.buttonWaveformColor.Location = new System.Drawing.Point(14, 54);
this.buttonWaveformColor.Name = "buttonWaveformColor"; this.buttonWaveformColor.Name = "buttonWaveformColor";
this.buttonWaveformColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformColor.TabIndex = 1; this.buttonWaveformColor.TabIndex = 1;
this.buttonWaveformColor.Text = "Color"; this.buttonWaveformColor.Text = "Color";
this.buttonWaveformColor.UseVisualStyleBackColor = true; this.buttonWaveformColor.UseVisualStyleBackColor = true;
@ -2744,7 +2744,7 @@
// panelWaveformSelectedColor // panelWaveformSelectedColor
// //
this.panelWaveformSelectedColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelWaveformSelectedColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelWaveformSelectedColor.Location = new System.Drawing.Point(138, 27); this.panelWaveformSelectedColor.Location = new System.Drawing.Point(138, 26);
this.panelWaveformSelectedColor.Name = "panelWaveformSelectedColor"; this.panelWaveformSelectedColor.Name = "panelWaveformSelectedColor";
this.panelWaveformSelectedColor.Size = new System.Drawing.Size(21, 20); this.panelWaveformSelectedColor.Size = new System.Drawing.Size(21, 20);
this.panelWaveformSelectedColor.TabIndex = 1; this.panelWaveformSelectedColor.TabIndex = 1;
@ -2752,9 +2752,9 @@
// //
// buttonWaveformSelectedColor // buttonWaveformSelectedColor
// //
this.buttonWaveformSelectedColor.Location = new System.Drawing.Point(16, 27); this.buttonWaveformSelectedColor.Location = new System.Drawing.Point(14, 25);
this.buttonWaveformSelectedColor.Name = "buttonWaveformSelectedColor"; this.buttonWaveformSelectedColor.Name = "buttonWaveformSelectedColor";
this.buttonWaveformSelectedColor.Size = new System.Drawing.Size(112, 21); this.buttonWaveformSelectedColor.Size = new System.Drawing.Size(112, 23);
this.buttonWaveformSelectedColor.TabIndex = 0; this.buttonWaveformSelectedColor.TabIndex = 0;
this.buttonWaveformSelectedColor.Text = "Selected color"; this.buttonWaveformSelectedColor.Text = "Selected color";
this.buttonWaveformSelectedColor.UseVisualStyleBackColor = true; this.buttonWaveformSelectedColor.UseVisualStyleBackColor = true;
@ -2763,7 +2763,7 @@
// checkBoxWaveformShowGrid // checkBoxWaveformShowGrid
// //
this.checkBoxWaveformShowGrid.AutoSize = true; this.checkBoxWaveformShowGrid.AutoSize = true;
this.checkBoxWaveformShowGrid.Location = new System.Drawing.Point(16, 192); this.checkBoxWaveformShowGrid.Location = new System.Drawing.Point(16, 201);
this.checkBoxWaveformShowGrid.Name = "checkBoxWaveformShowGrid"; this.checkBoxWaveformShowGrid.Name = "checkBoxWaveformShowGrid";
this.checkBoxWaveformShowGrid.Size = new System.Drawing.Size(73, 17); this.checkBoxWaveformShowGrid.Size = new System.Drawing.Size(73, 17);
this.checkBoxWaveformShowGrid.TabIndex = 6; this.checkBoxWaveformShowGrid.TabIndex = 6;

View File

@ -87,7 +87,118 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
} }
} }
public NOcrChar GetMatch(NikseBitmap bitmap, int topMargin, bool deepSeek, bool italic, double italicAngle) public NOcrChar GetMatchExpanded(NikseBitmap nikseBitmap, ImageSplitterItem targetItem)
{
int w = targetItem.NikseBitmap.Width;
foreach (NOcrChar oc in OcrCharactersExpanded)
{
if (oc.ExpandCount > 1 && oc.Width > w && targetItem.X + oc.Width < nikseBitmap.Width)
{
bool ok = true;
var index = 0;
while (index < oc.LinesForeground.Count && ok)
{
NOcrPoint op = oc.LinesForeground[index];
foreach (Point point in op.GetPoints())
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nikseBitmap.Width && p.Y < nikseBitmap.Height)
{
Color c = nikseBitmap.GetPixel(p.X, p.Y);
if (c.A <= 150 || c.R + c.G + c.B <= VobSubOcr.NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
index = 0;
while (index < oc.LinesBackground.Count && ok)
{
NOcrPoint op = oc.LinesBackground[index];
foreach (Point point in op.GetPoints())
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nikseBitmap.Width && p.Y < nikseBitmap.Height)
{
Color c = nikseBitmap.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > VobSubOcr.NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
if (ok)
{
return oc;
}
ok = true;
index = 0;
while (index < oc.LinesForeground.Count && ok)
{
NOcrPoint op = oc.LinesForeground[index];
foreach (Point point in op.ScaledGetPoints(oc, oc.Width, oc.Height - 1))
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nikseBitmap.Width && p.Y < nikseBitmap.Height)
{
Color c = nikseBitmap.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > VobSubOcr.NocrMinColor)
{
}
else
{
ok = false;
break;
}
}
}
index++;
}
index = 0;
while (index < oc.LinesBackground.Count && ok)
{
NOcrPoint op = oc.LinesBackground[index];
foreach (Point point in op.ScaledGetPoints(oc, oc.Width, oc.Height - 1))
{
Point p = new Point(point.X + targetItem.X, point.Y + targetItem.Y);
if (p.X >= 0 && p.Y >= 0 && p.X < nikseBitmap.Width && p.Y < nikseBitmap.Height)
{
Color c = nikseBitmap.GetPixel(p.X, p.Y);
if (c.A > 150 && c.R + c.G + c.B > VobSubOcr.NocrMinColor)
{
ok = false;
break;
}
}
}
index++;
}
if (ok)
{
return oc;
}
}
}
return null;
}
public NOcrChar GetMatch(NikseBitmap bitmap, int topMargin, bool deepSeek, bool italic, double italicAngle, int maxWrongPixels)
{ {
// only very very accurate matches // only very very accurate matches
foreach (var oc in OcrCharacters) foreach (var oc in OcrCharacters)
@ -114,46 +225,58 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
} }
} }
foreach (var oc in OcrCharacters) if (maxWrongPixels >= 1)
{ {
if (Math.Abs(bitmap.Width - oc.Width) < 8 && Math.Abs(bitmap.Height - oc.Height) < 8 && Math.Abs(oc.MarginTop - topMargin) < 8) foreach (var oc in OcrCharacters)
{ {
if (IsMatch(bitmap, oc, 1)) if (Math.Abs(bitmap.Width - oc.Width) < 8 && Math.Abs(bitmap.Height - oc.Height) < 8 && Math.Abs(oc.MarginTop - topMargin) < 8)
{ {
return oc; if (IsMatch(bitmap, oc, 1))
{
return oc;
}
} }
} }
} }
foreach (var oc in OcrCharacters) if (maxWrongPixels >= 2)
{ {
if (Math.Abs(widthPercent - oc.WidthPercent) < 20 && Math.Abs(oc.MarginTop - topMargin) < 15) foreach (var oc in OcrCharacters)
{ {
if (IsMatch(bitmap, oc, 2)) if (Math.Abs(widthPercent - oc.WidthPercent) < 20 && Math.Abs(oc.MarginTop - topMargin) < 15)
{ {
return oc; if (IsMatch(bitmap, oc, 2))
{
return oc;
}
} }
} }
} }
foreach (var oc in OcrCharacters) if (maxWrongPixels >= 20)
{ {
if (!oc.IsSensitive && Math.Abs(widthPercent - oc.WidthPercent) < 20 && Math.Abs(oc.MarginTop - topMargin) < 15 && oc.LinesForeground.Count + oc.LinesBackground.Count > 40) foreach (var oc in OcrCharacters)
{ {
if (IsMatch(bitmap, oc, 20)) if (!oc.IsSensitive && Math.Abs(widthPercent - oc.WidthPercent) < 20 && Math.Abs(oc.MarginTop - topMargin) < 15 && oc.LinesForeground.Count + oc.LinesBackground.Count > 40)
{ {
return oc; if (IsMatch(bitmap, oc, 20))
{
return oc;
}
} }
} }
} }
foreach (var oc in OcrCharacters) if (maxWrongPixels >= 10)
{ {
if (oc.IsSensitive && Math.Abs(widthPercent - oc.WidthPercent) < 30 && Math.Abs(oc.MarginTop - topMargin) < 15 && oc.LinesForeground.Count + oc.LinesBackground.Count > 40) foreach (var oc in OcrCharacters)
{ {
if (IsMatch(bitmap, oc, 10)) if (oc.IsSensitive && Math.Abs(widthPercent - oc.WidthPercent) < 30 && Math.Abs(oc.MarginTop - topMargin) < 15 && oc.LinesForeground.Count + oc.LinesBackground.Count > 40)
{ {
return oc; if (IsMatch(bitmap, oc, 10))
{
return oc;
}
} }
} }
} }
@ -179,7 +302,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
{ {
if (Math.Abs(widthPercent - oc.WidthPercent) < 60 && Math.Abs(oc.MarginTop - topMargin) < 17 && oc.LinesForeground.Count + oc.LinesBackground.Count > 50) if (Math.Abs(widthPercent - oc.WidthPercent) < 60 && Math.Abs(oc.MarginTop - topMargin) < 17 && oc.LinesForeground.Count + oc.LinesBackground.Count > 50)
{ {
if (IsMatch(bitmap, oc, 25)) if (IsMatch(bitmap, oc, maxWrongPixels))
{ {
return oc; return oc;
} }

View File

@ -236,6 +236,12 @@
<Compile Include="Forms\Ocr\AddBeterMultiMatch.Designer.cs"> <Compile Include="Forms\Ocr\AddBeterMultiMatch.Designer.cs">
<DependentUpon>AddBeterMultiMatch.cs</DependentUpon> <DependentUpon>AddBeterMultiMatch.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\Ocr\AddBetterMultiMatchNOcr.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Ocr\AddBetterMultiMatchNOcr.Designer.cs">
<DependentUpon>AddBetterMultiMatchNOcr.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Ocr\AddToOcrReplaceList.cs"> <Compile Include="Forms\Ocr\AddToOcrReplaceList.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -512,6 +518,12 @@
<Compile Include="Forms\GetDictionaries.Designer.cs"> <Compile Include="Forms\GetDictionaries.Designer.cs">
<DependentUpon>GetDictionaries.cs</DependentUpon> <DependentUpon>GetDictionaries.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\Ocr\BinaryOcrChooseEditDb.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Ocr\BinaryOcrChooseEditDb.Designer.cs">
<DependentUpon>BinaryOcrChooseEditDb.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Ocr\BinaryOcrTrain.cs"> <Compile Include="Forms\Ocr\BinaryOcrTrain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -1191,6 +1203,9 @@
<EmbeddedResource Include="Forms\Ocr\AddBeterMultiMatch.resx"> <EmbeddedResource Include="Forms\Ocr\AddBeterMultiMatch.resx">
<DependentUpon>AddBeterMultiMatch.cs</DependentUpon> <DependentUpon>AddBeterMultiMatch.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Forms\Ocr\AddBetterMultiMatchNOcr.resx">
<DependentUpon>AddBetterMultiMatchNOcr.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Ocr\AddToOcrReplaceList.resx"> <EmbeddedResource Include="Forms\Ocr\AddToOcrReplaceList.resx">
<DependentUpon>AddToOcrReplaceList.cs</DependentUpon> <DependentUpon>AddToOcrReplaceList.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
@ -1327,6 +1342,9 @@
<DependentUpon>GetDictionaries.cs</DependentUpon> <DependentUpon>GetDictionaries.cs</DependentUpon>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Forms\Ocr\BinaryOcrChooseEditDb.resx">
<DependentUpon>BinaryOcrChooseEditDb.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Ocr\BinaryOcrTrain.resx"> <EmbeddedResource Include="Forms\Ocr\BinaryOcrTrain.resx">
<DependentUpon>BinaryOcrTrain.cs</DependentUpon> <DependentUpon>BinaryOcrTrain.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>