Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qCamera
Qt 6.11 is out! See what's new in the release blog

qCamera

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 3 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Negar_mgN Offline
    Negar_mgN Offline
    Negar_mg
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean that example ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Negar_mgN 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you mean that example ?

        Negar_mgN Offline
        Negar_mgN Offline
        Negar_mg
        wrote on last edited by
        #3

        @SGaist
        yes,i try it ,But the video recording did not work
        and the code is complicated for me.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Which platform are you on ?

          As for the complexity of this example, what exactly is the issue ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Negar_mgN 1 Reply Last reply
          0
          • SGaistS SGaist

            Which platform are you on ?

            As for the complexity of this example, what exactly is the issue ?

            Negar_mgN Offline
            Negar_mgN Offline
            Negar_mg
            wrote on last edited by Negar_mg
            #5

            @SGaist said in qCamera:

            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?

            jsulmJ 1 Reply Last reply
            0
            • Negar_mgN Negar_mg

              @SGaist said in qCamera:

              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?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Negar_mg said in qCamera:

              Example qt on my system only takes pictures and does not record any video

              You need to switch to "Video" tab in that example

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Negar_mgN 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Negar_mg said in qCamera:

                Example qt on my system only takes pictures and does not record any video

                You need to switch to "Video" tab in that example

                Negar_mgN Offline
                Negar_mgN Offline
                Negar_mg
                wrote on last edited by
                #7

                @jsulm cameraaa.png
                it's Inactive.How do I enable it?

                jsulmJ 1 Reply Last reply
                0
                • Negar_mgN Negar_mg

                  @jsulm cameraaa.png
                  it's Inactive.How do I enable it?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Negar_mgN 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @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?

                    Negar_mgN Offline
                    Negar_mgN Offline
                    Negar_mg
                    wrote on last edited by
                    #9

                    @jsulm
                    I tested this camera with opencv and it had no problem,
                    On the other hand, I tested this program on a laptop, with a webcam, and it was the same.
                    Is it possible that the problem is using Windows?

                    jsulmJ 1 Reply Last reply
                    0
                    • Negar_mgN Negar_mg

                      @jsulm
                      I tested this camera with opencv and it had no problem,
                      On the other hand, I tested this program on a laptop, with a webcam, and it was the same.
                      Is it possible that the problem is using Windows?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Negar_mg It should work.
                      What Qt version and compiler do you use?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Negar_mgN 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Negar_mg It should work.
                        What Qt version and compiler do you use?

                        Negar_mgN Offline
                        Negar_mgN Offline
                        Negar_mg
                        wrote on last edited by
                        #11

                        @jsulm
                        qt creator 4.15.0
                        kit=qt 5.12.11 MSVC2015 64bit

                        jsulmJ 1 Reply Last reply
                        0
                        • Negar_mgN Negar_mg

                          @jsulm
                          qt creator 4.15.0
                          kit=qt 5.12.11 MSVC2015 64bit

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Negar_mg Can you try with more recent version (5.15.2)?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Negar_mgN 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Negar_mg Can you try with more recent version (5.15.2)?

                            Negar_mgN Offline
                            Negar_mgN Offline
                            Negar_mg
                            wrote on last edited by
                            #13

                            @jsulm
                            I'm trying now.

                            1 Reply Last reply
                            0
                            • Negar_mgN Offline
                              Negar_mgN Offline
                              Negar_mg
                              wrote on last edited by
                              #14

                              kit.png
                              My program only has these kits. Can it be added to the new kit?

                              jsulmJ 1 Reply Last reply
                              0
                              • Negar_mgN Negar_mg

                                kit.png
                                My program only has these kits. Can it be added to the new kit?

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Negar_mg said in qCamera:

                                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).

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • Negar_mgN Offline
                                  Negar_mgN Offline
                                  Negar_mg
                                  wrote on last edited by
                                  #16
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • Negar_mgN Offline
                                    Negar_mgN Offline
                                    Negar_mg
                                    wrote on last edited by Negar_mg
                                    #17

                                    Thank you for your help
                                    I used Qt_5_15_2-Debug, but the part related to video recording is still inactive.
                                    I encountered this error while using this kit:
                                    Unsupported media type: "{32595559-0000-0010-8000-00AA00389B71}"

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved