ministero-salute / it-dgc-verificaC19-android

VerificaC19 is the official Italian customization of the EU Digital COVID Certificate Verifier App for the Android Operating System
https://www.dgc.gov.it
Apache License 2.0
101 stars 54 forks source link

QR code reading not reliable #73

Closed enricomiletto closed 3 years ago

enricomiletto commented 3 years ago

Describe the bug

When compared with the Swiss or the Dutch DCG verifier apps, VerificaC19 is error-prone and very slow in reading the QR codes when in nonoptimal circumstances.

When the QR code in frame is slightly rotated or not perfectly centred the app can take many seconds or even totally fail to read the QR code at all. And even when it does manage to read the QR code it often (in about 1 in 5 cases from my experience) fails to read it correctly and shows the "Certificazione non valida" message.

This is a problem because in some situations (for example at the entrance of big events) it can be difficult and time consuming to frame the code correctly or retry scanning the QR code after it was wrongfully read as invalid.

Expected behaviour

The QR code gets read and verified in 1 sec. or less and independently of how the QR code is rotated, just like it happens with Verifier apps of other countries.

Steps to reproduce the issue

  1. Tap on "Avvia Scansione"
  2. Frame the QR at an inclination above 30°
  3. The App will not manage to read the QR code at all or read it incorrectly with a relatively high probability

Technical details

enricomiletto commented 3 years ago

https://user-images.githubusercontent.com/80707578/127001276-34082264-af0a-41ab-a27c-1fcf9ea05643.mp4

This video shows pretty nicely what I'm talking about

Signoo commented 3 years ago

Seems like they're using different libraries for QR detection. Italian version; Dutch version;

Doesn't look like zxing has other options to make it faster.

enricomiletto commented 3 years ago

Hey @Signoo, I see.

The swiss version seems to be using zxing too, but it doesn't have problems handling rotated qr codes.

So maybe they found a way to solve this problem while still using zxing.

Signoo commented 3 years ago

@enricomiletto just looked a bit more into the code: The italian version uses a wrapper built around zxing: zxing-android-embedded which doesn't seem to be customizable. The swiss version uses zxing directly, it parses each camera frame, generates a PlanarYUVLuminanceSource which is then used by HybridBinarizer to generate the bitmap. Guess that's why the detection is faster.

It should be possible to implement the same in the italian version.

enricomiletto commented 3 years ago

I just discovered that the app also reads other types of barcodes. If one scans the barcode on a book, for example, the app will read it and then of course show the "Certificazione non valida" message. This is because standard ZXing can read 17 different types of 1D and 2D barcodes.

This explains why the app often fails to read correctly real DCC QR codes; it's not that the app reads the QR code wrong (which is something very very unlikely to happen because of the error correction in QR codes) but it "finds" a pattern inside the QR code matrix which corresponds to some other barcode standard, and this of course leads to invalid data.

This is exactly the same behaviour that the Barcode Scanner app (based on ZXing) has as you can see from the screenshot below

WhatsApp Image 2021-07-29 at 16 32 26

To solve this issue, the app should exclusively look for QR codes (just like the Swiss version which also uses ZXing does) and this will solve the issue of real DCC QR codes leading to the "Certificazione non valida" message.

enricomiletto commented 3 years ago

The cool/fun side effect of the fact that the app reads a variety of different barcode types is that you can convert a DCC into another barcode standard and still validate it, for example a Data Matrix (which is also supported by ZXing). :-P

https://user-images.githubusercontent.com/80707578/127520234-f00aa662-00b8-406b-ad56-7074cacdf88a.mp4

astagi commented 3 years ago

@Signoo @enricomiletto thanks for reporting this issue and for videos. We're working to improve scanning experience (especially on removing scanning errors), some updates on this will come in the next version!

enricomiletto commented 3 years ago

@astagi I tried the new update today, and the scanning definetly works much much better now. The app now reads QR-codes that are rotated more reliably and quicker (YAY! 👏)

That said:

Nonetheless, the last update was really a big improvement!

enricomiletto commented 3 years ago

The latest update of the app (1.0.3) has fixxed all the major issues mentioned in this GitHub issue.

The only (minor) "problem" remaining is that the app only reads the QR code when it's fully inside of the inner/not greyed out square; just a small portion of the QR code that's outside the square suffices for the app not to read it Other apps (i've tested personally the swiss and the dutch one), while they still have a similar "square" to help the user better frame the code, still read codes if they're not inside of that square.

astagi commented 3 years ago

@enricomiletto thank you for this update and sorry for my late response, I'm currently on vacation! I'm very happy to hear this, I think we can close this issue and open an "enhancement" to improve QR code reading process, WDYT?

enricomiletto commented 3 years ago

@astagi Yes I totally agree.