#include "mainwindow.h" #include "ui_mainwindow.h" #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); timer = new QTimer(this); on_refreshRateSlider_valueChanged(100); cv::Mat image = cv::Mat::zeros(frame.size(),CV_8UC3); qt_image = QImage((const unsigned char*) (image.data), image.cols, image.rows, QImage::Format_RGB888 ); myFunctions.init_detect_visages(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_open_webcam_clicked() { cap.open(0); if(!cap.isOpened()) // Check if we succeeded { statusBar()->showMessage("Error !"); } else { connect(timer, SIGNAL(timeout()), this, SLOT(update_window())); timer->start(ui->refreshRateSlider->value()); statusBar()->showMessage("Camera is open !"); } } void MainWindow::on_pushButton_close_webcam_clicked() { disconnect(timer, SIGNAL(timeout()), this, SLOT(update_window())); cap.release(); cv::Mat image = cv::Mat::zeros(frame.size(),CV_8UC3); qt_image = QImage((const unsigned char*) (image.data), image.cols, image.rows, QImage::Format_RGB888); ui->label->setPixmap(QPixmap::fromImage(qt_image)); ui->label->resize(ui->label->pixmap()->size()); cout << "camera is closed" << endl; } void MainWindow::update_window() { /* * Todo ! * Fonction détection du mode */ /* Capture de l'image */ cap >> frame; /* Infos Live */ ui->resText->setText(QString::number(frame.size().width) + "x" + QString::number(frame.size().height)); /* Check des options * Mode Couleur */ if ( ui->colorchooseComboBox->currentIndex() ==0 ) { if (ui->objectDetectorComboBox->currentIndex() == 0) { qt_image = QImage((const unsigned char*) (frame.data), frame.cols, frame.rows, QImage::Format_RGB888); } if (ui->objectDetectorComboBox->currentIndex() == 1) { qt_image = QImage((unsigned char*) (myFunctions.detect_visages(frame, RGB8).data), frame.cols, frame.rows, QImage::Format_RGB888); } if (ui->objectDetectorComboBox->currentIndex() == 2) { qt_image = QImage((unsigned char*) (myFunctions.dnn_test(frame).data), frame.cols, frame.rows, QImage::Format_RGB888); } } /* * Mode BW */ if ( ui->colorchooseComboBox->currentIndex() == 1 ) { if (ui->objectDetectorComboBox->currentIndex() == 0) { cv::cvtColor(frame, framebw, cv::COLOR_BGR2GRAY); qDebug() << "cvtColor OK"; qt_image = QImage((const unsigned char*) (framebw.data), framebw.cols, framebw.rows, QImage::Format_Grayscale8); qDebug() << "qt_image updated"; } if (ui->objectDetectorComboBox->currentIndex() == 1) { qt_image = QImage((const unsigned char*) (myFunctions.detect_visages(frame, GREY8).data), framebw.cols, framebw.rows, QImage::Format_RGB888) ; } } ui->label->setPixmap(QPixmap::fromImage(qt_image)); ui->label->resize(ui->label->pixmap()->size()); //-- Show what you got //imshow( window_name, frame ); } void MainWindow::on_refreshRateSlider_valueChanged(int value) { ui->refreshRateText->setText(QString::number(value) + " ms"); timer->start(value); }