java 网络摄像头 - 检测二维码,拍摄快照并解码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10473277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:12:32  来源:igfitidea点击:

Webcam - detect QR code, take snapshot and decode

javawebcamqr-codesnapshot

提问by chrisby

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.

我目前正在尝试编写一个 java 程序来利用内置的笔记本电脑网络摄像头或外部 USB 网络摄像头。这有望与 PC 和 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.

我想知道是否有人知道可以处理这一切的图书馆?我真的不想重新发明轮子,我不知道从哪里开始 1) 检测网络摄像头,2) 在检测到 QR 码时拍摄快照。

I am familiar with ZXing for decoding barcode images however.

但是,我熟悉用于解码条形码图像的 ZXing。

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

谢谢

采纳答案by Sean Owen

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.

zxing 有一个到 Actionscript 的端口,这将使它可以通过 Flash 使用,它可以访问网络摄像头。端口有点旧,不是 100% 完成,但应该可以工作。

回答by Bartosz Firyn

This examplepresent how to read QR code data with Webcam Capturelibrary 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.

本示例展示了如何使用Webcam Capture库和 ZXing读取二维码数据。Webcam Capture 与 32 位和 64 位 Windows、Linux 和 Mac OX 兼容。对于 Linux,它还支持 ARM 架构。

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

回答by AlexTheo

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.

您可以使用 gstreamer 与您的相机进行交互。对于 Windows,它可能再次是 gstreamer 或 DirectShow。在这两种情况下,您都需要使用一些特殊的过滤器来捕获数据,在 DirectShow 中它将是 SampleGrabber。我认为 gstreamer 应该提供一些类似的插件。