0

我只是想拍照并希望将其保存到 QImage 并稍后保存到文件中。但是在这一点上,我总是得到捕获会话尚未准备好的信息。我不需要gui,我只是需要后端。对于所有的帮助,我将永远感激不尽。

主文件

#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");

}
4

0 回答 0