Beispiel #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);
        }
Beispiel #2
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);
        }