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. Using a thermal camera in qt

Using a thermal camera in qt

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 988 Views 2 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 want to use the thermal camera in my program, this is the code I wrote for a normal camera that connects via USB, but when I connect the thermal camera to the same USB port, the image looks like this:
    test.jpg

    and this is my code

    void MainWindow::on_btn_thermal_start_clicked()
     {
    
    thermalCap.open(1);
    
    if(!thermalCap.isOpened())  // Check if we succeeded
    {
        cout << "camera is not open" << endl;
        errordialog("Thermal_camera is not open" );
    }
    else
    {
        cout << "camera is open" << endl;
        Thermal_CameraTimeout_Func();
    }
    }
      void MainWindow::Thermal_update_PicInWindow()
      {
          //thermal
          thermalCap >> thermalFrame;
          flip(thermalFrame, thermalFrame, 1);
      
          cvtColor(thermalFrame, thermalFrame,COLOR_BGR2RGB);
      
          thermalImage = QImage((const unsigned char*) (thermalFrame.data),
                               thermalFrame.cols, thermalFrame.rows, QImage::Format_RGB888);
      
          ui->lbl_thermal->setPixmap(QPixmap::fromImage(thermalImage));
      
          ui->lbl_thermal->resize(ui->lbl_thermal->pixmap()->size());
      }
      
      void MainWindow::Thermal_CameraTimeout_Func()
      {
          if (!(timerthermalVideo->isActive()))
          {
              timerthermalVideo->start(50);
              ui->btn_thermal_start->setText("STOP_Camera");
              Thermal_update_PicInWindow();
      
          }
          else if (timerthermalVideo->isActive())
          {
              timerthermalVideo->stop();
              ui->btn_thermal_start->setText("START_Camera");
              thermalCap.release();
      
          }
      
      }
    

    i am using lepton flir 2 and qt5 and windows
    If you have any advice or suggestions, please let me know

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Negar_mg said in Using a thermal camera in qt:

      thermalImage = QImage((const unsigned char*) (thermalFrame.data),
      thermalFrame.cols, thermalFrame.rows, QImage::Format_RGB888);

      As always when creating a QImage from some raw data - read the docs, especially about the memory management.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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

        thanks,Can you tell me how to do this?Or give an example?

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

          Hi,

          The key information here is the life time of the buffer that you use to create your QImage object.

          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
          1
          • SGaistS SGaist

            Hi,

            The key information here is the life time of the buffer that you use to create your QImage object.

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

            @SGaist said in Using a thermal camera in qt:

            The key information here is the life time of the buffer that you use to create your QImage object.

            Thanks, I noticed that my thermal camera image on Google (webcam test) is also gray, but in Firefox (webcam test) it is the natural color, the difference between the two sites is in the image mode and in the video standard.
            In Google, which displays an image similar to my program:
            Image mode = gray scale
            Video standard = ???
            And in Firefox this information is equal to
            Image mode = rgb
            Video standard = QQVGA
            Can this information be changed in qt? How?

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

              Check QCameraViewfinderSettings.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - 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
                #7

                Thank you for your help.

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

                  I used the qcamera example for my thermal camera, I wanted to ask what command should I use to make the image rotate (like a mirror)?
                  And what command should I use to stop the image?
                  Thank you for your help :)

                  Pl45m4P 1 Reply Last reply
                  0
                  • Negar_mgN Negar_mg

                    I used the qcamera example for my thermal camera, I wanted to ask what command should I use to make the image rotate (like a mirror)?
                    And what command should I use to stop the image?
                    Thank you for your help :)

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by
                    #9

                    @Negar_mg said in Using a thermal camera in qt:

                    I wanted to ask what command should I use to make the image rotate (like a mirror)?

                    • https://doc.qt.io/qt-5/qimage.html#image-transformations
                    • https://doc.qt.io/qt-5/qimage.html#mirrored

                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

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

                      Thanks, but I used the Camera Example in qt and the code is as follows and as far as I know it did not use qimage.

                      menu = new QMenu;
                      
                      videoDevicesGroup = new QActionGroup(this);
                      videoDevicesGroup->setExclusive(true);
                      const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras();
                      for (const QCameraInfo &cameraInfo : availableCameras) {
                          QAction *videoDeviceAction = new QAction(cameraInfo.description(), videoDevicesGroup);
                          videoDeviceAction->setCheckable(true);
                          videoDeviceAction->setData(QVariant::fromValue(cameraInfo));
                          if (cameraInfo == QCameraInfo::defaultCamera())
                              videoDeviceAction->setChecked(true);
                      
                          menu->addAction(videoDeviceAction);
                      }
                      
                      
                      ui->cameraLayout->addWidget(menu);
                      

                      //................................................................................................................

                             void MainWindow::updateCameraDevice(QAction *action)
                            {
                             setCamera(qvariant_cast<QCameraInfo>(action->data()));
                            }
                      
                            void MainWindow::setCamera(const QCameraInfo &cameraInfo)
                            {
                                m_camera.reset(new QCamera(cameraInfo));
                      
                      
                                m_mediaRecorder.reset(new QMediaRecorder(m_camera.data()));
                      
                                m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
                      
                      
                                m_mediaRecorder->setMetaData(QMediaMetaData::Title,QVariant(QLatin1String("Test Title")));
                      
                      
                                ui->viewfinder->setMinimumSize( 600, 440 );
                                m_camera->setViewfinder(ui->viewfinder);
                      
                                m_camera->start();
                            }
                      
                      1 Reply Last reply
                      0
                      • Negar_mgN Offline
                        Negar_mgN Offline
                        Negar_mg
                        wrote on last edited by
                        #11

                        I solved my problem and I share it here,
                        In order for the camera image to be displayed like a mirror using qcamera, the code is as follows:

                         #include "mainwindow.h"
                         
                         #include "ui_mainwindow.h"
                         
                         
                         
                         MainWindow::MainWindow(QWidget *parent)
                         
                             : QMainWindow(parent)
                         
                             , ui(new Ui::MainWindow)
                         
                         {
                         
                             ui->setupUi(this);
                         
                             menu = new QMenu;
                         
                         
                         
                             QActionGroup *videoDevicesGroup = new QActionGroup(this);
                         
                             videoDevicesGroup->setExclusive(true);
                         
                             const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras();
                         
                             for (const QCameraInfo &cameraInfo : availableCameras) {
                         
                                 QAction *videoDeviceAction = new QAction(cameraInfo.description(), videoDevicesGroup);
                         
                                 videoDeviceAction->setCheckable(true);
                         
                                 videoDeviceAction->setData(QVariant::fromValue(cameraInfo));
                         
                                 if (cameraInfo == QCameraInfo::defaultCamera())
                         
                                     videoDeviceAction->setChecked(true);
                        
                                 menu->addAction(videoDeviceAction);
                        
                                 videoItem = new QGraphicsVideoItem;
                         
                                 videoItem->setSize(QSizeF(640, 480));
                        
                                 scene = new QGraphicsScene(this);
                         
                                 graphicsView = new QGraphicsView(scene);
                         
                         
                         
                                 scene->addItem(videoItem);
                         
                             }
                         
                         
                         
                             connect(videoDevicesGroup, &QActionGroup::triggered, this, &MainWindow::updateCameraDevice);
                         
                         
                         
                             setCamera(QCameraInfo::defaultCamera());
                         
                         
                         
                             ui->verticalLayout_2->addWidget(menu);
                         
                         }
                         
                         
                         
                         MainWindow::~MainWindow()
                         
                         {
                         
                             delete ui;
                         
                         }
                         
                         
                         
                         void MainWindow::updateCameraDevice(QAction *action)
                         
                         {
                         
                             setCamera(qvariant_cast<QCameraInfo>(action->data()));
                         
                         }
                         
                         
                         
                         void MainWindow::setCamera(const QCameraInfo &cameraInfo)
                         
                         {
                             m_camera.reset(new QCamera(cameraInfo));
                         
                             QTransform xForm;
                         
                             xForm.scale(-1,1);
                         
                             xForm.translate(-( scene->sceneRect().width() ), 0);
                             m_camera->setViewfinder(videoItem);
                            videoItem->setTransform(QTransform(xForm));
                             ui->verticalLayout_3->addWidget(graphicsView);
                             m_camera->start();
                         
                         }
                        
                        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