We experience some problems with the Barcode recognition. We tested 2 methods for reading the barcodes: via GetAllPossibleBarcodes and via GetCodeText.
Apart from the very poor performance which both methods have, we get some strange results.
These are the testscenarios:
- Read with enhanced extractor.Resolution (300 instead of 150) AND using MedianSmoothing. Results are:
Test 1, found barcode: 8122
Test 1, found barcode: 7646
Test 1, found barcode: 51
Test 1, found barcode: 57
Test 1, found barcode: 46
Test 2, found barcode: 376
Test 2, found barcode: 376
- Read with enhanced extractor.Resolution (300 instead of 150). Results are:
Test 1, found barcode: 8122
Test 1, found barcode: 7646
Test 1, found barcode: 51
Test 1, found barcode: 57
Test 1, found barcode: 46
Test 2, found barcode: 51
Question 1: why does method 2 (via GetCodeText) return different results?
Question 2: We have some PDFs in which the quality of the barcodes is quite poor. What can we do for optimizing those PDFs/images? We experimented with Resolution and MedianSmoothing…
This is the code we use:
PdfExtractor extractor = new PdfExtractor();
extractor.BindPdf(SourcePath);
extractor.StartPage = 1;
extractor.EndPage = 1;
extractor.Resolution = 300;
extractor.ExtractImage();
int imageCounter = 0;
List result = new List();
while (extractor.HasNextImage())
{
imageCounter++;
MemoryStream stream = new MemoryStream();
extractor.GetNextImage(stream);
Bitmap bmp = new Bitmap(stream);
stream.Position = 0;
// TESTING VIA GetAllPossibleBarCodes
using (var reader = new BarCodeReader(new Bitmap(stream), BarCodeReadType.AllSupportedTypes))
{
reader.Read();
//RecognitionHints.ImageBinarization imageBinarization = RecognitionHints.ImageBinarization.MedianSmoothing;
//reader.ImageBinarizationHints = imageBinarization;
BarCodeReader.PossibleBarCode[] pb1 = reader.GetAllPossibleBarCodes();
reader.Close();
foreach (BarCodeReader.PossibleBarCode pb1s in pb1)
{
Debug.WriteLine(string.Format("Test 1, found barcode: {0}", pb1s.Codetext));
}
}
// TESTING VIA GetCodeText
using (var reader = new BarCodeReader(new Bitmap(stream), BarCodeReadType.AllSupportedTypes))
{
//RecognitionHints.ImageBinarization imageBinarization = RecognitionHints.ImageBinarization.MedianSmoothing;
//reader.ImageBinarizationHints = imageBinarization;
while (reader.Read())
{
if (!result.Contains(reader.GetCodeText()))
result.Add(reader.GetCodeText());
}
}
reader.Close();
foreach (string pb2s in result)
{
Debug.WriteLine(string.Format("Test 2, found barcode: {0}", pb2s));}
}
}
}