File Exchange

image thumbnail

QR Code encode and decode

version 1.0 (14.9 KB) by

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

4.44444
20 Ratings

56 Downloads

Updated

View License

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.

Comments and Ratings (45)

Thanks to Andres Puerto, this perfectly works for me using MATLAB Version 8.4.0.150421 (R2014b) to get the functions running without errors or warnings.

Hi , downloaded 3.3 jars from (https://repo1.maven.org/maven2/com/google/zxing/javase/3.3.0/ and https://repo1.maven.org/maven2/com/google/zxing/core/3.3.0/), and functions are inside differente folders for this matlab code, so you have to change the imports in this way:

for encode function :

import com.google.zxing.qrcode.*;
import com.google.zxing.*;

for decode function:

import com.google.zxing.qrcode.*;
import com.google.zxing.client.j2se.*;
import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.Result.*;

there are another changes to do:
in function encode M_java.height and M_java.width are invalid, instead use M_java.getHeight(), M_java.getWidth()

Special thanks for Ari Bejarano the Java's Master

I can run test_qr.jpg only but other images containing QR code can not be decode with this test_qr.m file...can anyone tell me the solution as i am getting empty string after running any other QR code other than test_qr.jpg.

megh shah

hii
i cannot find zxing file in this site ,would you suggest me another site to download zxing and also please tell me where to install this file. and please tell me procedure for installing zxing.
Email: meghshah1758@gmail.com

Ibraheem

Argo Argo

s_il

s_il (view profile)

Hello. I cannot run this code. When i run encode_qr.m, I get an 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.QRCodeWriter" fails this test.' When I run test_qr.m I get this error and also 'Error in test_qr (line 10)
test_encode = encode_qr('la la la', [32 32]);'
Could you help me please?
Email: sofia.iliopoulou.28@gmail.com

Yudha Viki

I cnnot run this code, when I run the decode_qr.m, im getting an Error "Error: File: decode_qr.m Line: 26 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." and when i run test_qr.m im also getting an error "Warning: Invalid file or directory 'D:\TELKOM UNIVERSITY\IF\FINAL WORK PLANING\PROJECT\QR CODE
DECODER\DECODE_MATLAB\3rd_party\zxing-1.6\core\core.jar'.
> In javaclasspath>local_validate_dynamic_path (line 266)
In javaclasspath>local_javapath (line 182)
In javaclasspath (line 119)
In javaaddpath (line 71)
In test_qr (line 6)
Warning: Invalid file or directory 'D:\TELKOM UNIVERSITY\IF\FINAL WORK PLANING\PROJECT\QR CODE
DECODER\DECODE_MATLAB\3rd_party\zxing-1.6\javase\javase.jar'.
> In javaclasspath>local_validate_dynamic_path (line 266)
In javaclasspath>local_javapath (line 182)
In javaclasspath (line 119)
In javaaddpath (line 71)
In test_qr (line 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.QRCodeWriter" fails this test.

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

please help me....

Thank.

E-Mail : yudhaviki@gmail.com

GP

GP (view profile)

Mina Fouad

VIBHATH V B

I cannot run this code. I am looking for decoding an image containing qr code. How to do that?
When I run the decode-qr code, I am getting an error "Error using im2java2d Expected input number 1, Image, to be one of these types:uint8, uint16, double, logical".

E-mail:vibhathvb@gmail.com

hello,when i am running the file test_qr, qr code is being generated and then i save the image at desktop location,But when i use another file named "decode_qr" to decode the same saved image, which was generated by test_qr, it displays an error titled "no qr code found." this decode_qr.m file is working for other downloaded qr codes. kindly help me out.

I have Two questions related to QR Code
1. what the maximum size of data that can be embedded inside a QR Code
2. whether 7% of error is acceptable to decode 100 data

paria

paria (view profile)

Hey, when I want use the decode file, it shows error like:
Error in decode_qr (line 34)
source = BufferedImageLuminanceSource(jimg);
would you please help me how to solve it?

kailash singh

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

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);

li

li (view profile)

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!

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.

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!

haem

haem (view profile)

Peng Wenbin

Better to use java directly.

Yanshuai Tu

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

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.

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.

Rob

Rob (view profile)

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.

Rob

Rob (view profile)

ejs

ejs (view profile)

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

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()

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.

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.

Matt

Matt (view profile)

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

Ahmed

Ahmed (view profile)

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.

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.

Jay

Jay (view profile)

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?

Jay

Jay (view profile)

Jackie

Jackie (view profile)

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

Brandon

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

Brandon

where do I find Zxing.zip? Thanks!

Michael Chan

Michael Chan (view profile)

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

mingming

Sven

Sven (view profile)

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

Tim Zaman

Lior Shapira

Lior Shapira (view profile)

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

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!!

MATLAB Release
MATLAB 7.11 (R2010b)
Acknowledgements

Inspired: QR Code encoder

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video