【问题标题】:Scan QRcode with inverted colors using Vision API使用 Vision API 扫描反色二维码
【发布时间】:2017-11-14 10:46:35
【问题描述】:

经过几个小时让我的应用检测到这个二维码:

我意识到问题出在二维码的外观上。反转颜色后,检测工作正常。

有没有办法让 Vision API 检测到第一个二维码?我尝试启用所有符号系统,但它不起作用。我想这是可能的,因为应用程序QR Code Reader 检测到了它。

【问题讨论】:

  • 澄清一下,我尝试用蓝色扫描第二个二维码,效果也很好,没有特别需要黑色二维码。

标签: android google-play-services qr-code vision


【解决方案1】:

我改进了谷歌的示例应用“条形码阅读器”,以检测倒色条形码和常规条形码。

这里是谷歌示例应用的链接:

https://github.com/googlesamples/android-vision/tree/master/visionSamples/barcode-reader

我通过编辑“CameraSource”类来做到这一点, 包:"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();
            }
        }

【讨论】:

    【解决方案2】:

    我认为这仍然是一个悬而未决的问题,请参阅link 了解详细信息。开发人员所述的一种解决方法:

    是的,条形码 API 通常不支持颜色反转代码。目前没有参数或选项来控制它。虽然有些 API 支持它们,但我不认为这是一个通用功能。

    作为一种解决方法,您可以在将位图中的颜色传递给条形码 API 之前对其进行预处理(可能在交替帧上反转颜色)。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多