6

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

chrisby
  • 63
  • 1
  • 1
  • 4

3 Answers3

7

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());
}
Bartosz Firyn
  • 2,664
  • 2
  • 21
  • 18
0

You could use gstreamer in order to interact with your camera. For windows it could be gstreamer again or DirectShow. In both cases you will need to capture your data by using some special filters, in DirectShow it would be SampleGrabber. I think that gstreamer should provide some similar plugins.

AlexTheo
  • 4,004
  • 1
  • 21
  • 35
0

zxing has a port to Actionscript, which would make it usable via Flash, which can access a webcam. The port is a little old and not 100% complete, but ought to work.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • I have no experience with actionscript. How similar is to to PHP/Java? I have a very good knowledge of PHP and moderate ability in Java. – chrisby May 07 '12 at 15:01
  • It is most similar to Javascript, really. It's not really like Java, and maybe bears a little more resemblance to PHP -- but is not really like either. – Sean Owen May 07 '12 at 16:04