Aspose.BarCode for .NET provides better and faster barcode recognition using the following image processing algorithms:
These settings can be useful while detecting barcodes from scanned or slightly damaged images. The probability of barcode detection will increase by this setting. |
Recognition Hints
The following code snippet shows how to use median smoothing, HLS and grayscale image processing techniques while recognizing the barcode:
[C#]
string image = @"code39Extended.jpg";
// create an instance of BarCodeReader and set image and symbology type to recognize
BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard);
// set grayscale image processing
reader.SetHints(RecognitionHints.ImageBinarizationHints.Grayscale);
// try to recognize all possible barcodes in the image
while (reader.Read())
{
// display the codetext
Console.WriteLine("Codetext: " + reader.GetCodeText());
}
// close the reader
reader.Close();
[VB.NET]
Dim image As String = "code39Extended.jpg"
' create an instance of BarCodeReader and set image and symbology type to recognize
Dim reader As BarCodeReader = New BarCodeReader(image, BarCodeReadType.Code39Standard)
' set grayscale image processing
reader.SetHints(RecognitionHints.ImageBinarizationHints.Grayscale)
' try to recognize all possible barcodes in the image
Do While reader.Read()
' display the codetext
Console.WriteLine("Codetext: " & reader.GetCodeText())
Loop
' close the reader
reader.Close()
The following code snippet shows how to use median smoothing, HLS and grayscale image processing techniques while recognizing the barcode:
[C#]
string image = @"code39Extended.jpg"; // create an instance of BarCodeReader and set image and symbology type to recognize BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard); // set grayscale image processing reader.SetHints(RecognitionHints.ImageBinarizationHints.Grayscale); // try to recognize all possible barcodes in the image while (reader.Read()) { // display the codetext Console.WriteLine("Codetext: " + reader.GetCodeText()); } // close the reader reader.Close();
[VB.NET]
Dim image As String = "code39Extended.jpg" ' create an instance of BarCodeReader and set image and symbology type to recognize Dim reader As BarCodeReader = New BarCodeReader(image, BarCodeReadType.Code39Standard) ' set grayscale image processing reader.SetHints(RecognitionHints.ImageBinarizationHints.Grayscale) ' try to recognize all possible barcodes in the image Do While reader.Read() ' display the codetext Console.WriteLine("Codetext: " & reader.GetCodeText()) Loop ' close the reader reader.Close()
Setting Threshold Value for BarCode Image
In this process the pixels, which are brighter than the specified threshold value, are set to white. By carefully choosing the threshold value, performance of barcode recognition process can be increased significantly.
There are 4 threshold values that can be set. Each one is described below:
- AutoCalculateByLine: The Barcode reader will try to automatically calculate the threshold value for each line. This setting is only valid for Pdf417 and all 1D barcodes.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard);
reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByLine);
[VB.NET]
Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard)
reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByLine)
- AutoCalculateByImage: The Barcode reader will automatically calculate the threshold value for the whole image.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard);
reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByImage);
[VB.NET]
Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard)
reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByImage)
- FixedValues: The Barcode reader will use some internally defined values (between 10 and 250) for threshold.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard);
reader.SetHints(RecognitionHints.ThresholdHints.FixedValues);
[VB.NET]
Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard)
reader.SetHints(RecognitionHints.ThresholdHints.FixedValues)
- Customized: User can set the threshold value between 1 and 255.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard);
reader.SetHints(RecognitionHints.ThresholdHints.Customized);
reader.CustomizedThreshold = 127;
[VB.NET]
Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard)
reader.SetHints(RecognitionHints.ThresholdHints.Customized)
reader.CustomizedThreshold = 127
In this process the pixels, which are brighter than the specified threshold value, are set to white. By carefully choosing the threshold value, performance of barcode recognition process can be increased significantly.
There are 4 threshold values that can be set. Each one is described below:
- AutoCalculateByLine: The Barcode reader will try to automatically calculate the threshold value for each line. This setting is only valid for Pdf417 and all 1D barcodes.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard); reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByLine);
[VB.NET]Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard) reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByLine) - AutoCalculateByImage: The Barcode reader will automatically calculate the threshold value for the whole image.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard); reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByImage);
[VB.NET]Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard) reader.SetHints(RecognitionHints.ThresholdHints.AutoCalculateByImage) - FixedValues: The Barcode reader will use some internally defined values (between 10 and 250) for threshold.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard); reader.SetHints(RecognitionHints.ThresholdHints.FixedValues);
[VB.NET]Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard) reader.SetHints(RecognitionHints.ThresholdHints.FixedValues) - Customized: User can set the threshold value between 1 and 255.
[C#]
BarCodeReader reader = new BarCodeReader("test.png", BarCodeReadType.Code39Standard); reader.SetHints(RecognitionHints.ThresholdHints.Customized); reader.CustomizedThreshold = 127;
[VB.NET]Dim reader As BarCodeReader = New BarCodeReader("test.png", BarCodeReadType.Code39Standard) reader.SetHints(RecognitionHints.ThresholdHints.Customized) reader.CustomizedThreshold = 127
