Snap Picture Not Working
-
I'm aware of that class, I just wanted to prototype with the easy way before messing with anything more complicated. If you could give me insight as to why my initial approach doesn't work, I'd appreciate it. In the mean time, I've also tried to start doing this the "right way", but alas ran into trouble rather fast. I connected the image capture to my class for when I snap a photo, but it's not getting into the function (which prints a simple id through qDebug). Here's my code:
MainWindow.c:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //qDebug() << "QCameraInfo: " << checkCameraAvailability(); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); camera = new QCamera(cameras.first()); imageCapture = new QCameraImageCapture(camera); connect(imageCapture,&QCameraImageCapture::imageAvailable,this,&MainWindow::testFunc); camView = new QCameraViewfinder(); camera->setViewfinder(camView); camView->show(); camera->start(); ui->horizontalLayout->addWidget(camView); ui->horizontalLayout->addWidget(&testLabel); } MainWindow::~MainWindow() { delete ui; } void MainWindow::testFunc(int id, QVideoFrame buffer) { qDebug() << id; } void MainWindow::on_SnapButton_clicked() { imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer); imageCapture->setBufferFormat(QVideoFrame::Format_Jpeg); camera->setCaptureMode(QCamera::CaptureStillImage); camera->searchAndLock(); imageCapture->capture(); camera->unlock(); //testLabel.setPixmap(camView->grab()); } -
I looked around and read that "imageCapture->capture();" will only capture to a file (and filled up my picture directory). I haven't found any way to trigger a capture to buffer. Can anyone help?
-
Did you try connecting the imageCaptured signal (forgive the old syntax) ?
connect(m_pImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(processCapturedImage(int,QImage)));Then the slot:
void xxxxx::processCapturedImage(int requestId, const QImage& img)You can extract from the QImage passed to the slot.
-
Since you want to send it to a REST service, why not exploit the fact that having that temporary file allows you to retry a failed upload without clogging the memory used by your application. You can delete the file once you're done with it.
-
I looked into using the QImage, but I would either have to convert it to a QVideoFrame (and I couldn't find how), or perform a tedious manual conversion. I'd rather find out why the buffer option isn't supported and fix it rather than hack my way around. I'm going to try on my Linux machine with a spare webacam I found and see if that works.
@SGaist
I don't see why a temporary image would fare better than a buffer. I would have to read the file and re-fill my buffer if it fails, resulting in more time lost. -
Because the windows platform camera plugin doesn't implement that option.
-
If there was, it would be part of the plugin. See the DSCameraSession class.