Created
November 24, 2014 18:56
-
-
Save darkwave/b60a74838c6d311fc0cd to your computer and use it in GitHub Desktop.
QRCode reader using ZXing with Processing 3.0a5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
import com.google.zxing.*; | |
import java.io.ByteArrayInputStream; | |
import javax.imageio.ImageIO; | |
import com.google.zxing.common.*; | |
import com.google.zxing.client.j2se.*; | |
import java.awt.image.BufferedImage; | |
Capture cam; //Set up the camera | |
com.google.zxing.Reader reader = new com.google.zxing.MultiFormatReader(); | |
boolean globalHistogram = false; | |
void setup() { | |
cam = new Capture(this, 320, 240); | |
size(cam.width, cam.height); | |
cam.start(); | |
} | |
void draw() { | |
if (cam.available() == true) { | |
cam.read(); | |
tint(255, 255); | |
image(cam, 0, 0); | |
BufferedImage buf = (BufferedImage) cam.getNative(); | |
// Now test to see if it has a QR code embedded in it | |
LuminanceSource source = new BufferedImageLuminanceSource(buf); | |
BinaryBitmap bitmap; | |
if (globalHistogram) | |
bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); | |
else | |
bitmap = new BinaryBitmap(new HybridBinarizer(source)); | |
Result result = null; | |
try { | |
result = reader.decode(bitmap); | |
} | |
catch (Exception e) { | |
} | |
//Once we get the results, we can do some display | |
if (result != null && | |
result.getText() != null) { | |
println(result.getText()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment