Solved Using a thermal camera in qt
-
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:
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 -
@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.
-
thanks,Can you tell me how to do this?Or give an example?
-
Hi,
The key information here is the life time of the buffer that you use to create your QImage object.
-
@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? -
Check QCameraViewfinderSettings.
-
Thank you for your help.
-
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 :) -
@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)?
-
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(); }
-
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(); }