Fixed bug in ocr from cleanup

This commit is contained in:
niksedk 2014-03-23 19:10:53 +01:00
parent ff3e2d4cc8
commit 4562d80387
2 changed files with 8 additions and 47 deletions

View File

@ -1,9 +1,9 @@
using System;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.OCR;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.OCR;
namespace Nikse.SubtitleEdit.Forms
{
@ -11,7 +11,7 @@ namespace Nikse.SubtitleEdit.Forms
{
private List<NOcrChar> _nocrChars;
private NOcrChar _nocrChar = null;
private NOcrChar _nocrChar;
private double _zoomFactor = 5.0;
bool _drawLineOn;
bool _startDone;
@ -127,7 +127,6 @@ namespace Nikse.SubtitleEdit.Forms
private bool IsMatch()
{
NikseBitmap nbmp = new NikseBitmap(pictureBoxCharacter.Image as Bitmap);
var bmp = pictureBoxCharacter.Image as Bitmap;
foreach (NOcrPoint op in _nocrChar.LinesForeground)
{
foreach (Point point in op.ScaledGetPoints(_nocrChar, nbmp.Width, nbmp.Height))
@ -453,13 +452,14 @@ namespace Nikse.SubtitleEdit.Forms
{
int importedCount = 0;
int notImportedCount = 0;
openFileDialog1.Filter = "nOCR files|nOCR_*.xml";
openFileDialog1.Filter = "nOCR files|*.nocr";
openFileDialog1.InitialDirectory = Configuration.DataDirectory;
openFileDialog1.FileName = string.Empty;
openFileDialog1.Title = "Import existing nOCR database into current";
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
foreach (NOcrChar newChar in VobSubOcr.LoadNOcr(openFileDialog1.FileName))
NOcrDb newDb = new NOcrDb(openFileDialog1.FileName);
foreach (NOcrChar newChar in newDb.OcrCharacters)
{
bool found = false;
foreach (NOcrChar oldChar in _nocrChars)

View File

@ -4191,45 +4191,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
public static List<NOcrChar> LoadNOcr(string fileName)
{
var nocrChars = new List<NOcrChar>();
if (File.Exists(fileName))
{
try
{
var doc = new XmlDocument();
doc.Load(fileName);
foreach (XmlNode node in doc.DocumentElement.SelectNodes("Char"))
{
var oc = new NOcrChar(node.Attributes["Text"].Value);
oc.Width = Convert.ToInt32(node.Attributes["Width"].Value, CultureInfo.InvariantCulture);
oc.Height = Convert.ToInt32(node.Attributes["Height"].Value, CultureInfo.InvariantCulture);
oc.MarginTop = Convert.ToInt32(node.Attributes["MarginTop"].Value, CultureInfo.InvariantCulture);
if (node.Attributes["Italic"] != null)
oc.Italic = Convert.ToBoolean(node.Attributes["Italic"].Value, CultureInfo.InvariantCulture);
if (node.Attributes["ExpandCount"] != null)
oc.ExpandCount = Convert.ToInt32(node.Attributes["ExpandCount"].Value, CultureInfo.InvariantCulture);
foreach (XmlNode pointNode in node.SelectNodes("Point"))
{
var op = new NOcrPoint(DecodePoint(pointNode.Attributes["Start"].Value), DecodePoint(pointNode.Attributes["End"].Value));
XmlAttribute a = pointNode.Attributes["On"];
if (a != null && Convert.ToBoolean(a.Value))
oc.LinesForeground.Add(op);
else
oc.LinesBackground.Add(op);
}
nocrChars.Add(oc);
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
return nocrChars;
}
public static List<NOcrChar> LoadNOcrForTesseract(string xmlRessourceName)
{
var nocrChars = new List<NOcrChar>();
@ -5683,7 +5644,7 @@ namespace Nikse.SubtitleEdit.Forms
string fileName = GetNOcrLanguageFileName();
if (!string.IsNullOrEmpty(fileName))
{
LoadNOcr(fileName);
_nOcrDb = new NOcrDb(fileName);
}
}