Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qr code reader #1185

Merged
merged 13 commits into from
Mar 1, 2021
Merged

Qr code reader #1185

merged 13 commits into from
Mar 1, 2021

Conversation

sklencar
Copy link
Contributor

@sklencar sklencar commented Feb 12, 2021

QR code reader implementation using ZXing library.

  • Supported multiple platforms
    • full support for Android and iOS,
    • supported also MacOS desktop build, but seems to have bug that it is capturing invalid image for ZXing library,
    • WIN build not supported;
  • available for TextEdit widget if an attribute's name contains qrcode case insensitive. Note that name is taken from field.name or overwriten by field.alias if exists.
  • added invalid data changed notification
  • basic style with simple header and camera overlay

Related manual-test: lutraconsulting/input-manual-tests#28
closes #408

Known issues

  • camera issues
    • blank page when camera is being loaded (affects some devices)
    • QImage qt_imageFromVideoFrame(const QVideoFrame &) : unsupported pixel format Format_ABGR32 while converting videoOutput to QImage (seems to be Android only).
    • sometimes not QR decoder not responses well
RPReplay_Final1613558974.MP4

@sklencar sklencar changed the title WIP: Qr code reader Qr code reader Feb 17, 2021
Copy link
Collaborator

@tomasMizera tomasMizera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good job!

I did not go through the whole code yet, though what I have seen so far looks great. I tested it on Android and it works well. I could not get Linux build running but I guess we will be able to sort it out.

Some notes:

  • Permission for camera on Android is now again requested at startup (this was changed in Camera permission crash #1081). I think what we want is to opt it when needed - when user clicks on take a photo or now qr code icon. It is possible that it comes from ZXing library, but the problem is that it will be forbidden in upcoming version of Android to immediately ask for permissions without any information.
  • If permission is not granted and user opens QR code scanner, it says something like "Camera service is not operating?" which is not true, user only did not provide permission.
  • Maybe icon for QR Code can be smaller?
  • When user scans invalid (not convertible) value for field, maybe we could display some more user friendly message, now:

.github/workflows/android.yml Show resolved Hide resolved
@sklencar
Copy link
Contributor Author

All remarks from notes should be resolved. However I kept the QR code icon unchanged. I would suggest to revise all icons in quick widgets to use its size variable or derive size from a ratio of rowHeight.

Copy link
Collaborator

@tomasMizera tomasMizera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a phone discussion, please add some more comment to have an idea how this is working. It is working very nice on Android! Thanks for resolving the permission problems, it is now working as expected.

app/android.pri Show resolved Hide resolved
@@ -474,6 +497,10 @@ Item {
return form.loadWidgetFn(widget.toLowerCase())
else return ''
}

Component.onCompleted: {
supportDataImport = importDataHandler.supportImportData(Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supportImportData function is not defined in default importDataHandler in qgsquickfeatureform

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I can't see how this one was resolved

Comment on lines 500 to 502

Component.onCompleted: {
supportDataImport = importDataHandler.supportImportData(Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the need for this function to be called there, however, it is not very common that library would ask for change. I guess it should be the other way around - Input letting qgsquick know we want to supportDataImport.

I know it is hard to get the Name variable but I think this is too tightly coupled.
I was thinking you could instead of invoking this method when component completes, invoke it by setting the object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is simplified to use the function from handler directly to assign supportDataImport attribute. Added also default function to default handler definition.

app/qml/FeaturePanel.qml Outdated Show resolved Hide resolved
@tomasMizera
Copy link
Collaborator

Also regarding the manual test, I vote to add it here lutraconsulting/input-manual-tests#5 rather than creating new test case. Thanks!

@sklencar
Copy link
Contributor Author

Remarks resolved + manual test relocated.

I have checked the issue with scanning the same code for multiple fields. The issue seems to be rather linked with the library (or, of course, something else). This use case is possible, but the scanner acts like it has problem to scan it sometimes. Usually when I was moving camera a bit and wait longer time, it eventually scan the code. This could be possibly improved to add some flags to the DecodeHints in decoder (e.g Binarizer which I keep as default since I was having some issues with reading barcodes when i set it to Binarizer::FixedThreshold). In any case, this is something that has to be investigated further.

Copy link
Collaborator

@tomasMizera tomasMizera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for resolving the notes, however, I unresolved one, I could not find how it was resolved (the one with Component.onCompleted)

Other than that there are some notes about memory. After clearing these I am ok to merge so passing to you @wonder-sk 🟢

app/codefilter.h Show resolved Hide resolved
@@ -474,6 +497,10 @@ Item {
return form.loadWidgetFn(widget.toLowerCase())
else return ''
}

Component.onCompleted: {
supportDataImport = importDataHandler.supportImportData(Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I can't see how this one was resolved

app/codefilter.cpp Outdated Show resolved Hide resolved
app/codefilter.cpp Show resolved Hide resolved

QVideoFilterRunnable *CodeFilter::createFilterRunnable()
{
return new QRRunnable( this );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably save this address to a new attribute and free it in CodeFilter's destructor or somehow destroy QRRunnable instance when this (CodeFilter) is deleted

Copy link
Contributor Author

@sklencar sklencar Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From documentation, it seems that destructions is handled. Also added docs to the function.
However, I am easy to change it if needed.
http://doc.qt.io/qt-5/qabstractvideofilter.html#createFilterRunnable

app/codefilter.cpp Outdated Show resolved Hide resolved
app/codefilter.h Outdated Show resolved Hide resolved
app/qml/CodeReader.qml Outdated Show resolved Hide resolved
@sklencar sklencar requested a review from wonder-sk March 1, 2021 12:42
@wonder-sk wonder-sk merged commit 3ae5476 into master Mar 1, 2021
@PeterPetrik PeterPetrik deleted the qr_code branch April 15, 2021 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to use camera as QR code scanner instead of taking photos
4 participants