Qr code from pdf is not recognized

for a new project i want to test aspose.barcode. but unfortunately only 50% of the QR code is recognized. am i doing something wrong? Or why are the QR codes not recognized?

using Aspose.BarCode;
using Aspose.BarCode.BarCodeRecognition;
using Aspose.BarCode.ComplexBarcode;
using Aspose.Pdf;

using Aspose.Pdf.Devices;
using System;
using System.Drawing.Imaging;
using System.IO;

namespace ConsoleApp11
{
class Program
{
// PDF Path import
public const string dataDirPDF = “C:\Daten\Aspose\”;

    static void Main(string[] args)
    {            
        // List all PDF's in Folder
        DirectoryInfo d = new DirectoryInfo(@dataDirPDF);
        FileInfo[] Files = d.GetFiles("*.pdf"); 
        
        foreach (FileInfo file in Files)
        {   
            // Create PNG from PDF
            ReadQRCode(file.FullName);
        }
               
        Console.WriteLine("Abgeschlossen");
        Console.ReadLine();
    }
  
    static void ReadQRCode(string filename)
    {
        Aspose.BarCode.License license = new Aspose.BarCode.License();
        license.SetLicense("Aspose.BarCode.lic");

        Console.WriteLine(filename);

        try
        {
            // Bind the pdf document
            Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
            pdfExtractor.BindPdf(filename);
            
            // Extract the images
            pdfExtractor.ExtractImage();

            // Save images to stream in a loop
            while (pdfExtractor.HasNextImage())
            {
                // Save image to stream
                MemoryStream imageStream = new MemoryStream();
                pdfExtractor.GetNextImage(imageStream);
                imageStream.Position = 0;
                int found = 0;

                // Recognize the barcode from the image stream above
                using (BarCodeReader reader = new BarCodeReader(imageStream, DecodeType.QR))
                {
                    foreach (BarCodeResult barcodeResult in reader.ReadBarCodes())
                    {
                        found = 1;
                        var result = barcodeResult.CodeText.Split(new string[] { "\n" }, StringSplitOptions.None);

                        Console.WriteLine("************");
                        Console.WriteLine("Zeile 3 " + result[3]);
                        Console.WriteLine("Zeile 28 " + result[28]);
                        Console.WriteLine("************");
                        Console.WriteLine("\n");
                   
                    }
                }
                if (found == 0) {
                    Console.WriteLine("no QR Found");
                }

            }
           
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

    }

}

}
for example this qr code is not recognized
qr-factsheet.pdf (133.6 KB)

@Giani,

Please notice, I am able to reproduce the issue as you mentioned using your template file and sample code. I found QR code is not recognized by Aspose.BarCode for .NET recognition engine. I have logged a ticket with an id " BARCODENET-37754" for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Thanks for the quick reply

@Giani,

You are welcome.

Main problem in your code that QR in pdf file is not image. You can check that with this code.

int index = 0;
// Save images to stream in a loop
while (pdfExtractor.HasNextImage())
{
MemoryStream imageStream = new MemoryStream();
pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;
index++;
using (FileStream fstr = new FileStream(@“d:\save\rec\imgs” + index.ToString() + “.png”, FileMode.Create))
{
imageStream.CopyTo(fstr);
}
}

To solve this problem you should render PDF file to the image.
TestPDF.zip (1.4 KB)
You can call

TestPDF.RecognizeFromPDF(filename, 1, DecodeType.QR);

from the attached file (and yes i Will update the article when I have time).

hello alexander

thank you for your help

i thought its not necessary to create an image. in a earlier version i made images
and nothing was recognized there either. Maybe the reason is that it is swiss qr code.

Yes but TestPDF.RecognizeFromPDF(filename, 1, DecodeType.QR); recognizes it well.

hello aleskander

you are right. the qr codes are now recognized. the ones that are not recognized i can’t read on the smartphone either. i guess the scan quality is too bad.

thank you for your help

You can attach that bad barcode and we will add it ti our database. It is possible that we will found restoration method for that distortions in next releases.

hi alexander

i attached 3 examples with bad barcodes. i think the reason is to bad quality in the scanprocess.
i will show in the next 1-2 weeks the result my boss and then we will order the license. thank you for your help.

Examples.zip (65.4 KB)

Yes, problem with target patterns(black squares in three barcode corners which are surrounded other squares). Internal squares must be fully filled with black color. You can paint them (squares) in some image editor and these barcodes will be read well.