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. Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready"
Forum Updated to NodeBB v4.3 + New Features

Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready"

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 334 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.
  • NihilishN Offline
    NihilishN Offline
    Nihilish
    wrote last edited by Nihilish
    #1

    I'm trying to get the camera on an Android tablet to feed frames to a model I have that will analyze every frame. I don't want/need to show a viewfinder, as this is just background processing. I have tried a bunch of different things and I always end up with a variation of

    'QCameraImageCapture error: "Camera not ready"'

    Camera {
                    id: camera
                    captureMode: Camera.CaptureStillImage
                    cameraState: Camera.ActiveState
                    position: Camera.FrontFace
    
                    imageCapture {
                        onReadyChanged: {
                            camera.imageCapture.capture()
                        }
                        onImageCaptured: {
                            console.log(requestId, preview)
                        }
                    }
                }
    
                Component.onCompleted: {
                    camera.start()
                }
    

    This code is in my main QML container, it runs as soon the app is instantiated. The goal is for me to add a call to my model in onImageCaptured with the frame. But I get the "Camera not ready" error periodically.

    What am I missing? I would do everything from the model with the QCamera object, but I've read that QCamera doesn't work on Android, only the QML Camera does. The weird thing is if I attach a VideoOutput component to the camera, I can see the camera feed. But imageCapture still. gives me that "Camera not ready error" error

    M jsulmJ 2 Replies Last reply
    0
    • NihilishN Nihilish

      I'm trying to get the camera on an Android tablet to feed frames to a model I have that will analyze every frame. I don't want/need to show a viewfinder, as this is just background processing. I have tried a bunch of different things and I always end up with a variation of

      'QCameraImageCapture error: "Camera not ready"'

      Camera {
                      id: camera
                      captureMode: Camera.CaptureStillImage
                      cameraState: Camera.ActiveState
                      position: Camera.FrontFace
      
                      imageCapture {
                          onReadyChanged: {
                              camera.imageCapture.capture()
                          }
                          onImageCaptured: {
                              console.log(requestId, preview)
                          }
                      }
                  }
      
                  Component.onCompleted: {
                      camera.start()
                  }
      

      This code is in my main QML container, it runs as soon the app is instantiated. The goal is for me to add a call to my model in onImageCaptured with the frame. But I get the "Camera not ready" error periodically.

      What am I missing? I would do everything from the model with the QCamera object, but I've read that QCamera doesn't work on Android, only the QML Camera does. The weird thing is if I attach a VideoOutput component to the camera, I can see the camera feed. But imageCapture still. gives me that "Camera not ready error" error

      M Offline
      M Offline
      mvuori
      wrote last edited by
      #2

      @Nihilish I don't know what is missing, but QCamera does work in Android

      NihilishN 1 Reply Last reply
      0
      • NihilishN Nihilish

        I'm trying to get the camera on an Android tablet to feed frames to a model I have that will analyze every frame. I don't want/need to show a viewfinder, as this is just background processing. I have tried a bunch of different things and I always end up with a variation of

        'QCameraImageCapture error: "Camera not ready"'

        Camera {
                        id: camera
                        captureMode: Camera.CaptureStillImage
                        cameraState: Camera.ActiveState
                        position: Camera.FrontFace
        
                        imageCapture {
                            onReadyChanged: {
                                camera.imageCapture.capture()
                            }
                            onImageCaptured: {
                                console.log(requestId, preview)
                            }
                        }
                    }
        
                    Component.onCompleted: {
                        camera.start()
                    }
        

        This code is in my main QML container, it runs as soon the app is instantiated. The goal is for me to add a call to my model in onImageCaptured with the frame. But I get the "Camera not ready" error periodically.

        What am I missing? I would do everything from the model with the QCamera object, but I've read that QCamera doesn't work on Android, only the QML Camera does. The weird thing is if I attach a VideoOutput component to the camera, I can see the camera feed. But imageCapture still. gives me that "Camera not ready error" error

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote last edited by
        #3

        @Nihilish said in Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready":

        What am I missing?

        Access rights for the camera? On mobile platforms like Android your app needs to request access rights for the camera (and many other things).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        NihilishN 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Nihilish said in Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready":

          What am I missing?

          Access rights for the camera? On mobile platforms like Android your app needs to request access rights for the camera (and many other things).

          NihilishN Offline
          NihilishN Offline
          Nihilish
          wrote last edited by
          #4

          @jsulm I did request and give permission to use the camera in the AndroidManifest. I noticed yesterday that even though I get the "camera not ready" error, the camera is taking and saving a bunch of pictures in /storage/emulated/0/DCIM/IMG_xxxx.jpg. So something is working but it's not triggering onImageCaptured

          1 Reply Last reply
          0
          • M mvuori

            @Nihilish I don't know what is missing, but QCamera does work in Android

            NihilishN Offline
            NihilishN Offline
            Nihilish
            wrote last edited by
            #5

            @mvuori said in Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready":

            @Nihilish I don't know what is missing, but QCamera does work in Android

            Here's an attempt I made using QCamera by creating a CameraManager class that implements QAbstractVideoSurface. I would expect present and start to be called but they aren't.

            #include "CameraManager.h"
            
            #include <QQuickWindow>
            #include <QWindow>
            #include <QCameraViewfinder>
            #include <QCameraInfo>
            
            CameraManager::CameraManager(QObject *parent)
                : QAbstractVideoSurface{parent},
                mCamera(nullptr)
            {
                QList<QCameraInfo> cameras = QCameraInfo::availableCameras(QCamera::Position::FrontFace);
                if (!cameras.isEmpty())
                {
                    qDebug() << "HACK - CREATE CAMERA!!!";
            
                    mCamera = new QCamera(cameras.first(), this);
                    mCamera->setViewfinder(this);
                    mCamera->setCaptureMode(QCamera::CaptureVideo);
                    mCamera->start();
            
                    qDebug() << "HACK - CAMERA STATE: " << mCamera->state();
                    qDebug() << "HACK - CAMERA SUPPORTED FORMATS: " << mCamera->supportedViewfinderPixelFormats();
                }
            }
            
            
            bool CameraManager::start(const QVideoSurfaceFormat &format)
            {
                qDebug() << "HACK - START!!!";
            
                if (!supportedPixelFormats(QAbstractVideoBuffer::NoHandle).contains(format.pixelFormat())) {
                    return false;
                }
                return QAbstractVideoSurface::start(format);
            }
            
            
            bool CameraManager::present(const QVideoFrame &frame)
            {
                qDebug() << "HACK - PRESENT FRAME";
            
                if (!frame.isValid())
                    return false;
            
                emit frameAvailable(frame);
                return true;
            }
            
            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