コード例 #1
0
        private void FillFormWithPictures(SubMatrix matrix)
        {
            ImageCreator creator = new ImageCreator();

            pictures.Add(creator.CreateImageOutOfMatrix(matrix));
            var lines = new Splitters.LineSplitter().SplitToLines(matrix);

            pictures.AddRange(lines.Select(r => creator.CreateImageOutOfMatrix(r)));
            lines.RemoveAll(b => b.Empty);
            var lsp = new Splitters.LetterSplitter(lines.First());

            foreach (var line in lines)
            {
                lsp.SetNewMatrix(line);
                letters.AddRange(lsp.GetLetters());
            }
            pictures.AddRange(letters.Where(mat => !mat.Empty).Select(mat => creator.CreateImageOutOfMatrix(mat)));
            pictureBoxLine.Image = pictures.First();
            index = 0;
        }
コード例 #2
0
ファイル: TestSuite.cs プロジェクト: Tobraef/OCR
        public void TestRecursiveCatch()
        {
            var testMatrix = new ImageMatrix(new Bitmap(Image.FromFile(Path.Combine(DATA.testFolder, "DefenseTest1png.png"))));
            var matrices   = DefenseMechanism.RecursiveDistinguish(testMatrix);

            if (matrices.Count != 5)
            {
                Console.WriteLine("TEST_RecursiveCatch: Count of found matrices is incorrect, received count: " + matrices.Count.ToString());
                ImageCreator crt = new ImageCreator();
                crt.CreateImageOutOfMatrix(testMatrix).Save(Path.Combine(DATA.testFolder, "TestRecursive.png"));
                int i = 0;
                foreach (var m in matrices)
                {
                    crt.CreateImageOutOfMatrix(m).Save(Path.Combine(DATA.testFolder, "TestRecursive" + i++.ToString() + ".png"));
                }
            }
            else
            {
                Console.WriteLine("TEST_RecursiveCatch: Passed");
            }
        }
コード例 #3
0
        /// <summary>
        /// Retrieves letters ignoring spaces, so outcome is a line of text.
        /// </summary>
        /// <param name="pathToImage"></param>
        /// <returns></returns>
        public IEnumerable <Bitmap> ParseToLettersImages(string pathToImage)
        {
            var            mainMatrix = new ImageMatrix(new Bitmap(Image.FromFile(pathToImage)));
            var            clr        = GetClearedTextMatrix(mainMatrix);
            var            lines      = GetLines(clr);
            LetterSplitter splitter   = new LetterSplitter(clr);
            var            letters    = lines.SelectMany(l => {
                splitter.SetNewMatrix(l);
                return(splitter.GetLetters());
            });
            List <SubMatrix> summarize = new List <SubMatrix> {
                clr
            };

            summarize.AddRange(lines);
            summarize.AddRange(letters);
            var crt = new ImageCreator();

            return(summarize.Select(a => crt.CreateImageOutOfMatrix(a)));
        }
コード例 #4
0
ファイル: TestSuite.cs プロジェクト: Tobraef/OCR
        public void TestImageMatrixReadAndWrite()
        {
            PrepareImage();
            ImageCreator creator    = new ImageCreator();
            string       matrixFile = simplePageUrl.Replace(".png", "MAT.txt");

            matrix.ToFullMatrix().SaveMatrixToFile(matrixFile);
            var   mat   = new ImageMatrix(matrixFile);
            float ratio = MatrixTools.EqualPixelRatio(matrix, mat);

            if (ratio > 0.995)
            {
                Console.WriteLine("TEST_MatrixR/W: PASSED, ratio: " + ratio.ToString());
            }
            else
            {
                Console.WriteLine("TEST_MatrixR/W: FAIL, compare ratio: " + ratio.ToString());
            }
            matrixFile = matrixFile.Replace(".txt", ".png");
            creator.CreateImageOutOfMatrix(mat).Save(matrixFile);
        }
コード例 #5
0
        private void TestDisplay()
        {
            var folder = Path.Combine(DATA.testFolder, "Test Defense");
            var qwe    = new ImageMatrix(new Bitmap(Image.FromFile(Path.Combine(folder, "qwe.png"))));
            var q      = new ImageMatrix(new Bitmap(Image.FromFile(Path.Combine(folder, "q.png"))));
            var w      = new ImageMatrix(new Bitmap(Image.FromFile(Path.Combine(folder, "w.png"))));
            var e      = new ImageMatrix(new Bitmap(Image.FromFile(Path.Combine(folder, "e.png"))));

            qwe = qwe.CopyMatrix(new MatrixTools(qwe).TrimWhiteAreaAround());
            q   = q.CopyMatrix(new MatrixTools(q).TrimWhiteAreaAround());
            w   = w.CopyMatrix(new MatrixTools(w).TrimWhiteAreaAround());
            e   = e.CopyMatrix(new MatrixTools(e).TrimWhiteAreaAround());
            qwe = MatrixTools.Scale(qwe, 150, 50);
            q   = MatrixTools.Scale(q);
            w   = MatrixTools.Scale(w);
            e   = MatrixTools.Scale(e);
            var crt    = new ImageCreator();
            var result = Splitters.DefenseMechanism.SplitToSingleLetters(qwe, new List <ImageMatrix> {
                q, w, e
            });

            pictures.AddRange(result.Select(a => crt.CreateImageOutOfMatrix(a)));
            pictureBoxLine.Image = pictures.First();
        }
コード例 #6
0
        private void Button2_Click(object sender, EventArgs e)
        {
            Collect();
            var crt = new ImageCreator();

            pictures             = new Splitters.MatrixSplitter(textBoxLetter.Text).Letters.Select(l => crt.CreateImageOutOfMatrix(l)).ToList();
            pictureBoxLine.Image = pictures.First();
        }