Exemplo n.º 1
0
        private IEnumerable <IEnumerable <CsvRow> > ProcessImageGetLettersFromPage(Image <Rgba32> image, QrReaderData qrData)
        {
            var rowsPerPage     = (int)Math.Ceiling(qrData.MetaData.DataChunkSize / (double)DataOutput.MaxLettersPerRow);
            var letters         = new List <CsvRow>((int)qrData.MetaData.DataChunkSize);
            var lettersFallback = new List <CsvRow>((int)qrData.MetaData.DataChunkSize);
            var nextY           = 0;

            for (var y = 0; y < rowsPerPage; y++)
            {
                var nextRowContentArea = image.GetNextRowContentArea(nextY);
                nextY = nextRowContentArea.Y + nextRowContentArea.Height;

                var rowImage = image.Clone(img => img.Crop(nextRowContentArea));

                var currentRowLetters = y == rowsPerPage - 1
                        ? qrData.MetaData.DataChunkSize - DataOutput.MaxLettersPerRow * y : DataOutput.MaxLettersPerRow;
                var nextX = 0;
                for (var x = 0; x < currentRowLetters; x++)
                {
                    var nextLetterContentArea = rowImage.GetNextLetterContentArea(nextX);
                    nextX = nextLetterContentArea.X + nextLetterContentArea.Width;

                    var letterImage = rowImage.Clone(img =>
                                                     img.Crop(nextLetterContentArea));

                    using (var memoryStream = new MemoryStream())
                    {
                        letterImage.SaveAsBmp(memoryStream);
                        memoryStream.Seek(0, 0);
                        letters.Add(new CsvRow(_columnNameToIndex, LoadImageHelper.FileAsData(memoryStream)));
                        lettersFallback.Add(new CsvRow(_columnNameToIndex, LoadImageHelper.FileAsData(memoryStream, threshold: 90)));
                    }
                }
            }

            return(new List <IEnumerable <CsvRow> > {
                letters, lettersFallback
            });
        }
Exemplo n.º 2
0
        public void GenerateCsv()
        {
            var columnNameToIndex = new Dictionary <string, int>();

            columnNameToIndex["class"] = 0;
            for (var i = 1; i <= 1024; i++)
            {
                columnNameToIndex[$"pixel{i}"] = i;
            }
            var writer = new CsvWriter(() => new StreamWriter(new FileStream("data.csv", FileMode.Create)));

            writer.Write(Directory.GetFiles("assets").Select(fileName => new CsvRow(columnNameToIndex, LoadImageHelper.FileAsData(fileName))));
        }