Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, May 14, 2019 1:42:14 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 202

Was thanked: 9 time(s) in 9 post(s)

Attached is a project that will load all files in a given directory and try to detect if any MICRs are present using the MICRCodeDetectionCommand and CMC7CodeDetectionCommand commands.

Once the zones are found on every page, a redaction annotation is added and burned into the image and then saved out. Here is the relevant code:

Code:
static void DetectRedact(string file)
      {
         AnnWinFormsRenderingEngine renderingEngine = new AnnWinFormsRenderingEngine();

         var dir = Path.Combine(Path.GetDirectoryName(file), "Redacted");
         if (!Directory.Exists(dir))
            Directory.CreateDirectory(dir);
         string outFile = Path.Combine(dir, Path.GetFileNameWithoutExtension(file) + "_redacted.tif");

         int totalPages = codecs.GetTotalPages(file);
         for (int i = 1; i <= totalPages; i++)
            using (RasterImage image = codecs.Load(file, i))
            {
               AnnContainer container = new AnnContainer();
               container.Mapper.MapResolutions(image.XResolution, image.YResolution, image.XResolution, image.YResolution);
               container.Size = container.Mapper.SizeToContainerCoordinates(image.ImageSize.ToLeadSizeD());

               MICRCodeDetectionCommand detectionCommand = new MICRCodeDetectionCommand();
               detectionCommand.Run(image);
               if (detectionCommand.MICRZone != LeadRect.Empty && detectionCommand.MICRZone.Width > 0 && detectionCommand.MICRZone.Height > 0)
               {
                  AnnRedactionObject redaction = new AnnRedactionObject
                  {
                     Rect = container.Mapper.RectToContainerCoordinates(detectionCommand.MICRZone.ToLeadRectD()),
                     Fill = AnnSolidColorBrush.Create("Black")
                  };
                  container.Children.Add(redaction);
               }

               CMC7CodeDetectionCommand cmc7DetectionCommand = new CMC7CodeDetectionCommand();
               cmc7DetectionCommand.Run(image);
               if (cmc7DetectionCommand.CMC7Zone != LeadRect.Empty && cmc7DetectionCommand.CMC7Zone.Width > 0 && cmc7DetectionCommand.CMC7Zone.Height > 0)
               {
                  AnnRedactionObject redaction = new AnnRedactionObject
                  {
                     Rect = container.Mapper.RectToContainerCoordinates(cmc7DetectionCommand.CMC7Zone.ToLeadRectD()),
                     Fill = AnnSolidColorBrush.Create("Black")
                  };
                  container.Children.Add(redaction);
               }

               var img = renderingEngine.RenderOnImage(container, image.Clone());

               codecs.Save(img, outFile, RasterImageFormat.TifJpeg411, 24, 1, 1, 1, CodecsSavePageMode.Append);
            }
      }


File Attachment(s):
micr_redact.zip (4kb) downloaded 52 time(s).
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Thursday, March 26, 2020 9:09:43 AM(UTC)
Luke Duvall

Groups: Registered, Tech Support, Administrators
Posts: 34


Updated Project to LEADTOOLS Version 20 using Visual Studio 2019

File Attachment(s):
micr_redact.zip (4kb) downloaded 2 time(s).
Luke Duvall
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.133 seconds.