Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webcam - detect QR code, take snapshot and decode

I am currently trying to write a java program to utilize either a built in laptop webcam or an external USB webcam. This would hopefully be compatible with both PC and Mac.

I was wondering if anyone knew of a library that can deal with it all? I don't really want to reinvent the wheel and I wouldn't have any idea where to start in 1) detecting a webcam, 2) taking a snapshot when a QR code is detected.

I am familiar with ZXing for decoding barcode images however.

I have searched high and low, I strongly suspect the library I look for doesn't exist, however its worth an ask!

My first question on here, so I hope it is clear!

edit: alternatively, if one doesn't exist, could you point me in the right direction of how to take a snapshot from webcam when a QR code is detected? :)

Thanks

like image 782
chrisby Avatar asked May 06 '12 18:05

chrisby


People also ask

Can I read a QR code with my webcam?

You can also scan QR Codes with your desktop, laptop or tablet. Several websites allow you to scan QR Codes through your webcam or front-facing camera. Hold up the QR Code in front of your device and the associated link will appear on the screen.

Can you scan a QR code by Screenshotting it?

If the QR code you need to scan is in a website or app, take a screenshot of it to save the image to your photo library. Similarly, if someone sent you a photo of a QR code, use the Share menu to save it to your photo library.

How do I decrypt a QR code?

When you see a QR code on a Web page, just right-click it and select "Read QR code from image" from the context menu. Step 2: Right-click the QR code. Screenshot by Rob Lightner. If the code just contains a link, a new tab will open with that link.


1 Answers

This example present how to read QR code data with Webcam Capture library together with ZXing. Webcam Capture is compatible with both 32- and 64-bit Windows, Linux and Mac OX. For Linux it also supports ARM architecture.

The code is pretty simple:

Webcam webcam = Webcam.getDefault(); // non-default (e.g. USB) webcam can be used too
webcam.open();

Result result = null;
BufferedImage image = null;

if (webcam.isOpen()) {
    if ((image = webcam.getImage()) == null) {
        continue;
    }

    LuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        result = new MultiFormatReader().decode(bitmap);
    } catch (NotFoundException e) {
        // fall thru, it means there is no QR code in image
    }
}

if (result != null) {
    System.out.println("QR code data is: " + result.getText());
}
like image 50
Bartosz Firyn Avatar answered Sep 18 '22 12:09

Bartosz Firyn