I want to create an application that uses laptop's camera to take photos repeatedly and send the photo's bytes via protobuf. With the below code, on Windows everything works perfectly but on Ubuntu 22.04 (ran on a virtual machine) only one photo is sent after that the camera does not take any other photos.
void Camera::setCamera(const QCameraInfo& cameraInfo)
{
m_camera.reset(new QCamera(cameraInfo));
m_camera.data()->setCaptureMode(QCamera::CaptureStillImage);
m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
m_imageCapture.data()->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
// connect
QObject::connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, [=] (int id, QImage img){
++photosTaken;
QByteArray buf;
QBuffer buffer(&buf);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "JPG");
std::string protoData(buf.constData(), buf.length());
// create and send protobuf
foxglove::CompressedImage compressedImageProto;
compressedImageProto.set_data(protoData);
compressedImageProto.set_format("jpg");
m_publisher.Send(compressedImageProto);
std::cout << "Sent photo number: " << photosTaken << " with size: " << compressedImageProto.ByteSizeLong() << std::endl;
});
QObject::connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, [=] (bool state) {
if(state == true) {
m_camera.data()->searchAndLock();
m_imageCapture.data()->capture();
m_camera.data()->unlock();
}
});
m_camera.data()->start();
}