本文整理汇总了C#中Nikse.SubtitleEdit.Logic.Ocr.NOcrChar类的典型用法代码示例。如果您正苦于以下问题:C# NOcrChar类的具体用法?C# NOcrChar怎么用?C# NOcrChar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NOcrChar类属于Nikse.SubtitleEdit.Logic.Ocr命名空间,在下文中一共展示了NOcrChar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadOcrCharacters
public void LoadOcrCharacters()
{
var list = new List<NOcrChar>();
var listExpanded = new List<NOcrChar>();
if (!File.Exists(FileName))
{
OcrCharacters = list;
OcrCharactersExpanded = listExpanded;
return;
}
using (Stream gz = new GZipStream(File.OpenRead(FileName), CompressionMode.Decompress))
{
bool done = false;
while (!done)
{
var ocrChar = new NOcrChar(gz);
if (ocrChar.LoadedOk)
{
if (ocrChar.ExpandCount > 0)
listExpanded.Add(ocrChar);
else
list.Add(ocrChar);
}
else
{
done = true;
}
}
}
OcrCharacters = list;
OcrCharactersExpanded = listExpanded;
}
示例2: Add
public void Add(NOcrChar ocrChar)
{
if (ocrChar.ExpandCount > 0)
OcrCharactersExpanded.Insert(0, ocrChar);
else
OcrCharacters.Insert(0, ocrChar);
}
示例3: AddHistoryItem
private void AddHistoryItem(NOcrChar nocrChar)
{
if (_historyIndex > 0 && _historyIndex < _history.Count - 1)
{
while (_history.Count > _historyIndex + 1)
_history.RemoveAt(_history.Count - 1);
_historyIndex = _history.Count - 1;
}
_history.Add(new NOcrChar(nocrChar));
_historyIndex++;
}
示例4: Initialize
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink)
{
listBoxLinesForeground.Items.Clear();
listBoxlinesBackground.Items.Clear();
NikseBitmap nbmp = new NikseBitmap(vobSubImage);
nbmp.ReplaceTransparentWith(Color.Black);
vobSubImage = nbmp.GetBitmap();
radioButtonHot.Checked = true;
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_nocrChar = new NOcrChar();
_nocrChar.MarginTop = character.Y - character.ParentY;
_imageWidth = character.NikseBitmap.Width;
_imageHeight = character.NikseBitmap.Height;
_drawLineOn = false;
_warningNoNotForegroundLinesShown = false;
buttonShrinkSelection.Visible = showShrink;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.NikseBitmap.GetBitmap();
Bitmap org = (Bitmap)vobSubImage.Clone();
Bitmap bm = new Bitmap(org.Width, org.Height);
Graphics g = Graphics.FromImage(bm);
g.DrawImage(org, 0, 0, org.Width, org.Height);
g.DrawRectangle(Pens.Red, character.X, character.Y, character.NikseBitmap.Width, character.NikseBitmap.Height - 1);
g.Dispose();
pictureBoxSubtitleImage.Image = bm;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
SizePictureBox();
checkBoxItalic.Checked = italicChecked;
_history = new List<NOcrChar>();
_historyIndex = -1;
_nocrChar.Width = _imageWidth;
_nocrChar.Height = _imageHeight;
GenerateLineSegments(150, false, _nocrChar, new NikseBitmap(pictureBoxCharacter.Image as Bitmap));
ShowOcrPoints();
pictureBoxCharacter.Invalidate();
}
示例5: NOcrChar
public NOcrChar(NOcrChar old)
{
LinesForeground = new List<NOcrPoint>();
LinesBackground = new List<NOcrPoint>();
Text = old.Text;
Width = old.Width;
Height = old.Height;
MarginTop = old.MarginTop;
Italic = old.Italic;
foreach (NOcrPoint p in old.LinesForeground)
LinesForeground.Add(new NOcrPoint(new Point(p.Start.X, p.Start.Y), new Point(p.End.X, p.End.Y)));
foreach (NOcrPoint p in old.LinesBackground)
LinesBackground.Add(new NOcrPoint(new Point(p.Start.X, p.Start.Y), new Point(p.End.X, p.End.Y)));
}
示例6: TestNOcrSaveLoad
public void TestNOcrSaveLoad()
{
string tempFileName = Path.GetTempFileName();
var db = new NOcrDb(tempFileName);
var nOcrChar = new NOcrChar("t");
nOcrChar.ExpandCount = 0;
nOcrChar.Italic = false;
nOcrChar.MarginTop = 2;
nOcrChar.Width = 10;
nOcrChar.Height = 10;
nOcrChar.LinesForeground.Add(new NOcrPoint(new Point(1, 1), new Point(2, 2)));
nOcrChar.LinesBackground.Add(new NOcrPoint(new Point(3, 4), new Point(5, 6)));
db.Add(nOcrChar);
var nOcrChar2 = new NOcrChar("u");
nOcrChar2.ExpandCount = 0;
nOcrChar2.Italic = false;
nOcrChar2.MarginTop = 3;
nOcrChar2.Width = 12;
nOcrChar2.Height = 12;
nOcrChar2.LinesForeground.Add(new NOcrPoint(new Point(1, 1), new Point(2, 2)));
nOcrChar2.LinesBackground.Add(new NOcrPoint(new Point(3, 4), new Point(5, 6)));
db.Add(nOcrChar2);
db.Save();
db = new NOcrDb(tempFileName);
Assert.IsTrue(db.OcrCharacters.Count == 2);
Assert.IsTrue(db.OcrCharacters[0].Text == nOcrChar2.Text);
Assert.IsTrue(db.OcrCharacters[0].Italic == nOcrChar2.Italic);
Assert.IsTrue(db.OcrCharacters[0].MarginTop == nOcrChar2.MarginTop);
Assert.IsTrue(db.OcrCharacters[0].LinesForeground.Count == nOcrChar2.LinesForeground.Count);
Assert.IsTrue(db.OcrCharacters[0].LinesForeground[0].Start.X == nOcrChar2.LinesForeground[0].Start.X);
Assert.IsTrue(db.OcrCharacters[0].LinesForeground[0].Start.Y == nOcrChar2.LinesForeground[0].Start.Y);
Assert.IsTrue(db.OcrCharacters[0].LinesBackground.Count == nOcrChar2.LinesBackground.Count);
Assert.IsTrue(db.OcrCharacters[0].LinesBackground[0].Start.X == nOcrChar2.LinesBackground[0].Start.X);
Assert.IsTrue(db.OcrCharacters[0].LinesBackground[0].Start.Y == nOcrChar2.LinesBackground[0].Start.Y);
Assert.IsTrue(db.OcrCharacters[1].Text == nOcrChar.Text);
try
{
File.Delete(tempFileName);
}
catch
{
}
}
示例7: GenerateLineSegments
public static void GenerateLineSegments(int numberOfLines, bool veryPrecise, NOcrChar nOcrChar, NikseBitmap nbmp)
{
int giveUpCount = 10000;
var r = new Random();
int count = 0;
int hits = 0;
bool tempVeryPrecise = veryPrecise;
while (hits < numberOfLines && count < giveUpCount)
{
var start = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
var end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
if (hits < 5 && count < 100) // a few large lines
{
for (int k = 0; k < 500; k++)
{
if (Math.Abs(start.X - end.X) + Math.Abs(start.Y - end.Y) > nOcrChar.Height / 2)
{
break;
}
else
{
end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
}
}
}
else // and a lot of small lines
{
for (int k = 0; k < 500; k++)
{
if (Math.Abs(start.X - end.X) + Math.Abs(start.Y - end.Y) < 5)
{
break;
}
else
{
end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
}
}
}
var op = new NOcrPoint(start, end);
bool ok = true;
foreach (NOcrPoint existingOp in nOcrChar.LinesForeground)
{
if (existingOp.Start.X == op.Start.X && existingOp.Start.Y == op.Start.Y &&
existingOp.End.X == op.End.X && existingOp.End.Y == op.End.Y)
ok = false;
}
if (ok && IsMatchPointForeGround(op, !tempVeryPrecise, nbmp, nOcrChar))
{
nOcrChar.LinesForeground.Add(op);
//AddHistoryItem(nOcrChar);
hits++;
}
count++;
if (count > giveUpCount - 100 && !tempVeryPrecise)
tempVeryPrecise = true;
}
count = 0;
hits = 0;
tempVeryPrecise = veryPrecise;
while (hits < numberOfLines && count < giveUpCount)
{
var start = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
var end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
if (hits < 5 && count < 100) // a few large lines
{
for (int k = 0; k < 500; k++)
{
if (Math.Abs(start.X - end.X) + Math.Abs(start.Y - end.Y) > nOcrChar.Height / 2)
{
break;
}
else
{
end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
}
}
}
else // and a lot of small lines
{
for (int k = 0; k < 500; k++)
{
if (Math.Abs(start.X - end.X) + Math.Abs(start.Y - end.Y) < 5)
{
break;
}
else
{
end = new Point(r.Next(nOcrChar.Width), r.Next(nOcrChar.Height));
}
}
}
var op = new NOcrPoint(start, end);
bool ok = true;
foreach (NOcrPoint existingOp in nOcrChar.LinesBackground)
//.........这里部分代码省略.........
示例8: IsMatchPointBackGround
private static bool IsMatchPointBackGround(NOcrPoint op, bool loose, NikseBitmap nbmp, NOcrChar nOcrChar)
{
foreach (Point point in op.ScaledGetPoints(nOcrChar, nbmp.Width, nbmp.Height))
{
if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(point.X, point.Y);
if (c.A > 150 && c.R + 100 + c.G + c.B > VobSubOcr.NocrMinColor)
{
return false;
}
if (nbmp.Width > 10 && point.X + 1 < nbmp.Width)
{
c = nbmp.GetPixel(point.X + 1, point.Y);
if (c.A > 150 && c.R + 100 + c.G + c.B > VobSubOcr.NocrMinColor)
{
return false;
}
}
if (loose)
{
if (nbmp.Width > 10 && point.X >= 1)
{
c = nbmp.GetPixel(point.X - 1, point.Y);
if (c.A > 150 && c.R + 100 + c.G + c.B > VobSubOcr.NocrMinColor)
{
return false;
}
}
if (nbmp.Height > 10 && point.Y + 1 < nbmp.Height)
{
c = nbmp.GetPixel(point.X, point.Y + 1);
if (c.A > 150 && c.R + 100 + c.G + c.B > VobSubOcr.NocrMinColor)
{
return false;
}
}
if (nbmp.Height > 10 && point.Y >= 1)
{
c = nbmp.GetPixel(point.X, point.Y - 1);
if (c.A > 150 && c.R + 100 + c.G + c.B > VobSubOcr.NocrMinColor)
{
return false;
}
}
}
}
}
return true;
}
示例9: Undo
private void Undo()
{
_drawLineOn = false;
_startDone = false;
if (_history.Count > 0 && _historyIndex > 0)
{
_historyIndex--;
_nocrChar = new NOcrChar(_history[_historyIndex]);
}
else if (_historyIndex == 0)
{
var c = new NOcrChar(_nocrChar);
c.LinesForeground.Clear();
c.LinesBackground.Clear();
_nocrChar = c;
_historyIndex--;
}
ShowOcrPoints();
}
示例10: Redo
private void Redo()
{
if (_history.Count > 0 && _historyIndex < _history.Count - 1)
{
_historyIndex++;
_nocrChar = new NOcrChar(_history[_historyIndex]);
ShowOcrPoints();
}
}
示例11: listBoxFileNames_SelectedIndexChanged
private void listBoxFileNames_SelectedIndexChanged(object sender, EventArgs e)
{
labelNOcrCharInfo.Text = string.Empty;
if (listBoxFileNames.SelectedIndex < 0)
return;
_nocrChar = listBoxFileNames.Items[listBoxFileNames.SelectedIndex] as NOcrChar;
if (_nocrChar == null)
{
pictureBoxCharacter.Invalidate();
groupBoxCurrentCompareImage.Enabled = false;
listBoxLinesForeground.Items.Clear();
listBoxlinesBackground.Items.Clear();
}
else
{
textBoxText.Text = _nocrChar.Text;
checkBoxItalic.Checked = _nocrChar.Italic;
pictureBoxCharacter.Invalidate();
groupBoxCurrentCompareImage.Enabled = true;
labelNOcrCharInfo.Text = string.Format("Size: {0}x{1}, margin top: {2} ", _nocrChar.Width, _nocrChar.Height, _nocrChar.MarginTop);
if (pictureBoxCharacter.Image != null)
{
if (IsMatch())
{
groupBoxCurrentCompareImage.BackColor = Color.LightGreen;
}
else
{
groupBoxCurrentCompareImage.BackColor = Control.DefaultBackColor;
}
}
_drawLineOn = false;
_history = new List<NOcrChar>();
_historyIndex = -1;
if (_bitmap == null)
{
var bitmap = new Bitmap(_nocrChar.Width, _nocrChar.Height);
var nbmp = new NikseBitmap(bitmap);
nbmp.Fill(Color.White);
pictureBoxCharacter.Image = nbmp.GetBitmap();
SizePictureBox();
ShowOcrPoints();
bitmap.Dispose();
}
}
}
示例12: listBoxInspectItems_SelectedIndexChanged
private void listBoxInspectItems_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBoxInspectItems.SelectedIndex < 0)
return;
var img = _imageList[listBoxInspectItems.SelectedIndex];
if (img.NikseBitmap != null)
{
pictureBoxInspectItem.Width = img.NikseBitmap.Width;
pictureBoxInspectItem.Height = img.NikseBitmap.Height;
var old = img.NikseBitmap.GetBitmap();
pictureBoxInspectItem.Image = old;
pictureBoxCharacter.Image = old;
SizePictureBox();
}
else
{
pictureBoxInspectItem.Image = null;
pictureBoxCharacter.Image = null;
}
var match = _matchList[listBoxInspectItems.SelectedIndex];
if (match == null)
{ // spaces+new lines
_nocrChar = null;
pictureBoxCharacter.Invalidate();
buttonUpdate.Enabled = false;
buttonDelete.Enabled = false;
buttonEditDB.Enabled = false;
buttonAddBetterMatch.Enabled = false;
textBoxText.Text = string.Empty;
textBoxText.Enabled = false;
checkBoxItalic.Checked = false;
checkBoxItalic.Enabled = false;
}
else if (match.NOcrCharacter == null)
{ // no match found
buttonUpdate.Enabled = false;
buttonDelete.Enabled = false;
textBoxText.Text = string.Empty;
checkBoxItalic.Checked = match.Italic;
_nocrChar = null;
pictureBoxCharacter.Invalidate();
buttonEditDB.Enabled = true;
buttonAddBetterMatch.Enabled = true;
textBoxText.Enabled = false;
checkBoxItalic.Enabled = false;
}
else
{
buttonUpdate.Enabled = true;
buttonDelete.Enabled = true;
textBoxText.Text = match.Text;
checkBoxItalic.Checked = match.Italic;
_nocrChar = match.NOcrCharacter;
pictureBoxCharacter.Invalidate();
buttonEditDB.Enabled = true;
buttonAddBetterMatch.Enabled = true;
textBoxText.Enabled = true;
checkBoxItalic.Enabled = true;
}
}
示例13: Add
/// <summary>
/// The add.
/// </summary>
/// <param name="ocrChar">
/// The ocr char.
/// </param>
public void Add(NOcrChar ocrChar)
{
if (ocrChar.ExpandCount > 0)
{
this.OcrCharactersExpanded.Insert(0, ocrChar);
}
else
{
this.OcrCharacters.Insert(0, ocrChar);
}
}
示例14: LoadNOcrForTesseract
public static List<NOcrChar> LoadNOcrForTesseract(string xmlRessourceName)
{
var nocrChars = new List<NOcrChar>();
Assembly asm = Assembly.GetExecutingAssembly();
Stream strm = asm.GetManifestResourceStream(xmlRessourceName);
if (strm != null)
{
XmlDocument doc = new XmlDocument();
var rdr = new StreamReader(strm);
using (var zip = new System.IO.Compression.GZipStream(rdr.BaseStream, System.IO.Compression.CompressionMode.Decompress))
{
byte[] data = new byte[175000];
zip.Read(data, 0, 175000);
doc.LoadXml(Encoding.UTF8.GetString(data));
}
rdr.Close();
try
{
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;
}
示例15: ScaledGetPoints
public List<Point> ScaledGetPoints(NOcrChar nOcrChar, int width, int height)
{
return GetPoints(this.GetScaledStart(nOcrChar, width, height), this.GetScaledEnd(nOcrChar, width, height));
}