Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QML Camera does not work on android!
QtWS25 Last Chance

QML Camera does not work on android!

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 680 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MesrineM Offline
    MesrineM Offline
    Mesrine
    wrote on last edited by
    #1

    Hello everyone,

    I am testing a qr decoder using android
    the custom qml type-file is

    import QtQuick 2.0
    import QtMultimedia
    import QtQrDec
    import MyDesigns
    
    Item
    {
        id:root
        signal gotdata(string data);
        function stop() {
            timer.stop();
            camera.stop();
            startcamera.visible=true;
        }
    
        VideoOutput {
            id: videoOutput
            anchors.fill: root
        }
        MediaDevices {
            id: devices
        }
        Camera {
            id: camera
            active: false
            cameraDevice: devices.defaultVideoInput
            onErrorOccurred: (error,errorString)=> {
                                 console.log( devices.videoInputs);
                                 console.log(errorString)
                                 console.log(error)
                             }
    
        }
        Connections {
            target: QRImageDecoder
            function onText_changed(boo) {
                root.gotdata(QRImageDecoder.text)
            }
        }
        Connections {
            target: QRImageDecoder
            function onPermissionRequested(boo) {
                if(boo)
                {
                    console.log( devices.videoInputs);
                    console.log(camera.cameraFormat)
    
                    devices.videoInputs.forEach((Cdev)
                                                => {
                                                    if(Cdev.position===Cdev.BackFace)
                                                    {
                                                        camera.cameraDevice=Cdev;
                                                    }
                                                });
    
    
                    camera.start();
                    timer.start();
                    startcamera.visible=false;
                }
            }
        }
    
        CaptureSession {
            id: capturesession
            camera: camera
            videoOutput: videoOutput
            imageCapture: ImageCapture {
                id: imageCapture
                onErrorOccurred:(requestId, error, message)=> {
                                    console.log("capture error:",message)
    
                }
    
                onImageCaptured: {
                    console.log("onImageCaptured");
                    QRImageDecoder.source = imageCapture.preview
                }
    
            }
        }
        Timer {
            id: timer
            interval: 500; running: false; repeat: true
            onTriggered:
            {
                console.log("camera:",camera.cameraFormat.pixelFormat)
                if( imageCapture.readyForCapture )
                {
                    imageCapture.capture();
                }
            }
        }
        MyButton
        {
            id:startcamera
            anchors.centerIn: root
            text:qsTr("ScanQr")
            onClicked:
            {
                QRImageDecoder.requestPermision();
            }
            width:100
            height:width*0.5
        }
    }
    

    The thing is that when pressing the 'ScanQr' button, the app ask for permission to use the camera. If the permission is granted The video is shown on the app but the video is lagging.
    And the imageCapture.readyForCapture is always false.

    On the debugger, I get:

    W Gralloc4: allocator 3.x is not supported
    W Gralloc3: allocator 3.x is not supported
    W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
    W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
    

    Any help will be much appreciated.
    Thank you for your time.

    MesrineM ekkescornerE 2 Replies Last reply
    0
    • MesrineM Mesrine

      Hello everyone,

      I am testing a qr decoder using android
      the custom qml type-file is

      import QtQuick 2.0
      import QtMultimedia
      import QtQrDec
      import MyDesigns
      
      Item
      {
          id:root
          signal gotdata(string data);
          function stop() {
              timer.stop();
              camera.stop();
              startcamera.visible=true;
          }
      
          VideoOutput {
              id: videoOutput
              anchors.fill: root
          }
          MediaDevices {
              id: devices
          }
          Camera {
              id: camera
              active: false
              cameraDevice: devices.defaultVideoInput
              onErrorOccurred: (error,errorString)=> {
                                   console.log( devices.videoInputs);
                                   console.log(errorString)
                                   console.log(error)
                               }
      
          }
          Connections {
              target: QRImageDecoder
              function onText_changed(boo) {
                  root.gotdata(QRImageDecoder.text)
              }
          }
          Connections {
              target: QRImageDecoder
              function onPermissionRequested(boo) {
                  if(boo)
                  {
                      console.log( devices.videoInputs);
                      console.log(camera.cameraFormat)
      
                      devices.videoInputs.forEach((Cdev)
                                                  => {
                                                      if(Cdev.position===Cdev.BackFace)
                                                      {
                                                          camera.cameraDevice=Cdev;
                                                      }
                                                  });
      
      
                      camera.start();
                      timer.start();
                      startcamera.visible=false;
                  }
              }
          }
      
          CaptureSession {
              id: capturesession
              camera: camera
              videoOutput: videoOutput
              imageCapture: ImageCapture {
                  id: imageCapture
                  onErrorOccurred:(requestId, error, message)=> {
                                      console.log("capture error:",message)
      
                  }
      
                  onImageCaptured: {
                      console.log("onImageCaptured");
                      QRImageDecoder.source = imageCapture.preview
                  }
      
              }
          }
          Timer {
              id: timer
              interval: 500; running: false; repeat: true
              onTriggered:
              {
                  console.log("camera:",camera.cameraFormat.pixelFormat)
                  if( imageCapture.readyForCapture )
                  {
                      imageCapture.capture();
                  }
              }
          }
          MyButton
          {
              id:startcamera
              anchors.centerIn: root
              text:qsTr("ScanQr")
              onClicked:
              {
                  QRImageDecoder.requestPermision();
              }
              width:100
              height:width*0.5
          }
      }
      

      The thing is that when pressing the 'ScanQr' button, the app ask for permission to use the camera. If the permission is granted The video is shown on the app but the video is lagging.
      And the imageCapture.readyForCapture is always false.

      On the debugger, I get:

      W Gralloc4: allocator 3.x is not supported
      W Gralloc3: allocator 3.x is not supported
      W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
      W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
      

      Any help will be much appreciated.
      Thank you for your time.

      MesrineM Offline
      MesrineM Offline
      Mesrine
      wrote on last edited by Mesrine
      #2

      @Mesrine

      I have tried the declarative camera example on Android and it works ok. It also returns the same warnings

      W Gralloc4: allocator 3.x is not supported
      W Gralloc3: allocator 3.x is not supported
      W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
      W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
      

      The video is lagging on my app because calling imageCapture.capture() freezes the VideoOutput. This freeze does not happen on the Desktop.
      Do you think it freezes because of memory issues or is it a feature?

      1 Reply Last reply
      0
      • MesrineM Mesrine

        Hello everyone,

        I am testing a qr decoder using android
        the custom qml type-file is

        import QtQuick 2.0
        import QtMultimedia
        import QtQrDec
        import MyDesigns
        
        Item
        {
            id:root
            signal gotdata(string data);
            function stop() {
                timer.stop();
                camera.stop();
                startcamera.visible=true;
            }
        
            VideoOutput {
                id: videoOutput
                anchors.fill: root
            }
            MediaDevices {
                id: devices
            }
            Camera {
                id: camera
                active: false
                cameraDevice: devices.defaultVideoInput
                onErrorOccurred: (error,errorString)=> {
                                     console.log( devices.videoInputs);
                                     console.log(errorString)
                                     console.log(error)
                                 }
        
            }
            Connections {
                target: QRImageDecoder
                function onText_changed(boo) {
                    root.gotdata(QRImageDecoder.text)
                }
            }
            Connections {
                target: QRImageDecoder
                function onPermissionRequested(boo) {
                    if(boo)
                    {
                        console.log( devices.videoInputs);
                        console.log(camera.cameraFormat)
        
                        devices.videoInputs.forEach((Cdev)
                                                    => {
                                                        if(Cdev.position===Cdev.BackFace)
                                                        {
                                                            camera.cameraDevice=Cdev;
                                                        }
                                                    });
        
        
                        camera.start();
                        timer.start();
                        startcamera.visible=false;
                    }
                }
            }
        
            CaptureSession {
                id: capturesession
                camera: camera
                videoOutput: videoOutput
                imageCapture: ImageCapture {
                    id: imageCapture
                    onErrorOccurred:(requestId, error, message)=> {
                                        console.log("capture error:",message)
        
                    }
        
                    onImageCaptured: {
                        console.log("onImageCaptured");
                        QRImageDecoder.source = imageCapture.preview
                    }
        
                }
            }
            Timer {
                id: timer
                interval: 500; running: false; repeat: true
                onTriggered:
                {
                    console.log("camera:",camera.cameraFormat.pixelFormat)
                    if( imageCapture.readyForCapture )
                    {
                        imageCapture.capture();
                    }
                }
            }
            MyButton
            {
                id:startcamera
                anchors.centerIn: root
                text:qsTr("ScanQr")
                onClicked:
                {
                    QRImageDecoder.requestPermision();
                }
                width:100
                height:width*0.5
            }
        }
        

        The thing is that when pressing the 'ScanQr' button, the app ask for permission to use the camera. If the permission is granted The video is shown on the app but the video is lagging.
        And the imageCapture.readyForCapture is always false.

        On the debugger, I get:

        W Gralloc4: allocator 3.x is not supported
        W Gralloc3: allocator 3.x is not supported
        W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
        W ample.nftminte: [SurfaceTexture-4-9500-0] bindTextureImage: clearing GL error: 0x500
        

        Any help will be much appreciated.
        Thank you for your time.

        ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by
        #3

        @Mesrine said in QML Camera does not work on android!:

        lagging

        don't know if this is the reason of your problems, but your QML Camera classes structure isn't valid from my POV: Camera should be inside CaptureSession
        see here my blog about Port QML Camera 5.15 to 6.6
        01_camera_classes.png

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.8 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        MesrineM 1 Reply Last reply
        2
        • ekkescornerE ekkescorner

          @Mesrine said in QML Camera does not work on android!:

          lagging

          don't know if this is the reason of your problems, but your QML Camera classes structure isn't valid from my POV: Camera should be inside CaptureSession
          see here my blog about Port QML Camera 5.15 to 6.6
          01_camera_classes.png

          MesrineM Offline
          MesrineM Offline
          Mesrine
          wrote on last edited by Mesrine
          #4

          @ekkescorner
          Thanks, I am no longer using imageCapture.capture(). I do not understand the difference between declaring the camera outside the CaptureSession and inside the CaptureSession. There is no warning or a mandatory statement about this in the documentation, or there is?

          ekkescornerE 1 Reply Last reply
          0
          • MesrineM Mesrine

            @ekkescorner
            Thanks, I am no longer using imageCapture.capture(). I do not understand the difference between declaring the camera outside the CaptureSession and inside the CaptureSession. There is no warning or a mandatory statement about this in the documentation, or there is?

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #5

            @Mesrine you're right. have overlooked that inside CaptureSession you set camera: camera

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.8 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved