I'm just simply trying to take a photo and save it hopefully to QImage and later on to file. But at this point I always get information that capture session is not ready. I don't need gui I jest need backend for this. For all the help I will be eternally grateful.
main.cpp
#include <QCamera>
#include <QGuiApplication>
#include <QMediaDevices>
#include <QQmlApplicationEngine>
#include <QMediaCaptureSession>
#include <QImageCapture>
static QString CAMERA_ID = "UVC Camera";
QVariant getCamera(QString cameraId){
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
for(auto &camera: cameras){
if(camera.description() == cameraId){
return QVariant::fromValue(camera);
}
}
return QVariant();
}
int main(int argc, char *argv[])
{
QScopedPointer<QCamera> camera;
QMediaCaptureSession captureSession;
QImageCapture* imageCapture;
QVariant cameraOptional = getCamera(CAMERA_ID);
if(cameraOptional.isValid()){
camera.reset(new QCamera(cameraOptional.value<QCameraDevice>()));
}
captureSession.setCamera(camera.data());
imageCapture = new QImageCapture;
captureSession.setImageCapture(imageCapture);
camera->start(); // Viewfinder frames start flowing
//on shutter button pressed
if(imageCapture->isReadyForCapture()){
qDebug()<<"isReady";
}else{
qDebug()<<"notReady";
}
imageCapture->captureToFile("C:/Users/lukas/Pictures/img.jpg");
}