Click here to Skip to main content
13,867,035 members
Click here to Skip to main content
Add your own
alternative version


143 bookmarked
Posted 24 Mar 2004
Licenced CPOL

Reading Barcodes from an Image

, 24 Mar 2004
Rate this:
Please Sign up or sign in to vote.
An example of how to process an image for barcode strings


I recently ran across Neil Van Eps series of articles on how to draw barcodes and found myself wondering how easy it would be to process an image to read barcodes. Attached is a demo project that shows one method for reading Code39.


I've been a Basic programmer since age 8 (love those GOTO's... Icky!), a VB4->VB6 programmer for ages (OK... Only since college), and a VB.NET programmer since it was released, but exclusively .NET for only about a year. Basically (sorry for the pun), I've been able to get by with very little knowledge of C or C++. I recently needed to do some image processing so I checked out The Code Project and found a series of articles titled Image Processing for Dummies with C# and GDI+ by Christian Graus. YES! I had finally found what I was looking for, an example on image processing. I started to translate the C# code to VB.NET (usually this is an easy task) and found it nearly impossible... Needless to say, I am now a C# developer as well. :)

Using the code

Although there are at least ten ways (that I can think of) to skin a cat, I selected a method for processing the image that was relatively simple just to prove the concept. First, I create an average of the pixels (histogram) down the image:

for(int y=0;y<bmp.Height;++y)
 for(int x=0; x < bmp.Width; ++x )
// Add up all the pixel values vertically (average the R,G,B channels)
  vertSum[x] += ((p[0] + (p+1)[0] + (p+2)[0])/3);

 p += nOffset;
Next run through the resulting array to find the narrow and wide bars:
for(int i = 0; i < vertHist.histogram.Length; ++i)
Finally, lookup the narrow/wide bar pattern to match it to a character:
dataString += parsePattern(new string(pattern));


The method I used to get the bar pattern isn't what I would call robust. I'd eventually like to figure out a better method for finding the barcode patterns (in any orientation) in addition to adding support for the various barcode types.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Benjamin Liedblad
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionPDF document Pin
Member 1139256621-Jan-15 11:41
memberMember 1139256621-Jan-15 11:41 
Bugerror in reading barcode Pin
san.1234531-Aug-12 3:14
membersan.1234531-Aug-12 3:14 
QuestionBarcodeImaging DLL Pin
Akshay 00719-Mar-12 1:34
groupAkshay 00719-Mar-12 1:34 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 20:37
professionalManoj Kumar Choubey26-Feb-12 20:37 
GeneralHelp me for Barcode 39 Extension Pin
naorem24-Jan-10 20:47
membernaorem24-Jan-10 20:47 
GeneralDone with Locate & Rotate Barcode [modified] Pin
techexpertgroup19-May-08 10:48
membertechexpertgroup19-May-08 10:48 
GeneralRe: Done with Locate & Rotate Barcode Pin
Berend Engelbrecht2-Oct-09 6:27
memberBerend Engelbrecht2-Oct-09 6:27 
QuestionBarcode 128 Pin
Ira8429-Nov-07 23:31
memberIra8429-Nov-07 23:31 
Generalhistogram Pin
samis20008-Sep-06 0:45
membersamis20008-Sep-06 0:45 
GeneralSuggestion If I may.. Pin
Pandele Florin5-Sep-06 4:38
memberPandele Florin5-Sep-06 4:38 
GeneralRe: Suggestion If I may.. Pin
Berend Engelbrecht3-Oct-09 4:10
memberBerend Engelbrecht3-Oct-09 4:10 
Generalbarcode v2 Pin
waelahmed9-Aug-06 5:29
memberwaelahmed9-Aug-06 5:29 
QuestionPossible bug? Pin
xWayne25-May-05 13:05
memberxWayne25-May-05 13:05 
AnswerRe: Possible bug? Pin
xWayne25-May-05 13:07
memberxWayne25-May-05 13:07 
GeneralRe: Possible bug? Pin
Benjamin Liedblad27-May-05 8:38
memberBenjamin Liedblad27-May-05 8:38 
GeneralRe: Possible bug? Pin
xWayne27-May-05 9:35
memberxWayne27-May-05 9:35 
GeneralRe: Possible bug? Pin
Reelix18-Nov-08 20:18
memberReelix18-Nov-08 20:18 
GeneralRe: Possible bug? [modified: new CodeProject version published] Pin
Berend Engelbrecht2-Oct-09 8:35
memberBerend Engelbrecht2-Oct-09 8:35 
GeneralRe: Possible bug? Pin
Reelix4-Oct-09 21:33
memberReelix4-Oct-09 21:33 
GeneralInteresting Pin
Joel Holdsworth25-Mar-04 7:25
memberJoel Holdsworth25-Mar-04 7:25 
Generalvision algorithms Pin
Member 1324872631-Mar-04 3:35
memberMember 1324872631-Mar-04 3:35 
GeneralRe: Interesting Pin
gpj geoff31-Mar-04 18:07
membergpj geoff31-Mar-04 18:07 
GeneralRe: Interesting Pin
Lucian_RT20-Jun-05 9:36
memberLucian_RT20-Jun-05 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 25 Mar 2004
Article Copyright 2004 by Benjamin Liedblad
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid