Exemplo n.º 1
0
        public List <List <int> > Parse(string scanPdfPath)
        {
            Mat[] scansBin;
            using (var scansPath = Gs.PdfToJpeg(scanPdfPath, $"Scans_{Guid.NewGuid()}", "scan"))
            {
                scansBin = scansPath.Files
                           .Select(path => Cv2.ImRead(path, ImreadModes.Grayscale))
                           .Select(mat => mat.GaussianBlur(
                                       new Size(KernelSize, KernelSize),
                                       GaussianSigma,
                                       GaussianSigma))
                           .Select(mat => mat.Threshold(BinThreshold, 255, ThresholdTypes.Binary))
                           .ToArray();
            }

            for (int i = 0; i < scansBin.Length; i++)
            {
                var scan = scansBin[i];
                Cv2.BitwiseNot(scan, scan);

                Deskew(scan);
            }
            var checks = FindChecks(scansBin);

            return(checks);
        }
 public LocatorModel(string templatePdfPath)
 {
     TemplatePdfPath = templatePdfPath;
     using (var templates = Gs.PdfToJpeg(TemplatePdfPath, $"Templates_{Guid.NewGuid()}", "template"))
     {
         TemplateImgs = templates.Files.Select(path =>
         {
             using (var stream = File.OpenRead(path))
             {
                 return(Image.FromStream(stream));
             }
         }).ToArray();
     }
     if (TemplateImgs.Length == 0)
     {
         throw new Exception("Invalid template pdf file");
     }
     Locations = new Dictionary <int, List <Point> > [TemplateImgs.Length];
     for (int i = 0; i < Locations.Length; i++)
     {
         Locations[i] = new Dictionary <int, List <Point> >();
     }
 }