コード例 #1
0
        public void TaxiEuler()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_taxiPng))
                using (Bitmap bitmap = new Bitmap(stream))
                {
                    IMonomap monomap = new Monomap(bitmap);
                    var      euler   = EulerCharacteristicComputer.Compute2D(monomap);
                    Assert.AreEqual(euler.S0, 3);
                    Assert.AreEqual(euler.S1, 3);
                    Assert.AreEqual(euler.S2, 3);
                    Assert.AreEqual(euler.S3, 3);

                    Assert.AreEqual(euler.S4, 0);
                    Assert.AreEqual(euler.S5, 0);
                    Assert.AreEqual(euler.S6, 0);
                    Assert.AreEqual(euler.S7, 0);

                    Assert.AreEqual(euler.S8, 2);
                    Assert.AreEqual(euler.S9, 2);

                    Assert.AreEqual(euler.S10, 0);
                    Assert.AreEqual(euler.S11, 0);
                    Assert.AreEqual(euler.S12, 0);
                    Assert.AreEqual(euler.S13, 0);

                    Assert.AreEqual(euler.S14, 0);
                }
        }
コード例 #2
0
        public void HalfTaxiEuler()
        {
            IMonomap monomap = new BitMonomap(_bitImage);
            var      euler   = EulerCharacteristicComputer.Compute2D(monomap);

            Assert.AreEqual(euler.S0, 2);
            Assert.AreEqual(euler.S1, 2);
            Assert.AreEqual(euler.S2, 2);
            Assert.AreEqual(euler.S3, 2);

            Assert.AreEqual(euler.S4, 0);
            Assert.AreEqual(euler.S5, 0);
            Assert.AreEqual(euler.S6, 0);
            Assert.AreEqual(euler.S7, 0);

            Assert.AreEqual(euler.S8, 1);
            Assert.AreEqual(euler.S9, 1);

            Assert.AreEqual(euler.S10, 0);
            Assert.AreEqual(euler.S11, 0);
            Assert.AreEqual(euler.S12, 0);
            Assert.AreEqual(euler.S13, 0);

            Assert.AreEqual(euler.S14, 0);
        }
コード例 #3
0
        public void DiffEuler()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_malevichInvertedPng))
                using (Bitmap bitmap = new Bitmap(stream))
                {
                    IMonomap monomap     = new Monomap(bitmap);
                    var      copyMonomap = monomap.Clone();
                    var      euler       = EulerCharacteristicComputer.Compute2D(monomap);
                    var      copyEuler   = EulerCharacteristicComputer.Compute2D(copyMonomap);

                    euler = euler - copyEuler;

                    Assert.AreEqual(euler.S0, 0);
                    Assert.AreEqual(euler.S1, 0);
                    Assert.AreEqual(euler.S2, 0);
                    Assert.AreEqual(euler.S3, 0);

                    Assert.AreEqual(euler.S4, 0);
                    Assert.AreEqual(euler.S5, 0);
                    Assert.AreEqual(euler.S6, 0);
                    Assert.AreEqual(euler.S7, 0);

                    Assert.AreEqual(euler.S8, 0);
                    Assert.AreEqual(euler.S9, 0);

                    Assert.AreEqual(euler.S10, 0);
                    Assert.AreEqual(euler.S11, 0);
                    Assert.AreEqual(euler.S12, 0);
                    Assert.AreEqual(euler.S13, 0);

                    Assert.AreEqual(euler.S14, 0);
                }
        }
