'QCamera - help setting one resolution for viewport preview and a bigger one for capture

I'm having issues when using an external USB camera in a QT C++ app.

My objective is to display on the screen a live preview, and to take a picture at a given moment.

For that, I was planning to use a QCameraViewfinder to get my preview, and a QCameraImageCapture to take the picture.

My wish is also to do the preview at low resolution (to have a decent fps) and to take the picture at full resolution. Nothing complicated I think.

Reading through the QCamera Overview, it looks fine to do like this.

Problem : I can't see how to set a different resolution on the viewfinder and on the ImageCapture.

My code looks like this, to init the camera :

QCamera *cameraUnitaire;
QCameraImageCapture *imageCaptureUnitaire;
QCameraViewfinder *viewFinderUnitaire;
QCameraViewfinderSettings *reglageUnitaire;
QImageEncoderSettings imageSettings;

cameraUnitaire = new QCamera(cameraInfo);

imageCaptureUnitaire = new QCameraImageCapture(cameraUnitaire);

cameraUnitaire->start();

reglageUnitaire = new QCameraViewfinderSettings();

reglageUnitaire->setResolution(640,480);  //low res

cameraUnitaire->setViewfinderSettings(*reglageUnitaire);

viewFinderUnitaire= new QCameraViewfinder();

viewFinderUnitaire->setFixedWidth(640); //low res again
viewFinderUnitaire->setFixedHeight(480);

cameraUnitaire->setViewfinder(viewFinderUnitaire);

imageSettings.setCodec("image/jpeg");
imageSettings.setResolution(2592, 1944);   //high res

imageCaptureUnitaire->setEncodingSettings(imageSettings);

And later, to capture the image :

qDebug() << "Ready ?" <<  imageCaptureUnitaire->isReadyForCapture();  //true
qDebug() << "Capture :" << imageCaptureUnitaire->capture("C:/Temp/lastmono");  //image size 640 * 480

   

and for the viewport :

QPixmap pixmap(viewFinderUnitaire->size());
viewFinderUnitaire->render(&pixmap);
m_dataImage = viewFinderUnitaire->grab();   //640*480


(... display the image)

Of course both 640x480 and 2592x1944 resolutions are supported by the camera (checked with supportedViewfinderResolutions in another piece of code)

My output picture (C:/Temp/lastmono.jpg) is at 640x480, not 2592x1944.

I don't get why my QCameraViewfinderSettings overwrite the QCameraImageCapture ones ?

I know that there is other classes available (QAbstractVideoSurface...) but didn't know if they could help me.

Thanks !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source