Android Qt 5.15 Camera: QCameraImageCapture error: "Camera not ready"
-
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
-
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
-
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
@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).
-
@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).
@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
-
@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
presentandstartto 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; }