Beispiel #1
0
 public SimpleSegmentator(Config configuration, AnalyzablePage analyzablePage)
 {
     GeneticConfiguration = configuration;
     _analyzablePage = analyzablePage;
     _hystogram = Functions.FeautureScaling(Hystogram.GetHystogram(_analyzablePage.Original));
     _width = _analyzablePage.Width;
 }
Beispiel #2
0
        public AnalyzablePage GetSegmentation()
        {
            if (_solution != null)
                return _solution;

            Solve();
            _solution = Solution(BestOrganism);
            return _solution;
        }
Beispiel #3
0
        public void SegmentatePage()
        {
            AnalyzablePage page         = this;
            var            factorConfig = new List <GrayCodeConfig> {
                new GrayCodeConfig(0, 0.5), new GrayCodeConfig(0, page.Height / 5)
            };
            var config = new GeneticAlgorithm.Domain.GeneticAlgorithm.Config(0.02, 20, 0.1, factorConfig, 50, 8);

            page.Lines = new List <AnalyzableLine>();
            page       = new SimpleSegmentator(config, page).GetSegmentation();
            Lines      = page.Lines;
        }
Beispiel #4
0
        private AnalyzablePage Solution(Organism organism)
        {
            try
            {
                var triggerValue = organism.Factors[0].Value;
                var minHeight = organism.Factors[1].Value;
                var height = _hystogram.GetLength(0);
                var page = new AnalyzablePage(height,_width);

                int start = 0;

                var isLine = false;

                for (var y = 0; y < height; y++)
                {
                    var trigger = (_hystogram[y] > triggerValue);

                    if (trigger)
                    {
                        if (!isLine)
                        {
                            start = y;
                            isLine = true;
                        }
                    }
                    else
                    {
                        if (isLine)
                        {
                            int end = y;
                            var lineHeight = end - start + 1;
                            if (lineHeight > minHeight)
                                page.AddLine(new AnalyzableLine(start, lineHeight));
                            isLine = false;
                        }

                    }
                }

                return page;

            }
            catch (Exception e)
            {
                throw new Exception("Cant generate solution",e);
            }
        }
Beispiel #5
0
        private void OwlFormLoad(object sender, EventArgs e)
        {
            var bitmap = new Bitmap(100, 100);
            try
            {
                bitmap = new Bitmap(@"Data/IMAGE.BMP");
            }
            catch (ArgumentException)
            {
                Application.Exit();
            }
            var page = new AnalyzablePage(bitmap);
            var ranges = page.Ranges();
            var points = page.Summ;
            var factors = new List<GrayCode>();
            var str = new StreamWriter("Ranges.dat");
            foreach (double t in ranges)
            {
                str.WriteLine(t);
            }

            str.Close();
            var str1 = new StreamWriter("Points.dat");
            foreach (double t in points)
            {
                str1.WriteLine(t);
            }
            str1.Close(); /*
            ranges = Repositories.Functions.FeautureScaling(ranges);
            points = Repositories.Functions.FeautureScaling(points);
            factors.Add(new GrayCode(0,-1,1));
            factors.Add(new GrayCode(0, 0, 1));
            factors.Add(new GrayCode(0, 0, 1)); */
            //var geneticAlgorithm = new GeneticAlgorithm(points, ranges, factors);
            //page.Lines = geneticAlgorithm.Solve();
            page.RenderLines(imageOutput);
        }
Beispiel #6
0
 private void AnalyzePage()
 {
     AnalyzablePage page;
     Cursor = Cursors.WaitCursor;
     Enabled = false;
     try { page = new AnalyzablePage(Page); }
     catch (Exception exception)
     {
         Enabled = true;
         MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     Status.Text = @"Автоматическое построение разметки...";
     page.SegmentatePage();
     Status.Text = "";
     Enabled = true;
 }