qzxing icon indicating copy to clipboard operation
qzxing copied to clipboard

Unable to detect QR codes via QZXingFilter on Ubuntu Touch

Open patrickjane opened this issue 3 years ago • 2 comments

Hi,

I am currently porting my (now working) SFOS app to Ubuntu Touch, and thus I also had to include qzxing in my project. I did it via cmake, like so:

set(QZXING_MULTIMEDIA "true")
set(QZXING_USE_QML "true")

add_subdirectory(submodules/qzxing/src)

add_definitions(-DQZXING_QML)                    // for the main project to register meta types
include_directories(submodules/qzxing/src)       // for the main project to register meta types

target_link_libraries(${PROJECT_NAME} [.....] qzxing)

In QML I'm doing this:

{
[...]
   Camera {
      id: camera
      focus {
         focusMode: Camera.FocusContinuous
         focusPointMode: Camera.FocusPointCenter
      }
   }

   Rectangle {
      width: parent.width * 0.8
      height: parent.width * 0.8
      anchors.horizontalCenter: parent.horizontalCenter
      anchors.verticalCenter: parent.verticalCenter
      color: "transparent"

      VideoOutput {
         id: videoOutput
         anchors.fill: parent
         source: camera
         filters: [ videoFilter ]
         autoOrientation: true
      }
   }

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

         onTagFound: {
            if (popped)
               return;

            popped = true
            pageStack.pop()
            handleScannedCode(tag)
         }
      }
   }
[...]
}

However detecting QR codes does not work. Instead I get the logs flooded with the following, as soon as the camera is activated (no matter where it is pointed to):

QZXingFilterRunnable: Buffer is empty
virtual uchar* AalGLTextureBuffer::map(QAbstractVideoBuffer::MapMode, int*, int*)
QVideoFrame::unmap() was called more times then QVideoFrame::map()
QZXingFilterRunnable: Buffer is empty
virtual uchar* AalGLTextureBuffer::map(QAbstractVideoBuffer::MapMode, int*, int*)
QVideoFrame::unmap() was called more times then QVideoFrame::map()
QZXingFilterRunnable: Buffer is empty
virtual uchar* AalGLTextureBuffer::map(QAbstractVideoBuffer::MapMode, int*, int*)
QVideoFrame::unmap() was called more times then QVideoFrame::map()
QZXingFilterRunnable: Buffer is empty
virtual uchar* AalGLTextureBuffer::map(QAbstractVideoBuffer::MapMode, int*, int*)
QVideoFrame::unmap() was called more times then QVideoFrame::map()

How can I make this work? QT version should be 5.12.

patrickjane avatar Jul 17 '21 18:07 patrickjane

Hello @patrickjane

I have just merged #201 so i would suggest you pull the latest code and also add the following definitions to your cmake:

set(QZXING_USE_DECODER_QR_CODE "true")

Moreover, seeing the message QZXingFilterRunnable: Buffer is empty i understant that the video filter is not receiving valid video frames. Could it be that you need to request a permission for the camera in Ubuntu Touch?

ftylitak avatar Aug 01 '21 12:08 ftylitak

@ftylitak I have analyzed the issue further, see here and here.

However I am unable to get it to work with my limited OpenGL/video/image processing experience. The solution mentioned by dobey works, instead of using a video filter, it is possible to work with snapshot timers and manual image recognition (as done here).

I don't think its a camera permission issue.

patrickjane avatar Aug 02 '21 06:08 patrickjane

I decided to continue working on this issue on the middleware-side of Ubuntu Touch, @patrickjane was correct in the assumption that GL needed to be used. The current state is here: https://gitlab.com/ubports/development/core/qtubuntu-camera/-/commit/4a551326f56e0b0d3debd3a1fe73d9c703dde42d

Now, I verified the image being mapped correctly by modifying QZXing to write a QImage right after memcpy'ing the contents into its own frame.

The remaining problem is the following output, with one application at least:

qml: This luminance source does not support rotation.
virtual uchar* AalGLTextureBuffer::map(QAbstractVideoBuffer::MapMode, int*, int*)
virtual void AalGLTextureBuffer::unmap()
Decoding phase 1: started
Decoding phase 1: failed: No code detected
Decoding phase 2, thorought scan: failed
Decoding phase 2, rotate: failed
Decoding failed:  "This luminance source does not support rotation."

I made the app in question use QZXing 3.3, so I wonder what might be missing here.

fredldotme avatar Aug 16 '22 23:08 fredldotme

Thanks to a community member I was pointed in the right direction, the same change as required by SailfishOS was needed.

Pull request available here: https://github.com/ftylitak/qzxing/pull/221 @ftylitak please consider taking a look at this

fredldotme avatar Aug 17 '22 05:08 fredldotme

#221 has been merged. In case anything else comes up, feel free to open a new issue.

ftylitak avatar Aug 22 '22 06:08 ftylitak