Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a Mathematica barcode image reader (much like TextRecognize) that allows the user to enter an image of a barcode and then read it to get an output string?

share|improve this question
1D or 2D? What symbology (i.e. standard)? – DavidC Sep 27 '13 at 1:57

Here is a bare bones, non-robust, use at your own risk, etc. code39 reader

(*get image *)
i = Binarize[Import@"", .7]

Mathematica graphics

(* Char encodings from Paul's article - See link bellow *)
c1 = IntegerDigits[#, 2, 9] &@{168,42,148,138,133,388,162,52,289,97,352,49,304,112,37,292,100,265,
c2 = Characters["$%*+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"];

(*binary code for the image, drop the white flanks at the ends*)
code = Join @@ Split[Round /@ Mean /@ Transpose@ImageData@i][[2 ;; -2]];

(*get strip widths... err lengths... whatever,dropping the start/stop marks*)
lengths = Most /@ Partition[Length /@ Split@code, 10];

(*determine what is a wide and a thin strips are*)
{max, min} = {Max@#, Min@#} &@lengths;
f = Nearest[{{max} -> 1, {min} -> 0}];

(*convert from wide/thin encoding to chars*)
StringJoin @@ (Join @@@ Map[f, lengths, {2}] /. Thread[Rule[c1, c2]])


Table and encoding shamelessly stolen from Paul Abbott's article on "The Mathematica Journal"

share|improve this answer
I can't get this to read other examples (eg here) – cormullion Sep 27 '13 at 8:31
@cormullion Yep, that image hasn't white flanks. But the code works OK if you pad it. Try with i = ImageTake[ImagePad[Import["‌​code39.gif"], {{40, 40}, {0, 0}}, White], 100] instead` – Dr. belisarius Sep 27 '13 at 11:57
@DavidG.Stork This code implements a barcode reader, not a creator as you could have found if you cared to test it. Enough. – Dr. belisarius Sep 27 '13 at 17:11
You are correct. The code you posted looked much like (http : // www.mathematica - - 2/Tricks9 - 2 _ 2. html) and the output appeared to be a crisp barcode (not a .jpg input image), so I mistakenly assumed yours was the same (creator) code. My mistake. – David G. Stork Sep 27 '13 at 17:29

Yes!... It's new in version 10. Here is the documentation page

The syntax is very simple:


It uses ZXing library (

You can alse create barcode using BarcodeImage as these examples: enter image description here enter image description here

share|improve this answer
How do you know it's using the zxing library? (I missed this in the docs and I'm curious) – Ajasja Dec 5 '13 at 12:32
Secret!.. I'm a beta tester and exchanged some mails with the developer. :) – Murta Dec 5 '13 at 13:56
Very useful for a lot of Mathematica users in the supermarket business :) – Dr. belisarius Nov 19 '14 at 23:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.