Free Support Forum - aspose.com

Can you specify a specific area to scan for barcodes?

Is it possible to define an are of an image to scan only? For instance, if you have a SOP within your business for putting barcodes onto documents within a 3x3 square of the top corner (left or right) could you then tell the barcodereader to only look at that left or right area? I think that could/would DRASTICALLY improve performace.

If this is possible already, please share! I need help!

Thank you,
Kiel

Not to answer my own question, but, after some time I figure out how to do this. I have cut down SIGNIFICANT time in processing files by doing this.

The code takes a multipage tiff (or any other single page image), cuts out a 350px x 350px chunk from the top right corner and scans that for a barcode. It builds an array that notifies you of which pages in the original document have barcodes. I have commented out an optional step to save the cropped sections so you can see if your barcodes are within the area or not.

Hope this helps someone else! Let me know if something doesnt work right.

string FullFilePath = "FILEPATH";

string FileName = Path.GetFileName(FILEPATH);

//Get number of pages, store in "totalFrame"
System.Drawing.Image img = System.Drawing.Image.FromFile(FullFilePath);
Guid guid = img.FrameDimensionsList[0];
FrameDimension dimension = new FrameDimension(guid);
int totalFrame = img.GetFrameCount(dimension);

BarCodeReader rd = null;

//Create array (where size=numpages as a maximum) to keep track of pages with barcodes
string[] codepages = new string[totalFrame];

//create counters
int j = 0, k;
string pagenums = "Barcode found on pages:"; //used for output message

for (int i = 0; i < totalFrame; i++)
{

// Set the active page and feed it to the BarCodeReader
img.SelectActiveFrame(dimension, i);

// This is where the cropped corner is created
Bitmap ImgCrop = new Bitmap(img).Clone(new Rectangle(img.Width - 350, 0, 350, 350), PixelFormat.Format24bppRgb);

// OPTIONAL LINE TO SAVE CORNER
//ImgCrop.Save(Server.MapPath("~/SandBox/") + Guid.NewGuid().ToString().Substring(0, 5) + "_pg" + i.ToString() +".jpg", ImageFormat.Jpeg);

rd = new BarCodeReader(new Bitmap(ImgCrop), BarCodeReadType.DataMatrix);
rd.SetHints(RecognitionHints.OrientationHints.RightToLeft);
rd.SetHints(RecognitionHints.ImageBinarizationHints.MedianSmoothing);

k = 0;

while (rd.Read())

{

j = j + 1;

k = k + 1;

}

pagenums += " Page " + i.ToString() + " (" + k + ") | ";

rd.Close();

}
//OPTIONAL line to output a message box in browser to display results
Response.Write("");

Hi,

Currently, the barcode reader scans the whole image for detecting barcodes. We will do some analysis about adding the scan area/region to detect barcode from only that part of the image.

I have added it as “New feature” in our issue tracking system (ID: 14176). We will notify you when we make some progress about this issue.

The code in my previous reply successfully does what I described. You can use that code for your idea.....orrrr I could use it for a "demo app" instead of doing the case study option before I buy the product.

Did you try it? I dont have a use, but, I could make it be a user selectable area of the document if I wanted to.

Hi,

For the “demo application”, you may download it at https://github.com/aspose-barcode/Aspose.BarCode-for-.NET.