3

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

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

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.

Louis
  • 1,913
  • 2
  • 28
  • 41
  • Just to clarify, I tried to scan the second QR code with the blue color and it works perfectly as well, there is no special need for a black QRCode. – Louis Nov 16 '17 at 14:47

2 Answers2

4

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();
            }
        }
Hadas
  • 906
  • 12
  • 22
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.

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91