qCamera
-
Hi
I'm new to qt
I wanted to see the camera image using qcamera in my application. I was able to get the camera image using the example for c ++, now I want to take a photo and record video, the qt example was a bit complicated in this case, please help .
I used opencv before, when I used it, I could use the frame to take photos and record video, but I can't find the frame on my qcamera. -
Hi,
Do you mean that example ?
-
Which platform are you on ?
As for the complexity of this example, what exactly is the issue ?
-
Which platform are you on ?
As for the complexity of this example, what exactly is the issue ?I am using qt creator in Windows. In opencv I take a photo using a frame and record video, but in this example I do not know how to record video.
Example qt on my system only takes pictures and does not record any video.
I also found the following code, but this code does not record video either:#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connected = false; recording = false; camera = new QCamera(); qDebug() << QCameraInfo::availableCameras().count(); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); foreach (const QCameraInfo &cameraInfo, cameras) { qDebug() << cameraInfo.deviceName() << cameraInfo.description() << cameraInfo.position(); ui->deviceSelection->addItem(cameraInfo.description()); } } MainWindow::~MainWindow() { delete ui; } void MainWindow::connectCamera() { QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); foreach (const QCameraInfo &cameraInfo, cameras) { qDebug() << cameraInfo.description() << ui->deviceSelection->currentText(); if (cameraInfo.description() == ui->deviceSelection->currentText()) { camera = new QCamera(cameraInfo); viewfinder = new QCameraViewfinder(this); camera->setViewfinder(viewfinder); ui->webcamLayout->addWidget(viewfinder); connect(camera, SIGNAL(error(QCamera::Error)), this, SLOT(cameraError(QCamera::Error))); connected = true; ui->connectButton->setText("Disconnect"); camera->start(); return; } } } void MainWindow::on_connectButton_clicked() { if (!connected) { connectCamera(); } else { camera->stop(); viewfinder->deleteLater(); ui->connectButton->setText("Connect"); connected = false; } } void MainWindow::on_captureButton_clicked() { if (connected) { imageCapture = new QCameraImageCapture(camera); camera->setCaptureMode(QCamera::CaptureStillImage); camera->searchAndLock(); imageCapture->capture("E:/image.jpg"); camera->unlock(); } } void MainWindow::on_recordButton_clicked() { if (connected) { if (!recording) { recorder = new QMediaRecorder(camera); connect(recorder, SIGNAL(error(QMediaRecorder::Error)), this, SLOT(cameraError(QCamera::Error))); camera->setCaptureMode(QCamera::CaptureVideo); recorder->setOutputLocation(QUrl(qApp->applicationDirPath())); recorder->record(); recording = true; } else { recorder->stop(); recording = false; } } } void MainWindow::cameraError(QCamera::Error error) { qDebug() << error; connected = false; camera->stop(); ui->connectButton->setText("Connect"); } void MainWindow::recordError(QMediaRecorder::Error error) { qDebug() << recorder->errorString(); }
Please tell me what is used to record video and photos instead of frames?
Why is no video recorded in this code or in the qcamera example? -
@Negar_mg If you check https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimediawidgets/camera/camera.cpp?h=5.15 you will see
ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo)));
So, it sets the "Video" tab to enabled if m_camera->isCaptureModeSupported(QCamera::CaptureVideo) returns true. It looks like for your camera it returns false. I don't know what you can do to change this.
Does your camera support video recording? -
Can it be added to the new kit?
Yes, install current Qt version for your compiler, then you should get a new Kit automatically.
If you used Qt Online Installer to install Qt, then you can use Qt Maintenance Tool (you can find it in the root folder of your Qt set-up, c:\qt).