ftylitak / qzxing

Qt/QML wrapper library for the ZXing library. 1D/2D barcode image processing library
Apache License 2.0
613 stars 336 forks source link

Unable to detect QR codes via QZXingFilter on SailfishOS #200

Closed patrickjane closed 2 years ago

patrickjane commented 3 years ago

Hello,

I am running SailfishOS 4.1.0.24 (QT 5.2) on a Sony XPeria 10 ii, and I want to read QR codes from within my app. I have included the full project in my project, and I have enabled several switches:

MyApp.pro
QT += multimedia

QZXing.pri
CONFIG += enable_decoder_qr_code qzxing_multimedia qzxing_qml

Currently I am trying the QZXingFilter like so:

int main(int argc, char *argv[])
{
   QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
   QScopedPointer<QQuickView> view(SailfishApp::createView());

   QZXing::registerQMLTypes();

   view->setSource(SailfishApp::pathTo(QString("qml/harbour-myapp.qml")));
   view->show();

   return app->exec();
}
   Rectangle {
      width: 400
      height: 400
      x: 30; y: 90

      Camera {
         id: camera

         focus {
            focusMode: Camera.FocusContinuous
            focusPointMode: Camera.FocusPointCenter
         }
      }

      VideoOutput {
         id: videoOutput
         source: camera
         filters: [ videoFilter ]
         autoOrientation: false
      }
   }

   QZXingFilter {
      id: videoFilter

      decoder {
         imageSourceFilter: QZXing.SourceFilter_ImageNormal
         enabledDecoders: QZXing.DecoderFormat_QR_CODE
         tryHarder: true
         tryHarderType: QZXing.TryHarderBehaviour_Rotate | QZXing.TryHarderBehaviour_ThoroughScanning

         onTagFound: {
            console.log("Tag found:", tag);
         }
      }
   }

Since I had issues with no code beeing detected (onTagFound never emitted, and decodingFinished signaling failure) I have commented in the debug messages in QZXing::decodeImage(). This gives me the following output:

[D] QZXing::decodeImage:448 - Iterations:  1 , sourceFilter:  2
[D] QZXing::decodeImage:467 - Decoding phase 1: started
[D] QZXing::decodeImage:473 - Decoding phase 1: failed:  No code detected
[D] QZXing::decodeImage:478 - Decoding phase 2, thorought scan: starting
[D] QZXing::decodeImage:491 - Decoding phase 2, thorought scan: failed:  No code detected
[D] QZXing::decodeImage:498 - Decoding phase 2, rotate: starting
[D] QZXing::decodeImage:511 - Decoding phase 2, rotate: failed:  No code detected
[D] QZXing::decodeImage:519 - Decoding failed:  "This luminance source does not support rotation."
[D] QZXing::decodeImage:563 - End decoding 3
[D] QZXing::decodeImage:448 - Iterations:  1 , sourceFilter:  2
[D] QZXing::decodeImage:467 - Decoding phase 1: started
[D] QZXing::decodeImage:473 - Decoding phase 1: failed:  No code detected
[D] QZXing::decodeImage:478 - Decoding phase 2, thorought scan: starting
[D] QZXing::decodeImage:491 - Decoding phase 2, thorought scan: failed:  No code detected
[D] QZXing::decodeImage:498 - Decoding phase 2, rotate: starting
[D] QZXing::decodeImage:511 - Decoding phase 2, rotate: failed:  No code detected
[D] QZXing::decodeImage:519 - Decoding failed:  "This luminance source does not support rotation."
[D] QZXing::decodeImage:563 - End decoding 3

So now I don't know what to do in order to make it scan the code. For testing, I am using one of those codes.

Could anyone help me out figuring out whats wrong here?

ftylitak commented 3 years ago

Hello @patrickjane

most likely it has something to do with the image encoding not being 100% supported by QZXing.

I have a Jolla C with Sailfish 4 so I will give it a try :) (minor note, the Qt version is 5.12 not 5.2 correct ?)

patrickjane commented 3 years ago

It should be 5.2 (https://sailfishos.org/wiki/Qt).

BTW: I am pretty sure there should be other apps for SailfishOS which are using ZXing/QZXing successfully, so I guess I am making some mistakes on the way.

ftylitak commented 3 years ago

Indeed you are correct, it seems that 5.2 is the correct.

Regarding your issue, till I find a proper way of integrating the solution, here is what you can do as a workaround. In file QZXingFilter at the following files: https://github.com/ftylitak/qzxing/blob/9973b3dd786298c6389476058639a25020e5507b/src/QZXingFilter.cpp#L183-L187

comment out all lines except line 184:

//#if defined(Q_OS_IOS) || defined (Q_OS_MAC)
        uchar* pixel = pixelInit + (y - 1) * captureRect.targetWidth;
//#else
//        uchar* pixel = pixelInit + (captureRect.targetHeight - y) * captureRect.targetWidth;
//#endif

Could you give it a try and send me your feedback if it works for you?

patrickjane commented 3 years ago

I have changed it, and I can confirm everything gets detected now. Thanks for the support!

patrickjane commented 2 years ago

I might add that, in order to include this project into a SFOS project, I had to add more adjustments, otherwise the install targets would be messed up and I would no longer be able to produce RPMs.

See the patch here https://github.com/patrickjane/harbour-scooter/blob/main/qzxing_sfos_fix.patch