Exemplo n.º 1
0
        private void Process()
        {
            Bitmap bitmapFromScreen = BitmapService.BitmapFromScreen(CaptureArea.Width, CaptureArea.Height, CaptureArea.Left, CaptureArea.Top, this.comboBoxScreen.SelectedIndex);

            pictureBox1.Image = bitmapFromScreen;


            projectionBitMapFilter = ProjectionService.ProjectandFilter(SelectedColor, Convert.ToInt32(this.numericUpDownColorMargin.Value), bitmapFromScreen);
            ProjectionsToChartSeries(projectionBitMapFilter);
            ProjectionsToChartSeries(projectionBitMapFilter);
            this.pictureBox2.Image = projectionBitMapFilter.Bitmap;

            projectionBitMapFilter.HorizontalSegments = ProjectionService.ToSegments(projectionBitMapFilter.HorizontalProjection, projectionBitMapFilter.Bitmap.Height);
            projectionBitMapFilter.VerticalSegments   = new List <Segment>();

            if (SubtitlesDetected(projectionBitMapFilter.HorizontalSegments))
            {
                long  Range        = projectionBitMapFilter.HorizontalSegments[0].End - projectionBitMapFilter.HorizontalSegments[0].Starts;
                Int64 AverageRange = MathHelper.Average(Ranges);

                projectionBitMapFilter.VerticalSegments = ProjectionService.ToSegments(projectionBitMapFilter.VerticalProjection, projectionBitMapFilter.Bitmap.Height);

                if (projectionBitMapFilter.VerticalSegments.Count != 0)
                {
                    projectionBitMapFilter = ProjectionService.MaxMinEvaluation(bitmapFromScreen.Height, projectionBitMapFilter);

                    List <Segment> GroupedSegments = SegmentationService.GroupSegments(projectionBitMapFilter.VerticalSegments);

                    Bitmap bitmapInitialSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();
                    Bitmap bitmapGroupedSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();

                    this.pictureBox2.Image                = BitmapService.DrawSegmentsinBitmap(projectionBitMapFilter.VerticalSegments, bitmapInitialSegments, Brushes.DarkRed);
                    this.pictureBoxGrouped.Image          = BitmapService.DrawSegmentsinBitmap(GroupedSegments, bitmapGroupedSegments, Brushes.Orange);
                    projectionBitMapFilter.CroppedBitmaps = BitmapService.ExtractCropBitmaps(GroupedSegments, projectionBitMapFilter.Bitmap);


                    foreach (Bitmap crop in projectionBitMapFilter.CroppedBitmaps)
                    {
                        var margin = BitmapService.CorrectMargin(crop);

                        projectionBitMapFilter.CorrectedMarginBitmaps.Add(margin);
                    }



                    List <char> predictions = new List <char>();

                    foreach (Bitmap bitmap in projectionBitMapFilter.CorrectedMarginBitmaps)
                    {
                        Bitmap resized = BitmapService.ResizeImage(bitmap, 32, 32);

                        projectionBitMapFilter.ResizedBitmaps.Add(resized);

                        string zerosandones = DatasetGenerator.ToZerosOnesSequence(' ', resized);

                        var c = PredictionService.Predict(zerosandones);
                        predictions.Add(c);

                        x++;
                    }

                    BitmapsToScreen(projectionBitMapFilter.ResizedBitmaps);

                    AddTextBoxToScreen(projectionBitMapFilter.CroppedBitmaps.Count, predictions);
                }
            }
        }