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



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


Groups: Manager, Tech Support, Administrators
Posts: 201

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:

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

         var dir = Path.Combine(Path.GetDirectoryName(file), "Redacted");
         if (!Directory.Exists(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();
               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")

               CMC7CodeDetectionCommand cmc7DetectionCommand = new CMC7CodeDetectionCommand();
               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")

               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 46 time(s).
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.


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.

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.105 seconds.