示例#1
0
        public void EventLayoutChanged()
        {
            if (PageFileSelected == null)
            {
                return;
            }
            bitmapSource = new Bitmap(PageFileSelected);
            if (bitmapSource == null)
            {
                return;
            }

            if ((bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) ||
                (bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                bitmapSource = ToolsConvolution.ConvertTo24(bitmapSource);
            }
            PageLayout.Save();

            //Rotate
            var bitmapRot             = new RotateBilinear(PageLayout.Rotation.Value, true).Apply(bitmapSource);
            var linesH                = ToolsFindLine.FindLinesH(bitmapRot.Width, bitmapRot.Height, PageLayout.LineSize.Value, PageLayout.LineOffset.Value, PageLayout.LineCount.Value);
            var linesV                = ToolsFindLine.FindLinesV(bitmapRot.Width, bitmapRot.Height, PageLayout.ColSize.Value, PageLayout.ColOffset.Value, PageLayout.ColCount.Value);
            List <RenderLine> rl_list = new List <RenderLine>();

            rl_list.AddRange(linesH);
            rl_list.AddRange(linesV);


            //var linesV = ToolsFindLine.FindLinesV(bitmapRot.Width, bitmapRot.Height, PageLayout.LineSize.Value, PageLayout.LineOffset.Value);
            ImageLayout = RenderBitmap(bitmapRot, rl_list);
        }
示例#2
0
        public ModelToken(IModelApplication application, string filePathImage, string filePathJson)
        {
            _application   = application;
            _filePathImage = filePathImage;
            _filePathJson  = filePathJson;
            _bitmapSource  = new Bitmap(filePathImage);

            if ((_bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) ||
                (_bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                _bitmapSource = ToolsConvolution.ConvertTo24(_bitmapSource);
            }

            Bitmap bitmapTemp = new Grayscale(1, 0, 0).Apply(_bitmapSource);

            bitmapTemp = new Erosion().Apply(bitmapTemp);
            bitmapTemp = new Threshold(160).Apply(bitmapTemp);
            bitmapTemp = new Invert().Apply(bitmapTemp);

            _kernel    = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5);
            _threshold = new ModelValueDouble(application.EventTokenChanged, 0);
            _weigth    = new ModelValueDouble(application.EventTokenChanged, 0);


            ModelRendererBitmapSource renderer = new ModelRendererBitmapSource(_bitmapSource);

            renderer.Render();
            Image = renderer.RenderedImage;



            ModelRendererBitmapSource rendererProcessed = new ModelRendererBitmapSource(bitmapTemp);

            rendererProcessed.Render();
            ImageProcessed = rendererProcessed.RenderedImage;

            if (File.Exists(filePathJson))
            {
                Load();
            }
            else
            {
                this._threshold = new ModelValueDouble(_application.EventTokenChanged, 0.8);
                this._weigth    = new ModelValueDouble(_application.EventTokenChanged, 1.0);
                this._label     = filePathImage.Split('_')[1];
                Save();
            }
        }
示例#3
0
        private void ExecuteParseAll()
        {
            if (PageFileSelected == null)
            {
                return;
            }
            bitmapSource = new Bitmap(PageFileSelected);
            if (bitmapSource == null)
            {
                return;
            }
            if ((bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) ||
                (bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                bitmapSource = ToolsConvolution.ConvertTo24(bitmapSource);
            }


            //Rotate
            var bitmapRot             = new RotateBilinear(PageLayout.Rotation.Value, true).Apply(bitmapSource);
            var linesH                = ToolsFindLine.FindLinesH(bitmapRot.Width, bitmapRot.Height, PageLayout.LineSize.Value, PageLayout.LineOffset.Value, PageLayout.LineCount.Value);
            var linesV                = ToolsFindLine.FindLinesV(bitmapRot.Width, bitmapRot.Height, PageLayout.ColSize.Value, PageLayout.ColOffset.Value, PageLayout.ColCount.Value);
            List <RenderLine> rl_list = new List <RenderLine>();

            rl_list.AddRange(linesH);
            rl_list.AddRange(linesV);

            //Convert to gray
            Bitmap bitmapTemp = new Grayscale(1, 0, 0).Apply(bitmapRot);

            bitmapTemp = new Erosion().Apply(bitmapTemp);
            bitmapTemp = new Threshold(160).Apply(bitmapTemp);
            bitmapTemp = new Invert().Apply(bitmapTemp);


            //Tuple<List<ConnectedComponent>, double, double>[] componentSectionList = new Tuple<List<ConnectedComponent>, double, double>[1];
            //Bitmap[] BitmapArray = new Bitmap[1];
            Tuple <List <ConnectedComponent>, double, double>[,] componentTable = new Tuple <List <ConnectedComponent>, double, double> [PageLayout.LineCount.Value, PageLayout.ColCount.Value];

            for (int lineIndex = 0; lineIndex < PageLayout.LineCount.Value; lineIndex++)
            {
                for (int colIndex = 0; colIndex < PageLayout.ColCount.Value; colIndex++)
                {
                    //TODO add margin?
                    int    x      = (int)((PageLayout.ColSize.Value * colIndex) + PageLayout.ColOffset.Value); // - PageLayout.Margin.Value;
                    int    y      = (int)((PageLayout.LineSize.Value * lineIndex) + PageLayout.LineOffset.Value) - PageLayout.Margin.Value;
                    int    w      = (int)PageLayout.ColSize.Value;                                             // + (PageLayout.Margin.Value * 2);
                    int    h      = (int)PageLayout.LineSize.Value + (PageLayout.Margin.Value * 2);
                    Bitmap bitmap = new Crop(new Rectangle(x, y, w, h)).Apply(bitmapTemp);
                    List <ConnectedComponent> lineComponentList = new List <ConnectedComponent>();
                    lineComponentList = GetTokens(bitmap);
                    componentTable[lineIndex, colIndex] = new Tuple <List <ConnectedComponent>, double, double>(lineComponentList, x, y);
                }
            }

            //ImageParse = RenderBitmap(bitmapRot, rl_list, componentTable);
            ImageLayout = RenderBitmap(bitmapRot, rl_list, componentTable);
            //Create output
            string[,] string_table = new string[PageLayout.LineCount.Value, PageLayout.ColCount.Value];
            for (int i = 0; i < PageLayout.LineCount.Value; i++)
            {
                for (int j = 0; j < PageLayout.ColCount.Value; j++)
                {
                    string_table[i, j] = TokensToString(componentTable[i, j].Item1, 3, " ");
                }
            }
            string csvFileSelected = LayoutFileSelected.Replace(".png", ".csv");

            ToolsIOCSV.WriteCSVFile(csvFileSelected, string_table, KozzionCore.IO.CSV.Delimiter.SemiColon);
        }