LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Detect and Redact MICR from files
#1
Posted
:
Tuesday, May 14, 2019 1:42:14 PM(UTC)
Groups: Manager, Tech Support, Administrators
Posts: 218
Was thanked: 12 time(s) in 12 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);
}
}
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.
#2
Posted
:
Thursday, March 26, 2020 9:09:43 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 34
Updated Project to LEADTOOLS Version 20 using Visual Studio 2019
Luke Duvall
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Detect and Redact MICR from files
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.