Esempio n. 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            //Add to dataset

            var textboxs = this.panel2.Controls;

            int samples = 0;

            foreach (TextBox tx in textboxs)
            {
                if (tx.Text != String.Empty)
                {
                    //TO CHECK
                    var zi       = tx.Text;
                    var i        = Convert.ToInt32(tx.Name);
                    var bit      = projectionBitMapFilter.ResizedBitmaps[i];
                    var sequence = DatasetGenerator.ToZerosOnesSequence(Convert.ToChar(zi), bit);

                    projectionBitMapFilter.ResizedBitmaps[i].Save(Variables.datasetimagespath + tx.Text + @".bmp");

                    FileWriter.AddLine(sequence, Variables.datasetpath);
                }
            }

            MessageBox.Show(samples + " new samples have been added");
        }
Esempio n. 2
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);
                }
            }
        }