public HexcellsSolver(HexPatternParameter pparam) { _patternParameter = pparam; Dictionary <string, Bitmap> refdic = new Dictionary <string, Bitmap>(); refdic.Add("-", Properties.Resources.pattern_dash); refdic.Add("{", Properties.Resources.pattern_Open); refdic.Add("}", Properties.Resources.pattern_Close); refdic.Add("?", Properties.Resources.pattern_QMark); refdic.Add("0", Properties.Resources.pattern_0); refdic.Add("1", Properties.Resources.pattern_1); refdic.Add("2", Properties.Resources.pattern_2); refdic.Add("3", Properties.Resources.pattern_3); refdic.Add("4", Properties.Resources.pattern_4); refdic.Add("5", Properties.Resources.pattern_5); refdic.Add("6", Properties.Resources.pattern_6); refdic.Add("7", Properties.Resources.pattern_7); refdic.Add("8", Properties.Resources.pattern_8); refdic.Add("9", Properties.Resources.pattern_9); refdic.Add("10", Properties.Resources.pattern_10); refdic.Add("12", Properties.Resources.pattern_12); refdic.Add("13", Properties.Resources.pattern_13); refdic.Add("14", Properties.Resources.pattern_14); refdic.Add("15", Properties.Resources.pattern_15); refdic.Add("16", Properties.Resources.pattern_16); refdic.Add("17", Properties.Resources.pattern_17); refdic.Add("18", Properties.Resources.pattern_18); refdic.Add("19", Properties.Resources.pattern_19); POCR = new PatternOCR(refdic, OCRCoupling.NORMAL_COUPLED_SEGMENTS); Cam = new HexCam(); OCR = new HexOCR(POCR); }
public Bitmap DisplayBinPattern(Bitmap shot, HexOCR ocr) { shot = new Bitmap(shot); bool[,] pattern = ocr.GetPattern(shot); var centers = ocr.GetHexPatternCenters(pattern, shot.Width, shot.Height); var grid = ocr.GetHexPatternGrid(centers); var counter = ocr.GetCounterArea(shot); BitmapData srcData = shot.LockBits(new Rectangle(0, 0, shot.Width, shot.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); IntPtr Scan0 = srcData.Scan0; int stride = srcData.Stride; int width = shot.Width; int height = shot.Height; unsafe { byte *p = (byte *)(void *)Scan0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int idx = (y * stride) + x * 4; bool on = pattern[x, y] || counter.Item1.Includes(x, y); p[idx + 0] = (byte)(on ? 0 : 255); p[idx + 1] = (byte)(on ? 0 : 255); p[idx + 2] = (byte)(on ? 0 : 255); p[idx + 3] = 255; } } } shot.UnlockBits(srcData); using (Graphics g = Graphics.FromImage(shot)) { Pen pen = new Pen(Color.Magenta); foreach (var center in centers) { g.DrawLine(pen, (int)(center.X - 5), (int)(center.Y - 5), (int)(center.X + 5), (int)(center.Y + 5)); g.DrawLine(pen, (int)(center.X + 5), (int)(center.Y - 5), (int)(center.X - 5), (int)(center.Y + 5)); } foreach (var row in grid.Item1) { g.DrawLine(pen, row, 0, row, shot.Height); } foreach (var col in grid.Item2) { g.DrawLine(pen, 0, col, shot.Width, col); } g.DrawRectangle(pen, counter.Item2.bl.X, counter.Item2.bl.Y, counter.Item2.Width, counter.Item2.Height); g.DrawRectangle(pen, counter.Item3.bl.X, counter.Item3.bl.Y, counter.Item3.Width, counter.Item3.Height); } return(shot); }