Barcode Recognition Problem - Datamatrix

Hi Imran.

unfortunately, we have again a problem with recognition of datamatrix barcodes from pdf.

We are using the latest dll's:

Aspose.Barcode 5.7.0.0
Aspose.Pdf 8.4.1

See attached file.

Please note: I've allready tested the same file in black&white, and the barcode could be readed.
Are there any special settings for colored pdf's?

Thank you.

Christian

Hi Christian,


Thanks for your inquiry. I tested your sample Pdf file against the latest builds of Aspose.BarCode 5.7.0.0 and Aspose.Pdf 8.4.1. I’m not able to reproduce the recognition problem. Please try the following source code below:

int imageIndex = 0;

// bind the pdf

PdfConverter converter = new PdfConverter();

converter.BindPdf(PDFLocalPath);

converter.DoConvert();

while (converter.HasNextImage())

{

MemoryStream ImgStream = new MemoryStream();

converter.GetNextImage(ImgStream, ImageFormat.Png);

imageIndex++;

using (BarCodeReader reader = new BarCodeReader(ImgStream, BarCodeReadType.DataMatrix))

{

while (reader.Read())

{

Console.WriteLine("Code Text: " + reader.GetCodeText() + " Type: " + reader.GetReadType());

}

}

<span style=“font-size:9.5pt;line-height:115%;font-family:Consolas;mso-fareast-font-family:
“Times New Roman”;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA”>}


Please do let know in case any confusion or questions.

Hi Imran.

Thank you for your code.
I've tested it and it works - the code was recognized.

The difference to my code (which fails recognition) was, that i was using the PDFExtractor-Class instead of the PdfConverter():

Aspose.Pdf.Facades.PdfExtractor extractor = new Aspose.Pdf.Facades.PdfExtractor();
extractor.BindPdf(source);
extractor.StartPage = 1;
extractor.EndPage = 1;
extractor.ExtractImage();
if (!extractor.HasNextImage()) return 0;
extractor.GetNextImage(ms);
ms.Position = 0;
reader = new BarCodeReader(ms, BarCodeReadType.DataMatrix);
reader.ImageBinarizationHints = RecognitionHints.ImageBinarization.MedianSmoothing;
while (reader.Read())
{
BarCode.Add(reader.GetCodeText());
}

May be you can talk with the aspose.pdf team and tell me the reason why it fails with the extractor.

An other difference: should i still use ImageBinarization.MedianSmoothing for better results or leave it unset? (it is working with and without that parameter)

Christian

Hi Christian,


Thanks for your inquiry. I’m even able to recognize the bar code image through PdfExtractor class. You need to set the orientation angle as 270 degrees before scanning.

// bind the pdf document<o:p></o:p>

PdfExtractor pdfExtractor = new PdfExtractor();

pdfExtractor.BindPdf(PDFLocalPath);

Console.WriteLine("Extracting images.....");

pdfExtractor.ExtractImage();

int i = 0;

// save images to stream in a loop

while (pdfExtractor.HasNextImage())

{

Console.WriteLine("Getting next image....");

i++;

// save image to stream

MemoryStream imageStream = new MemoryStream();

pdfExtractor.GetNextImage(imageStream, ImageFormat.Png);

BarCodeReader barcodeReader = new BarCodeReader(imageStream, BarCodeReadType.DataMatrix);

barcodeReader.OrientationHints = RecognitionHints.Orientation.Rotate270;

while (barcodeReader.Read())

{

Console.WriteLine(i + " Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetReadType().ToString());

}

// close the reader

barcodeReader.Close();

}


I can see in the Pdf file that the bar code is not rotated but PdfExtractor class is extracting rotated bar code images. Please refer to the Aspose.Pdf product team. I’m moving this thread to the Aspose.Total forum. My colleague from Aspose.Pdf product family will reply you shortly. We’re sorry for your inconvenience.

MedianSmoothing is a filter and removes the noise from the image while preserving the image edges. It depends on the images if the images are not noisy then you can leave it unset.

Please do let me know in case of any confusion or questions.

Hi Christian,


We are sorry for the inconvenience caused. While testing the scenario with latest version of Aspose.Pdf for .NET, I’ve also noticed that rotated image is being extracted instead upright and logged the issue as PDFNEWNET-35826 in our issue tracking system for further investigation. We will keep you updated about the issue progress via this forum thread. As a workaround, as Imran suggested above you can set image orientation for bar code recognition.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tital.

at the moment, we will use the PdfConverter-Class and getting good results with the default 150dpi-Resolution and RenderingOptions.BarcodeOptimization = true.

To aprove recognition, we have also added a second and third detection loop with RecognitionHints.Orientation.Rotate90 and .Rotate270 in our BarCodeReader-Section.

Regardless of the rotation-bug - what is better (detect and decode barcodes in pdf-files) - Extractor or Converter? What are the pros and cons of both classes?

Christian.

Hi Christian,


Thanks for your feedback. In general PdfExtractor extracts individual images from PDF document whereas PdfConverter coverts PDF document page to image. PdfExtractor extracts images without losing original image quality and by default PdfConverter converts Pdf page to image with 150 resolution, however you can change it according to your need. Moreover, in vector based PDF documents bar codes are not represented as images but lines so PdfConverter must be used in such cases.

In short you can use either of these classes for barcode recognition with vector based PDF document exception.

Please let me know if I can be of any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-35826) have been fixed in Aspose.Pdf for .NET 8.9.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Christian,


Thanks for your patience.

As the image is rotated on contents, and in order to generate correct output, please try using ImagePlacement approach. Please take a look over following code snippet.

[C#]

ImagePlacementAbsorber abs = new
ImagePlacementAbsorber();<o:p></o:p>

Document doc = new Document(inFile);

doc.Pages[1].Accept(abs);

foreach (ImagePlacement imagePlacement in abs.ImagePlacements)

{

using (Stream fileStream = File.Create(outFile))

{

imagePlacement.Save(fileStream);

}

}