Scan QRcode with inverted colors using Vision API

最后都变了- 提交于 2019-12-14 03:55:30

问题


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

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

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.


回答1:


I think this is still an open issue, please see link for details. One workaround for this as stated by a developer:

Right, the barcode API generally doesn't support color-inverted codes. There's no parameter or option to control this at the moment. Though some APIs support them, I don't believe it's a common feature.

For a workaround, you could preprocess the colors in the bitmap before passing them to the barcode API (perhaps inverting colors on alternate frames).

Hope this helps.




回答2:


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

here is a link to googles example app:

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

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

I added a parameter: private boolean isInverted = false;

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


来源:https://stackoverflow.com/questions/47283709/scan-qrcode-with-inverted-colors-using-vision-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!