mainwindow.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QImage>
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. timer = new QTimer(this);
  10. on_refreshRateSlider_valueChanged(100);
  11. cv::Mat image = cv::Mat::zeros(frame.size(),CV_8UC3);
  12. qt_image = QImage((const unsigned char*) (image.data), image.cols, image.rows, QImage::Format_RGB888 );
  13. myFunctions.init_detect_visages();
  14. }
  15. MainWindow::~MainWindow()
  16. {
  17. delete ui;
  18. }
  19. void MainWindow::on_pushButton_open_webcam_clicked()
  20. {
  21. cap.open(0);
  22. if(!cap.isOpened()) // Check if we succeeded
  23. {
  24. statusBar()->showMessage("Error !");
  25. }
  26. else
  27. {
  28. connect(timer, SIGNAL(timeout()), this, SLOT(update_window()));
  29. timer->start(ui->refreshRateSlider->value());
  30. statusBar()->showMessage("Camera is open !");
  31. }
  32. }
  33. void MainWindow::on_pushButton_close_webcam_clicked()
  34. {
  35. disconnect(timer, SIGNAL(timeout()), this, SLOT(update_window()));
  36. cap.release();
  37. cv::Mat image = cv::Mat::zeros(frame.size(),CV_8UC3);
  38. qt_image = QImage((const unsigned char*) (image.data), image.cols, image.rows, QImage::Format_RGB888);
  39. ui->label->setPixmap(QPixmap::fromImage(qt_image));
  40. ui->label->resize(ui->label->pixmap()->size());
  41. cout << "camera is closed" << endl;
  42. }
  43. void MainWindow::update_window()
  44. {
  45. /*
  46. * Todo !
  47. * Fonction détection du mode
  48. */
  49. /* Capture de l'image */
  50. cap >> frame;
  51. /* Infos Live */
  52. ui->resText->setText(QString::number(frame.size().width) + "x" + QString::number(frame.size().height));
  53. /* Check des options
  54. * Mode Couleur
  55. */
  56. if ( ui->colorchooseComboBox->currentIndex() ==0 ) {
  57. if (ui->objectDetectorComboBox->currentIndex() == 0) {
  58. qt_image = QImage((const unsigned char*) (frame.data), frame.cols, frame.rows, QImage::Format_RGB888);
  59. }
  60. if (ui->objectDetectorComboBox->currentIndex() == 1) {
  61. qt_image = QImage((unsigned char*) (myFunctions.detect_visages(frame, RGB8).data), frame.cols, frame.rows, QImage::Format_RGB888);
  62. }
  63. if (ui->objectDetectorComboBox->currentIndex() == 2) {
  64. qt_image = QImage((unsigned char*) (myFunctions.dnn_test(frame).data), frame.cols, frame.rows, QImage::Format_RGB888);
  65. }
  66. }
  67. /*
  68. * Mode BW
  69. */
  70. if ( ui->colorchooseComboBox->currentIndex() == 1 ) {
  71. if (ui->objectDetectorComboBox->currentIndex() == 0) {
  72. cv::cvtColor(frame, framebw, cv::COLOR_BGR2GRAY);
  73. qDebug() << "cvtColor OK";
  74. qt_image = QImage((const unsigned char*) (framebw.data), framebw.cols, framebw.rows, QImage::Format_Grayscale8);
  75. qDebug() << "qt_image updated";
  76. }
  77. if (ui->objectDetectorComboBox->currentIndex() == 1) {
  78. qt_image = QImage((const unsigned char*) (myFunctions.detect_visages(frame, GREY8).data), framebw.cols, framebw.rows, QImage::Format_RGB888) ;
  79. }
  80. }
  81. ui->label->setPixmap(QPixmap::fromImage(qt_image));
  82. ui->label->resize(ui->label->pixmap()->size());
  83. //-- Show what you got
  84. //imshow( window_name, frame );
  85. }
  86. void MainWindow::on_refreshRateSlider_valueChanged(int value)
  87. {
  88. ui->refreshRateText->setText(QString::number(value) + " ms");
  89. timer->start(value);
  90. }