Can't extract barcode value from these jpgs

Hi,


We make an intensive use of the Aspose barcode reader, we use it to read barcodes from like 3000 document/day.

The library fails to read barcodes ( or gives wrong value ) in some cases, where the codebare is clear and other libraries ( http://demo.leadtools.com/OnlineRecognitionDemo/default.aspx ) give the expected value very fast ( 22ms, but this is more due to the native code speed ).

Please find attached 34 samples of those documents :

Guid.jpeg => Aspose BarCode couldn’t extract the barcode
Guid #barcode => it did but the barcode value is wrong

The barcode is a 128Code and should be something like : “00100 PER000184412050614003897971”. They all must start with "00100 ".



Here is our code :
public static IEnumerable ReadBarCodesFromPdf(string filePath, int barcodePerPage = 1, float relativeX = 0, float relativeY = 0, float relativeWidth = 1, float relativeHeight = 1, BarCodeReadType codeType = BarCodeReadType.AllSupportedTypes)
{
if (System.IO.Path.GetExtension(filePath).ToLower() != “.pdf”)
yield break;

using (var pdf = new Aspose.Pdf.Document(filePath))
for (int i = 0; i < pdf.Pages.Count; ++i)
{
var abs = new ImagePlacementAbsorber();
pdf.Pages[i + 1].Accept(abs);
foreach( ImagePlacement imagePlacement in abs.ImagePlacements)
{
var xImage = imagePlacement.Image;
using (var memStream = new MemoryStream())
{
var barCode = default(string);
var barCodeRegion = default(BarCodeRegion);
xImage.Save(memStream);

var strbuilder = new StringBuilder();
using (var bitmap = new Bitmap(memStream))
{
var imguid = Guid.NewGuid();
bitmap.Save(string.Format(“e:\{0}.jpeg”, imguid));
using (var barcodeReader = new BarCodeReader(bitmap, new System.Drawing.Rectangle((int)(bitmap.Width * relativeX), (int)(bitmap.Height * relativeY), (int)(bitmap.Width * relativeWidth), (int)(bitmap.Height * relativeHeight)), codeType))
{
barcodeReader.ExpectedBarCodeCount = barcodePerPage;
barcodeReader.Timeout = 30000;
var nb = barcodePerPage;
while (nb-- > 0)
{
try
{

var readValue = false;
Thread taskThread = null;
var task = Task.Factory.StartNew(() => {taskThread = Thread.CurrentThread; readValue = barcodeReader.Read(); }, TaskCreationOptions.LongRunning);
Task.WaitAll(new Task[] { task }, 35000);
//try
//{
// if (!task.IsCompleted && taskThread != null)
// taskThread.Abort();
//}
//catch(NullReferenceException ex) // il peut devenir null entre temps
//{ }
// GC.Collect();
if (!readValue)
break;
}
catch (Exception ex)
{
_log.Error(string.Format(“Error when trying to extract from file {0} | page : {1}”, filePath, i), ex);
break;
}
var region = barcodeReader.GetRegion();
if (region != null)
{
barCode = barcodeReader.GetCodeText();

bitmap.Save(string.Format(“e:\{0} #{1}.jpeg”, imguid, barCode));
barCodeRegion = region;
yield return new BarCode(i + 1, barCodeRegion, barCode);
_log.InfoFormat(“BarCode : {0}”, barCode);
break;
}
}
}
}
}
}
}
}


We use the version 6.0.0, we haven’t seen a resolved ticket in the new versions that could solve this.


Thanks in advance,

Hi Yassine,


Thank you for contacting support. We’re looking into the matter and will get back to you soon.

Hi Yassine,

Thank you for being patient. We’ve tested all your sample barcode images against the latest build of Aspose.BarCode 6.3.0. We can recognize them as follows:

string[] files = Directory.GetFiles(folderPath);

foreach (string file in files)

{

using (BarCodeReader reader = new BarCodeReader(file, readerType))

{

while (reader.Read())

{

Console.WriteLine(Path.GetFileName(file) + "--Symbol:" + reader.GetReadType() + " Code :" + reader.GetCodeText());

}

Console.WriteLine();

}

}

We could not recognize an image (61abf66b-ab80-4233-aa8a-6c8e7217a0b4.jpeg) as there is no barcode. The resultant notepad file has been uploaded along this reply. We recommend using the latest version of Aspose.BarCode for .NET 6.3.0. Please refer to the download page:
http://www.aspose.com/community/files/51/.net-components/aspose.barcode-for-.net/default.aspx

Please feel free to reply us back in case of any confusion or questions.

Thank you for your quick answer,


We will update to the latest version as it reads most of them.

Still there are two bar codes in the attached results.txt which were not correctly read :

608b2b55-882c-4b44-8d31-7ac35c25f7cb #523121810940614040021000025395384317021
99904.jpeg–Symbol:Code128 Code :52312189253710404002100002539541433102199907

LeadTools
Type: Code 128
Data: 00100 NAR000210004040614008608231

6a6d4ce3-784d-413a-aba2-a27f7a158dea.jpeg–Symbol:Code128 Code :39100# M(Pm* 5h$
0BGIhSd

LeadTools : no result

Thanks in advance,

Yassine

Hi Yassine,


Thank you for your inquiry. We managed to replicate the problem of incorrect recognition. We’ve logged these issues as follows:

File Name: 608b2b55-882c-4b44-8d31-7ac35c25f7cb #52312181094061404002100002539538431702199904.jpeg
BARCODENET-33921 - Incorrect recognition of Code128 from the JPEG file

File Name: 6a6d4ce3-784d-413a-aba2-a27f7a158dea.jpeg
BARCODENET-33922 - Incorrect recognition of Code128 from the JPEG file

Your request has also been linked to these issues. We’ll keep you informed regarding any updates in this regard. We’re sorry for your inconvenience.

Hi Yassine,

In addition to the above reply, as a workaround, you can recognize it by applying orientation settings as follows:


string path = @"C:\AB\test240\error\608b2b55-882c-4b44-8d31-7ac35c25f7cb #52312181094061404002100002539538431702199904.jpeg";
using (BarCodeReader reader = new BarCodeReader(path, BarCodeReadType.Code128))
{

reader.OrientationHints = RecognitionHints.Orientation.Rotate180;
while (reader.Read())
{

Console.WriteLine(Path.GetFileName(path) + "--Symbol:" + reader.GetReadType() + " Code :" + reader.GetCodeText());

}
}

Result:
608b2b55-882c-4b44-8d31-7ac35c25f7cb #523121810940614040021000025395384317021
99904.jpeg–Symbol:Code128 Code :00100 NAR000210004040614008608231

Hi Yassine,


Thank you for being patient. We have a good news for you that the issue id BARCODENET-33922 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.BarCode for .NET 7.0.0. We’ll inform you via this forum thread as soon as the new release is published.

Hi Yassine,


Thank you for being patient. We have a good news for you that the issue id BARCODENET-33921 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.BarCode for .NET 7.0.0. We’ll inform you via this forum thread as soon as the new release is published.

The issues you have found earlier (filed as BARCODENET-33922;BARCODENET-33921) have been fixed in Aspose.BarCode for .NET 7.0.0.


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