public ManagedBitmap(NikseBitmap nbmp) { Width = nbmp.Width; Height = nbmp.Height; _colors = new Color[Width * Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { SetPixel(x, y, nbmp.GetPixel(x, y)); } } }
public ManagedBitmap(Bitmap oldBitmap) { NikseBitmap nbmp = new NikseBitmap(oldBitmap); Width = nbmp.Width; Height = nbmp.Height; _colors = new Color[Width * Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { this.SetPixel(x, y, nbmp.GetPixel(x, y)); } } }
public NOcrChar GetMatch(NikseBitmap nbmp) { const int NocrMinColor = 300; const int topMargin = 1; double widthPercent = nbmp.Height * 100.0 / nbmp.Width; foreach (NOcrChar oc in OcrCharacters) { if (Math.Abs(widthPercent - oc.WidthPercent) < 20 && Math.Abs(oc.MarginTop - topMargin) < 5) { // only very accurate matches bool ok = true; var index = 0; while (index < oc.LinesForeground.Count && ok) { NOcrPoint op = oc.LinesForeground[index]; foreach (Point point in op.ScaledGetPoints(oc, 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 + c.G + c.B > NocrMinColor) { } else { Point p = new Point(point.X - 1, point.Y); if (p.X < 0) p.X = 1; c = nbmp.GetPixel(p.X, p.Y); if (nbmp.Width > 20 && 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, 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 + c.G + c.B > NocrMinColor) { Point p = new Point(point.X, point.Y); if (oc.Width > 19 && point.X > 0) p.X = p.X - 1; 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 bool IsMatch() { NikseBitmap nbmp = new NikseBitmap(pictureBoxCharacter.Image as Bitmap); foreach (NOcrPoint op in _nocrChar.LinesForeground) { 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 + c.G + c.B > VobSubOcr.NocrMinColor) { } else { return false; } } } } foreach (NOcrPoint op in _nocrChar.LinesBackground) { 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 + c.G + c.B > VobSubOcr.NocrMinColor) { return false; } } } } return true; }
private static bool IsMatchPointForeGround(NOcrPoint op, bool loose, NikseBitmap nbmp, NOcrChar nOcrChar) { if (Math.Abs(op.Start.X - op.End.X) < 2 && Math.Abs(op.End.Y - op.Start.Y) < 2) return false; 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) { } else { return false; } if (loose) { 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) { } else { return false; } } 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) { } else { 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) { } else { 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) { } else { return false; } } } } } return true; }