Click here to Skip to main content
Email Password   helpLost your password?

Introduction

The following article describes an algorithm in VB.NET to detect 2 of 5 interleaved barcodes, which are widely used in industrial applications like document management (DMS). The algorithm can easily be extended to detect every other two-width barcode like 2 of 5 standard and Code 39.

Background

If you want to read barcodes from an image in professional applications, for example in document processing, you mainly face two problems:

  1. You have to use an expensive barcode tool, mainly because of runtime licenses.
  2. Your customer wants you to read barcode from documents which are of bad quality (fax, copies, photos, �).

The solution: Develop an algorithm on your own and tune it to the needs of your customer. This article explains how to develop a generic algorithm for two-width barcodes and a working example to read 2 of 5 interleaved.

Using the code

Scanning the barcodes is as simple as this:

Dim bmp As New Bitmap("d:\sample2of5.bmp") 
Dim scanner As New gmseNWScanner(_
        New gmseBarcodeDef2of5interleaved)
Dim result As gmseNWResult

Scanner.Scan(bmp)
For Each result In scanner.Result
    Debug.WriteLine(result.Text)
next

The main class is gmseNWScanner. It contains the generic scanning algorithm for two-width barcodes. The parameters are defined in the abstract class gmseNWBarcodeDef. The class gmseBarcodeDef2of5interleaved implements gmseNWBarcodeDef to decode 2 of 5 interleaved. The detected barcodes are saved in the following classes: gmseNWResult and gmseNWResultCollection.

Points of interest

Two-Width barcodes are represented with only two bar types: a narrow bar (n) and a wide bar (w). The tricky part is to get this representation from an image. Translating to text is straightforward. Scanning is done row by row (see chart). The array cBarWidth is computed. It contains the width of each bar in the current row. cBarWidth is scanned from left to right. The algorithm takes a subset of cBarWidth to find a candidate for a valid barcode. The subset is considered to be a candidate if the bars can be classified as narrow and wide bars. If a candidate is found, the algorithm extends the subset until a bar is found, this cannot be classified as a narrow or wide bar. The subset is then translated to the nw representation. The nw representation is then translated to the text with a Hashtable.

If you play with the algorithm you will see that sometimes regions in the image are identified as a barcode by accident. This is a common problem with barcode detection. Being restrictive in filtering out the unwanted regions will lead to an algorithm that does not detect barcodes on low quality images. So the best solution is to add a checksum. If possible, do some additional tests like using a fixed length of the coded text.

References

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionReading Barcode from an image
ZeenY
0:25 26 Feb '08  
how to read EAN8 or EAN13 barcode from an image using c#/.net?Confused

plz help me...
GeneralReading barcode type 39
ciapal
0:52 19 Feb '08  
And what about reading barcode type 39? Have you developed the algoritm to read it too?
Thank you.
bye Big Grin
QuestionThe Speed for barcode decoder
jackjack89
0:30 17 Apr '07  
Hi,
i found that the performance of "System.Runtime.InteropServices.Marshal.ReadByte"
is show... anyone can give me a suggestion what method can replace this function so the performance can be improved?

thanks

Jack
QuestionChange BMP File Error!
zfq308
17:57 20 Nov '06  
There was happened Error when i changed another BMP File

bmp.LockBits(...) 'Error :System.ArgumentException

Benjamin Zhou
AnswerRe: Change BMP File Error!
mackenb
5:52 25 Nov '06  
Can you post the code, that causes the error?
AnswerRe: Change BMP File Error! [modified]
Robert_Zenz
5:57 23 Mar '09  
The Solution would be to use the right parameter for format.
If it has 32Bit depth, then use PixelFormat.Format32bpp*...I'm not quiet sure if this would work.

Or you convert each pic to BW, means 1 Bit Color depth.

Bobby

modified on Monday, March 23, 2009 11:04 AM

AnswerRe: Change BMP File Error!
tqhang999
7:01 8 Oct '09  
Just change the code line #238 in the gmseNWScanner.vb file to
data = bmp.LockBits(New Rectangle(0,0, bmp.Width, bmp.Height), ImageLockMode.Readonly, bmp.PixelFormat)
GeneralSome question?
Pham Tuan
22:58 21 Sep '06  
I've got some problems to solve barcode recognition.
I can't detect barcode region in a large image.
If the image is too bad i don't know how to recover it.
Please answer me

Handsome + Rich = Amorous

GeneralBarcode font Code 128
angelagke
19:31 31 Jul '06  
Can i use this read barcodes from an image application to read or scan barcode with font code 128?

Thanks Mackenb Smile

angela
GeneralRe: Barcode font Code 128
mackenb
2:07 2 Aug '06  
Code 128 is not a two width barcode. For that reason the algorithm in this article can not be used to detect Code 128.
GeneralRe: Barcode font Code 128
angelagke
6:24 2 Aug '06  
ok, i get it.
Anyway thanks a lot for your explaination Smile

angela
Questionmailto:
KatliwaMax
21:29 30 May '06  
Sniff Hi

i'm trying to send an email using vb.net/html
the problem comes when i have to use a hyperlink to send an email

on the click of the button the mail does go to the reciepient. the problem is that on that mail there is a hyperlink that the reciepient should click on and that should too send mail to certain reciepients

my code looks something like this

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Dim MailSender As New System.Web.Mail.MailMessage

With MailSender
.To = txtEmail.Text
'retrieve managers email address
.From = txtUserMail.Text
'retrieve users email address
.Subject = "Request For Rights"
.BodyFormat = MailFormat.Html
.Body = "<html><Head>Request for rights</head>

<body> " + txtFirstName.Text + " " + txtLastName.Text + " has requested for " + cblAccess.SelectedValue + " on" & _
"
Database: " + txtDB.Text + ", Projects: " + txtProject.Text + "

" & _
" Do you appove or reject the request?
If you approve click here" & _
"If you reject click here
RejectedRejected "
End With
SmtpMail.SmtpServer = "00172MSGJNB0057"
SmtpMail.Send(MailSender)

Response.Redirect("Approved.aspx")

End SubConfused

katli
Generalhelp me, please!
4aaaa
17:43 9 Mar '06  
Confused I have barcode of machine is TR550 of PROMAX proceduce and connect to computer by COM gate, but i don't know anyway to connect with computer ,please show me the way detaily, (i have vb.net for this project),if you have source code is you give me,please. thank you very much.
- My email: quoc20042002@yahoo.com

4aaaa
GeneralRe: help me, please! [modified]
Pandele Florin
2:46 31 May '06  
First of all, this is the wrong place to ask about this.
You should first contact the manufacturer of your machine(I think it is a barcode reader)and ask him about the messages your device sends on the com port and the wiring of the com port.
Secondly you could use a microsoft activex called mscomm (it has a phone as icon)to receive/send com port messages. You might also want to set up windows hyperterminal(Start/programs/accessories/communications) and use it to make tests.




Last Updated 31 Jan 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010