コード例 #4
0
        public void MalevichInvertedEuler()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_malevichInvertedPng))
                using (Bitmap bitmap = new Bitmap(stream))
                {
                    IMonomap monomap = new Monomap(bitmap);
                    var      euler   = EulerCharacteristicComputer.Compute2D(monomap);
                    Assert.AreEqual(euler.S0, 1);
                    Assert.AreEqual(euler.S1, 1);
                    Assert.AreEqual(euler.S2, 1);
                    Assert.AreEqual(euler.S3, 1);

                    Assert.AreEqual(euler.S4, 4);
                    Assert.AreEqual(euler.S5, 4);
                    Assert.AreEqual(euler.S6, 4);
                    Assert.AreEqual(euler.S7, 4);

                    Assert.AreEqual(euler.S8, 0);
                    Assert.AreEqual(euler.S9, 0);

                    Assert.AreEqual(euler.S10, 1);
                    Assert.AreEqual(euler.S11, 1);
                    Assert.AreEqual(euler.S12, 1);
                    Assert.AreEqual(euler.S13, 1);

                    Assert.AreEqual(euler.S14, 0);
                }
        }
コード例 #5
0
ファイル: DefaultScanner.cs プロジェクト: devowl/quick-ocr
        /// <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);
        }
コード例 #6
0
        private void InternalGenerateEulerValue(
            char[] sourceChars,
            Font font,
            int minSize,
            int maxSize,
            List <Symbol> symbols)
        {
            foreach (char chr in sourceChars)
            {
                for (int size = minSize; size < maxSize + 1; size++)
                {
                    // TODO Что бы красиво выводить побуквенно идут по размерам каждой буквы, иначе тут лучше не вертикально а горизонтально по слою проходить
                    using (var newFont = new Font(font.FontFamily, size, font.Style, GraphicsUnit.Pixel))
                    {
                        IMonomap monomap = PrintChar(chr, newFont);
                        int      height  = GetFontHeight(monomap);

                        if (height < minSize)
                        {
                            continue;
                        }

                        var euler = EulerCharacteristicComputer.Compute2D(monomap);

                        var        chr1       = chr;
                        Symbol     symbol     = symbols.First(s => s.Chr == chr1);
                        SymbolCode symbolCode = new SymbolCode(height, euler);

                        lock (_syncObject)
                        {
                            symbol.Codes.Add(symbolCode);
                        }

                        BitmapCreated?.Invoke(this, new BitmapEventArgs(monomap.ToBitmap(), newFont, chr));
                    }
                }
            }
        }
コード例 #7
0
        public void MalevichInvertedImagesHaveSimularEuler()
        {
            using (Stream stream1 = Assembly.GetExecutingAssembly().GetManifestResourceStream(_malevichInvertedPng))
                using (Bitmap bitmap1 = new Bitmap(stream1))
                {
                    using (Stream stream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream(_malevichInvertedBorderedPng))
                        using (Bitmap bitmap2 = new Bitmap(stream2))
                        {
                            IMonomap monomap1 = new Monomap(bitmap1);
                            var      euler1   = EulerCharacteristicComputer.Compute2D(monomap1);

                            IMonomap monomap2 = new Monomap(bitmap2);
                            var      euler2   = EulerCharacteristicComputer.Compute2D(monomap2);

                            Assert.AreEqual(euler1.S0, euler2.S0);
                            Assert.AreEqual(euler1.S1, euler2.S1);
                            Assert.AreEqual(euler1.S2, euler2.S2);
                            Assert.AreEqual(euler1.S3, euler2.S3);

                            Assert.AreEqual(euler1.S4, euler2.S4);
                            Assert.AreEqual(euler1.S5, euler2.S5);
                            Assert.AreEqual(euler1.S6, euler2.S6);
                            Assert.AreEqual(euler1.S7, euler2.S7);

                            Assert.AreEqual(euler1.S8, euler2.S8);
                            Assert.AreEqual(euler1.S9, euler2.S9);

                            Assert.AreEqual(euler1.S10, euler2.S10);
                            Assert.AreEqual(euler1.S11, euler2.S11);
                            Assert.AreEqual(euler1.S12, euler2.S12);
                            Assert.AreEqual(euler1.S13, euler2.S13);

                            Assert.AreEqual(euler1.S14, euler2.S14);
                        }
                }
        }