public JsonResult PostImage([FromForm] IFormFile body)
        {
            byte[] imageBytes;
            string newFileName = new TimeSpan(DateTime.Now.Ticks).TotalMilliseconds.ToString();

            newFileName = newFileName.Substring(0, newFileName.IndexOf('.')) + ".png";
            Image page = null;

            using (var memoryStream = new MemoryStream())
            {
                body.CopyTo(memoryStream);
                page = Image.FromStream(memoryStream);
                OCR.S3Upload.Upload.UploadDocument("pdfidentify", newFileName, memoryStream, RegionEndpoint.USEast2);
            }
            Thread.Sleep(5000);


            Console.Out.WriteLine(newFileName);
            TextractResponse response = Analyze.AnalyzeFile(newFileName).Result;


            //Dictionary of every block indexed by ID
            Dictionary <string, Block> allBlocks = new Dictionary <string, Block>();

            foreach (var block in response.Blocks)
            {
                allBlocks.Add(block.Id, block);
            }


            //for each table block, save all children
            //for each child, save all children
            int          i            = 1;
            List <Block> targetBlocks = new List <Block>();
            List <BoundingBoxIdentifier> boundingBoxes = new List <BoundingBoxIdentifier>();

            foreach (var table in response.FilterType("TABLE"))
            {
                Analyze.GetChildrenRecursive(allBlocks, table, targetBlocks);

                BoundingBox boundingBox = table.Geometry.BoundingBox;
                //Convert relative location to absolute pixels
                BoundingBoxIdentifier identifier = new BoundingBoxIdentifier((int)(page.Width * boundingBox.Left),
                                                                             (int)(page.Height * boundingBox.Top),
                                                                             (int)(page.Width * boundingBox.Width),
                                                                             (int)(page.Height * boundingBox.Height),
                                                                             i++.ToString(),
                                                                             table.Id);

                boundingBoxes.Add(identifier);
            }

            PreservedData preservedData = new PreservedData(targetBlocks, boundingBoxes);


            return(Json(preservedData));
        }
        /// <summary>
        /// Compares the specified first image.
        /// </summary>
        /// <param name="firstImage">The first image.</param>
        /// <param name="secondImage">The second image.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Bitmaps must be the same size.</exception>
        public Image Compare(Image firstImage, Image secondImage)
        {
            Guard.AssertNotNull(firstImage, nameof(firstImage));
            Guard.AssertNotNull(secondImage, nameof(secondImage));

            if (firstImage.Width != secondImage.Width || firstImage.Height != secondImage.Height)
            {
                throw new ArgumentException("Bitmaps must be the same size.");
            }

            var differenceMap    = BitmapAnalyzer.Analyze(firstImage, secondImage);
            var differenceLabels = Labeler.Label(differenceMap);
            var boundingBoxes    = BoundingBoxIdentifier.CreateBoundingBoxes(differenceLabels);
            var differenceBitmap = CreateImageWithBoundingBoxes(secondImage, boundingBoxes);

            return(differenceBitmap);
        }
Beispiel #3
0
        public Bitmap Compare(Bitmap firstImage, Bitmap secondImage)
        {
            if (firstImage == null)
            {
                throw new ArgumentNullException("firstImage");
            }
            if (secondImage == null)
            {
                throw new ArgumentNullException("secondImage");
            }
            if (firstImage.Width != secondImage.Width || firstImage.Height != secondImage.Height)
            {
                throw new ArgumentException("Bitmaps must be the same size.");
            }

            var differenceMap    = BitmapAnalyzer.Analyze(firstImage, secondImage);
            var differenceLabels = Labeler.Label(differenceMap);
            var boundingBoxes    = BoundingBoxIdentifier.CreateBoundingBoxes(differenceLabels);
            var differenceBitmap = CreateImageWithBoundingBoxes(secondImage, boundingBoxes);

            return(differenceBitmap);
        }