public void ExternalPointsTest() { // 1000 // [ ] [X] [ ] [ ] //1000 // [ ] [ ] [X] [X] // [ ] [ ] [X] [X] // [ ] [ ] [ ] [ ] BitmapPad pad = new BitmapPad(); pad.SetPoint(1000, 1000); pad.SetPoint(999, 999); pad.SetPoint(1001, 1000); pad.SetPoint(1000, 1001); pad.SetPoint(1001, 1001); Assert.AreEqual(pad.Width, 3); Assert.AreEqual(pad.Height, 3); Assert.AreEqual(pad[0, 0], true); Assert.AreEqual(pad[1, 1], true); Assert.AreEqual(pad[2, 1], true); Assert.AreEqual(pad[1, 2], true); Assert.AreEqual(pad[2, 2], true); var tl = pad.TopLeftPoint; Assert.AreEqual(tl.X, 999); Assert.AreEqual(tl.Y, 999); var rb = pad.RightBottomPoint; Assert.AreEqual(rb.X, 1001); Assert.AreEqual(rb.Y, 1001); }
private void FillBitmapPad(int x, int y, EditMonomap monomap, BitmapPad pad) { var recursionStack = new Stack <LightPoint>(); recursionStack.Push(new LightPoint(x, y)); do { var currentPoint = recursionStack.Pop(); x = currentPoint.X; y = currentPoint.Y; for (int i = 0; i < _nearbyCells.Length; i++) { var nearbyCell = _nearbyCells[i]; int nextX = x + nearbyCell.X; int nextY = y + nearbyCell.Y; if (IsBlackCheckNearbyCell(nextX, nextY, monomap, pad)) { recursionStack.Push(new LightPoint(nextX, nextY)); } } } while (recursionStack.Any()); }
/// <summary> /// Распарсить изображение на более меньшие. /// </summary> /// <param name="sourceImage">Исходное распознаваемое изображение.</param> /// <returns>Список найденных фрагментов.</returns> public IList <QSymbol> GetFragments(IMonomap sourceImage) { var result = new List <QSymbol>(); var editMonomap = new EditMonomap(sourceImage); for (int y = 0; y < editMonomap.Height; y++) { for (int x = 0; x < editMonomap.Width; x++) { if (editMonomap[x, y]) { // Заполняем первую точку, что бы внутри метода проверку не делать для заполнения. BitmapPad pad = new BitmapPad(); pad.SetPoint(x, y); // Начинаем рекурсивное создание фигуры FillBitmapPad(x, y, editMonomap, pad); var symbol = new QSymbol(pad, pad.TopLeftPoint, EulerCharacteristicComputer.Compute2D(pad)); result.Add(symbol); } } } return(result); }
public void OnePointTest() { BitmapPad pad = new BitmapPad(); pad.SetPoint(1000, 1000); Assert.AreEqual(pad.Height, 1); Assert.AreEqual(pad.Width, 1); Assert.AreEqual(pad[0, 0], true); }
public void StretchPadSizeTest() { BitmapPad pad = new BitmapPad(); pad.SetPoint(0, 0); StretchPad stretchPad = new StretchPad(pad); Assert.AreEqual(stretchPad.Height, 3); Assert.AreEqual(stretchPad.Width, 3); }
private bool IsBlackCheckNearbyCell(int x, int y, IEditMonomap monomap, BitmapPad pad) { bool isBlack = monomap[x, y]; if (isBlack) { pad.SetPoint(x, y); monomap[x, y] = false; } return(isBlack); }
public void Square4x4TestPositiveCoorinates() { BitmapPad pad = new BitmapPad(); pad.SetPoint(1000, 1000); pad.SetPoint(1001, 1001); pad.SetPoint(1000, 1001); pad.SetPoint(1001, 1000); Assert.AreEqual(pad.Height, 2); Assert.AreEqual(pad.Width, 2); Assert.AreEqual(pad[0, 0], true); Assert.AreEqual(pad[1, 1], true); Assert.AreEqual(pad[0, 1], true); Assert.AreEqual(pad[1, 0], true); }
public void CleanTest() { BitmapPad pad = new BitmapPad(); pad.SetPoint(20, 20); Assert.AreEqual(pad.Height, 1); Assert.AreEqual(pad.Width, 1); pad.ClearPad(); Assert.AreEqual(pad.Height, 0); Assert.AreEqual(pad.Width, 0); pad.SetPoint(1000, 1000); Assert.AreEqual(pad.Height, 1); Assert.AreEqual(pad.Width, 1); }
public void StretchPadContantTest() { BitmapPad pad = new BitmapPad(); pad.SetPoint(0, 0); StretchPad stretchPad = new StretchPad(pad); Assert.IsFalse(stretchPad[0, 0]); Assert.IsFalse(stretchPad[1, 0]); Assert.IsFalse(stretchPad[2, 0]); Assert.IsFalse(stretchPad[0, 1]); Assert.IsTrue(stretchPad[1, 1]); Assert.IsFalse(stretchPad[2, 1]); Assert.IsFalse(stretchPad[0, 2]); Assert.IsFalse(stretchPad[1, 2]); Assert.IsFalse(stretchPad[2, 2]); }
public void LineTest() { BitmapPad pad = new BitmapPad(); pad.SetPoint(1000, 1000); pad.SetPoint(999, 999); pad.SetPoint(1001, 1001); Assert.AreEqual(pad.Height, 3); Assert.AreEqual(pad.Width, 3); Assert.AreEqual(pad[0, 0], true); Assert.AreEqual(pad[1, 1], true); Assert.AreEqual(pad[2, 2], true); Assert.AreEqual(pad[1, 0], false); Assert.AreEqual(pad[2, 0], false); Assert.AreEqual(pad[0, 1], false); Assert.AreEqual(pad[2, 1], false); Assert.AreEqual(pad[0, 2], false); Assert.AreEqual(pad[1, 2], false); }