Code covered by the BSD License  

Highlights from
QR Code encode and decode

4.15385

4.2 | 14 ratings Rate this file 68 Downloads (last 30 days) File Size: 14.9 KB File ID: #29239
image thumbnail

QR Code encode and decode

by

 

Functions to encode and decode a QR bar-code in images

| Watch this File

File Information
Description

A wrapper to the zxing library (http://code.google.com/p/zxing/). This submission includes files to encode a QR code from a string message, and decode a string message from an image containing an existing QR code. With little work these functions can be expanded to search for multiple bar-codes in images, decode multiple bar-codes in a single image etc.

Acknowledgements

This file inspired Qr Code Encoder.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.11 (R2010b)
Other requirements Download and build the core and javase components of the zxing library (see description) and make sure they are in Matlab's dynamic java classpath.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
20 Jul 2014 JAKAPONG JAIBOONRUANG

Ok, it worked for me. Thank you very much.

05 Jun 2014 Nasir Ali

it gives an error on "BufferedImage"
This is error message.can you please tell me what is the solution?

??? Undefined function or method 'BufferedImageLuminanceSource' for input arguments of type
'java.awt.image.BufferedImage'.

Error in ==> decode_qr at 34
source = BufferedImageLuminanceSource(jimg);

08 May 2014 li

the great program of QR encoder,i have a quetion how to use RSENC in matlab to get error codewords with rs code mathod.i only know how to use BCHENC .hope your help ,thank you!

22 Apr 2014 Bahtosai

Hi all,
I am curently working on QR Barcode. I found the link zxing have move. Can someone share to me or guide me step by step how to encode/decode QR barcode using matlab. I just know to use Matlab, and no eperience with JAVA etc. Many thanks.

if anyone have fully matlab source code for QR barcode encode/decode please share with me. Thanks.

20 Mar 2014 dreamsyoung

Hello,have you build this qrcode file successifully?I have some error problems in this matlab file building,can you send your successful qrcode file to my email?thank you!

17 Feb 2014 haem  
03 Dec 2013 Peng Wenbin

Better to use java directly.

07 Aug 2013 Yanshuai Tu

the two jar files can be download via google search. Does anyone know how to control the Error Correction Level in generation

21 Apr 2013 Eugenijus Januskevicius

Hi Wang,

i had thee same problem with Lithuanian symbols.

Here is the patch: add

qr_hints.put(EncodeHintType.CHARACTER_SET, 'UTF-8');

just after qr_hints.put(EncodeHintType.ERROR_CORRECTION, qr_quality);
in the 'encode_qr.m'

It will probably make QR code unreadable by any other QR decoder, except ZXing's.

07 Apr 2013 wang xiaoer

I got two problems:one was that a question mark would be found in the front of the information embedded when it contained a chinese character at least;the other was that,I got nothing when it contained more than sixty-six characters including punctuations,blank spaces.Can you give me some suggestions?Thanks in advance.

31 Jul 2012 Rob

Thank you for your code.
I have the code working using zxing 2.0 with Gonzalo modifications. Well, no
error message but nothing is displayed on
my image, no QR! I get a green 32x92 square! can figure out what is wrong, can any one help please?. Thanking you in advance.

31 Jul 2012 Rob  
24 Jun 2012 ejs

Thanks to Gonzalo, i was able to get the code to work. Seems zxing made an Unexpected Update recently.
Besides, i've made it to use error correction hints

14 May 2012 Gonzalo Garateguy

Matt, I was having the same problem but I find out that the method to obtain the height and width are slightly different you have to change M_java.height for M_java.getHeight() and M_jata.width for M_java.getWidth()

04 May 2012 Adnan Jahangir

There is a problem in encoding algorithm. Due to this you cannot decode the code generated by 'encode_qr'. To solve this problem open the function file 'encode_qr.m'. At the end of the file you will find the line - 'qr = logical(qr);'. Replace this with 'qr = 1-logical(qr);' (without apostrophe). Now plot the image with 'imagesc' command and type 'colormap(gray)' in command window. Now save the image to any image file type. Now you will be able to decode it with 'decode_qr' command.

23 Apr 2012 ARIZ ZUBAIR

when i run test_qr.m following error is generated:-
Warning: Duplicate entry,C:\Users\ARIZ ZUBAIR\Desktop\qrcode\3rd_party\zxing-1.6\core\core.jar
> In javaclasspath>local_validate_dynamic_path at 247
In javaclasspath>local_javapath at 157
In javaclasspath at 102
In javaaddpath at 68
In test_qr at 6
Warning: Duplicate entry,C:\Users\ARIZ ZUBAIR\Desktop\qrcode\3rd_party\zxing-1.6\javase\javase.jar
> In javaclasspath>local_validate_dynamic_path at 247
In javaclasspath>local_javapath at 157
In javaclasspath at 102
In javaaddpath at 68
In test_qr at 7
??? Undefined function or variable 'QRCodeWriter'.

Error in ==> encode_qr at 28
qr_writer = QRCodeWriter;

Error in ==> test_qr at 10
test_encode = encode_qr('la la la', [32 32]);

please help me.

15 Feb 2012 Matt

Lior,
Thanks for doing this code. I have installed ZXing and compiled the core and javase jar files.
My problem is that the test_qr.m function is giving me an error when I try to run it. The actual error is 'No appropriate method, property, or field
height for class com.google.zxing.common.BitMatrix'.
It indicates the error is in encoder_qr.m file on line 31. When I set the debugger to stop at line 31, I saw that M_java var on line 30 was only of size 1x1.
Is this variable supposed to behave like a struct and have some field values like .height and .width?
So the source of the error was that Matlab did not recognize M_java.height on line 31.
When I type M_java in the command line it gives me a picture of the QR code printed out, thought it doesn't appear to be sized 32 by 32.
Any help would be appreciated.

I'm a TA in class where we would like to used the QR codes to give cmds to the students' projects.

Thank you, Matt

03 Feb 2012 Ahmed

i am getting this. help me out

Warning: Invalid file or directory 'C:\Users\shehzil\Desktop\Lata\zxing-1.6\core\core.jar'.
> In javaclasspath>local_validate_dynamic_path at 270
In javaclasspath>local_javapath at 184
In javaclasspath at 119
In javaaddpath at 69
In test_qr at 6
Warning: Invalid file or directory 'C:\Users\shehzil\Desktop\Lata\zxing-1.6\javase\javasc.jar'.
> In javaclasspath>local_validate_dynamic_path at 270
In javaclasspath>local_javapath at 184
In javaclasspath at 119
In javaaddpath at 69
In test_qr at 7
??? Error: File: encode_qr.m Line: 25 Column: 8
Arguments to IMPORT must either end with ".*"
or else specify a fully qualified class name: "com.google.zxing.qrcode.QRCodeReader" fails this test.

27 Nov 2011 Andreas Kraushaar

I downlowed both Zxing1.6 and 1.7 but I can't import com.google.zxing.client.j2se.BufferedImageLuminanceSource, which is needed for QR-decode.
All other resources work fine.

05 Nov 2011 Jay

Very handy! I am not familiar with Java programming, so what do I need to be able to tweak the encoding parameters such as the recommended 30% error correction level? Can I include it in my function call or I have to dive into the Java source code?

05 Nov 2011 Jay  
18 Aug 2011 Jackie

Can't decode form QR-code image(include the encode function generator image)

21 Jul 2011 Brandon

Never mind; I think I found the correct version of the Zxing.zip file.

21 Jul 2011 Brandon

where do I find Zxing.zip? Thanks!

07 Jun 2011 Michael Chan

could you update the link to download zxing? The link you provided is not longer valid. Thank you.

07 Jun 2011 mingming  
02 Apr 2011 Sven

Sorry, my bad - works perfectly, had a bad path issue.

22 Feb 2011 Tim Zaman  
10 Jan 2011 Lior Shapira

See the example in test_qr.m, you need to add the java path to the QR library:
javaaddpath('...\zxing-1.6\core\core.jar');
javaaddpath('...\zxing-1.6\javase\javase.jar');

Make sure you unzip the zxing library and build it if necessary so you have the jar's

19 Dec 2010 Mohammed Huq

how can i add the QR code class path! i do not find any of "QRreader" folder in "Zxing.zip" can you please help!!

Contact us