本文介绍了使用Vision API扫描颜色反转的QRcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过数小时的努力使我的应用检测到此QRCode:

After struggling a few hours on making my app detect this QRCode:

我意识到问题出在QRCode外观上.反转颜色后,检测效果良好..

I realized that the problem was the in the QRCode appearance. After inverting the colors, the detection was working perfectly..

有没有一种方法可以使Vision API检测到第一个QRCode?我尝试启用所有符号系统,但是没有用.我猜可能是因为应用程序 QR Code阅读器检测到它.

Is there a way to make Vision API detect the first QRCode? I tried to enable all symbologies but it did not work. I guess it is possible because the app QR Code Reader detects it.

推荐答案

我改进了googles示例应用程序条形码阅读器",以检测彩色倒置条形码和常规条形码.

I improved googles example app "barcode-reader" to detect both inverted colored barcodes and regular ones.

这是指向Google示例应用的链接:

here is a link to googles example app:

https://github.com/googlesamples/android -vision/tree/master/visionSamples/条形码阅读器

我是通过编辑"CameraSource"类来做到这一点的,包:"com.google.android.gms.samples.vision.barcodereader.ui.camera".

I did so by editing "CameraSource" class,package: "com.google.android.gms.samples.vision.barcodereader.ui.camera".

我添加了一个参数:private boolean isInverted = false;

和更改的功能void setNextFrame(byte[] data, Camera camera):

void setNextFrame(byte[] data, Camera camera) {
            synchronized (mLock) {
                if (mPendingFrameData != null) {
                    camera.addCallbackBuffer(mPendingFrameData.array());
                    mPendingFrameData = null;
                }

                if (!mBytesToByteBuffer.containsKey(data)) {
                    Log.d(TAG,
                            "Skipping frame.  Could not find ByteBuffer associated with the image " +
                                    "data from the camera.");
                    return;
                }

                mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis;
                mPendingFrameId++;
                if (!isInverted){
                    for (int y = 0; y < data.length; y++) {
                        data[y] = (byte) ~data[y];
                    }
                    isInverted = true;
                } else {
                    isInverted = false;
                }
                mPendingFrameData = mBytesToByteBuffer.get(data);

                // Notify the processor thread if it is waiting on the next frame (see below).
                mLock.notifyAll();
            }
        }

这篇关于使用Vision API扫描颜色反转的QRcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:36