From 7aa410b6efbc5a9c7f1d9bd09e8a2be27a912a6f Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Thu, 11 Jun 2020 16:36:02 +0200 Subject: [PATCH] upgrade interface clarity + restart option in BeamerLocation routine --- app/SandboxSetup/beamerlocationgui.cpp | 47 ++++++++++++++++++---- app/SandboxSetup/beamerlocationgui.h | 3 ++ app/SandboxSetup/beamerlocationgui.ui | 31 ++++++++++++++- app/SandboxSetup/camerafocus.cpp | 4 +- app/SandboxSetup/croppingmask.cpp | 1 + app/SandboxSetup/croppingmask.ui | 13 +++--- app/SandboxSetup/initcamera.cpp | 2 +- app/SandboxSetup/mainwindow.cpp | 4 +- app/SandboxSetup/mainwindow.h | 2 +- app/SandboxSetup/monitorgui.cpp | 1 + app/SandboxSetup/monitorgui.ui | 20 ++++++++-- app/SandboxSetup/projectiongui.cpp | 2 +- app/SandboxSetup/projectiongui.ui | 55 +++++++++++++++++--------- app/SandboxSetup/saveconfiggui.cpp | 2 +- app/SandboxSetup/subapp.h | 2 +- src/components/beamer.cpp | 2 +- 16 files changed, 145 insertions(+), 46 deletions(-) diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp index f0bc3a3..378e6cc 100644 --- a/app/SandboxSetup/beamerlocationgui.cpp +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -20,6 +20,7 @@ BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWid mg = _mg; winFullScreen = new QtFullScreen(mg->getResolution(), true, this); ui->setupUi(this); + ui->txtInstructions->setAlignment(Qt::AlignJustify); myThread = new RefreshFrame(this); timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &BeamerLocationGui::refreshRoutine); @@ -71,8 +72,15 @@ void BeamerLocationGui::startRoutine(){ bases = std::vector<cv::Point3d>(); capturedPoints = std::vector<cv::Point3f>(); circle = std::vector<cv::Point3i>(); + updateLabelSteps(); - timer->start(200); + if(myThread->isRunning()){ + myThread->exit(0); + myThread->wait(); + } + + if(!timer->isActive()) + timer->start(100); } @@ -126,13 +134,14 @@ void BeamerLocationGui::userValidePoint(){ if(!circle.empty()){ capturedPoints.push_back( beamer->deprojectPixel(circle.at(0), &depth, camera) ); + updateLabelSteps(); // enough points to perform linear regression and move into next step if(capturedPoints.size() >= beamer->MAX_LINEAR_LINE_POINTS){ beamer->findLinearLineFrom(&capturedPoints, &bases, &directions); - capturedPoints = std::vector<cv::Point3f>(); - circle = std::vector<cv::Point3i>(); + capturedPoints.clear(); + circle.clear(); stepCross++; if((uint)stepCross >= crosses.size()){ @@ -145,18 +154,34 @@ void BeamerLocationGui::userValidePoint(){ void BeamerLocationGui::endRoutine(){ - timer->stop(); - myThread->exit(0); - myThread->wait(); - + timer->stop(); + myThread->exit(0); + myThread->wait(); endSuccess = (bases.size() == beamer->MAX_LINEAR_LINE_POINTS && directions.size() == beamer->MAX_LINEAR_LINE_POINTS); if(endSuccess){ // send to parent ReadyToValide - emit sendNotif(); + emit sendNotif(1); } winFullScreen->close(); + + cv::Mat black = cv::Mat(1, 1, CV_8UC3, cv::Scalar(0, 0, 0)); + QPixmap px = QPixmap::fromImage( QImage( (uchar *)black.data, + (int)black.cols, + (int)black.rows, + static_cast<int>(black.step.buf[0]), + QImage::Format_RGB888 ) ); + ui->lblFrame->setPixmap(px); +} + + +void BeamerLocationGui::updateLabelSteps(){ + + int state = stepCross*beamer->MAX_LINEAR_LINE_POINTS + capturedPoints.size() + 1; + int max = crosses.size() * beamer->MAX_LINEAR_LINE_POINTS; + std::string msg = (state <= max) ? std::to_string(state)+"/"+std::to_string(max) : "Complet"; + ui->lblSteps->setText( QString( msg.c_str() ) ); } @@ -164,3 +189,9 @@ void BeamerLocationGui::on_btnLock_clicked() { userValidePoint(); } + +void BeamerLocationGui::on_btnRestart_clicked() +{ + emit sendNotif(0); + startRoutine(); +} diff --git a/app/SandboxSetup/beamerlocationgui.h b/app/SandboxSetup/beamerlocationgui.h index 2cf6ede..b7e407a 100644 --- a/app/SandboxSetup/beamerlocationgui.h +++ b/app/SandboxSetup/beamerlocationgui.h @@ -33,6 +33,8 @@ private slots: void on_btnLock_clicked(); + void on_btnRestart_clicked(); + private: class RefreshFrame : public QThread { @@ -69,6 +71,7 @@ private: void userValidePoint(); void endRoutine(); void refreshRoutine(); + void updateLabelSteps(); }; #endif // BEAMERLOCATIONGUI_H diff --git a/app/SandboxSetup/beamerlocationgui.ui b/app/SandboxSetup/beamerlocationgui.ui index 092fa92..6bb6fc4 100644 --- a/app/SandboxSetup/beamerlocationgui.ui +++ b/app/SandboxSetup/beamerlocationgui.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>632</width> - <height>628</height> + <height>639</height> </rect> </property> <property name="windowTitle"> @@ -94,6 +94,35 @@ p, li { white-space: pre-wrap; } <bool>true</bool> </property> </widget> + <widget class="QLabel" name="lblSteps"> + <property name="geometry"> + <rect> + <x>416</x> + <y>20</y> + <width>101</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>0/0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + <widget class="QPushButton" name="btnRestart"> + <property name="geometry"> + <rect> + <x>490</x> + <y>330</y> + <width>89</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Restart</string> + </property> + </widget> </widget> <resources/> <connections/> diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 73af399..8a8b2bf 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -109,8 +109,8 @@ void CameraFocus::refreshFrame(){ cv::cvtColor(cannyGray, cannyRgb, CV_GRAY2BGR); if(!crc.empty()){ - cv::circle(rgbFromGray, cv::Point(crc[0].x, crc[0].y), crc[0].z, cv::Scalar(0,255,0), 2); - cv::circle(cannyRgb, cv::Point(crc[0].x, crc[0].y), crc[0].z, cv::Scalar(0,255,0), 2); + cv::circle(rgbFromGray, cv::Point(crc[0].x, crc[0].y), crc[0].z, cv::Scalar(0,255,0), 3); + cv::circle(cannyRgb, cv::Point(crc[0].x, crc[0].y), crc[0].z, cv::Scalar(0,255,0), 3); } QImage img = QImage((uchar *)rgbFromGray.data, (int)rgbFromGray.cols, (int)rgbFromGray.rows, static_cast<int>(rgbFromGray.step.buf[0]), QImage::Format_RGB888); diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 7d060c1..f96a754 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -9,6 +9,7 @@ CroppingMask::CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *pare setup = sandbox; mg = _mg; ui->setupUi(this); + ui->txtInstructions->setAlignment(Qt::AlignJustify); maskEdit = new MaskEdit(ui->frame->geometry()); ui->vLayout->addWidget(maskEdit, 1); diff --git a/app/SandboxSetup/croppingmask.ui b/app/SandboxSetup/croppingmask.ui index 3a09848..a1fb692 100644 --- a/app/SandboxSetup/croppingmask.ui +++ b/app/SandboxSetup/croppingmask.ui @@ -57,15 +57,18 @@ <string>Instructions :</string> </property> </widget> - <widget class="QTextEdit" name="textEdit"> + <widget class="QTextEdit" name="txtInstructions"> <property name="geometry"> <rect> - <x>60</x> - <y>400</y> - <width>441</width> - <height>121</height> + <x>40</x> + <y>390</y> + <width>561</width> + <height>91</height> </rect> </property> + <property name="readOnly"> + <bool>true</bool> + </property> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> diff --git a/app/SandboxSetup/initcamera.cpp b/app/SandboxSetup/initcamera.cpp index 4861aea..f1f3978 100644 --- a/app/SandboxSetup/initcamera.cpp +++ b/app/SandboxSetup/initcamera.cpp @@ -49,7 +49,7 @@ void InitCamera::setupCamera(){ } void InitCamera::setupReady(){ - emit sendNotif(); + emit sendNotif(0); } diff --git a/app/SandboxSetup/mainwindow.cpp b/app/SandboxSetup/mainwindow.cpp index 0f17b0d..0f3b4cc 100644 --- a/app/SandboxSetup/mainwindow.cpp +++ b/app/SandboxSetup/mainwindow.cpp @@ -60,7 +60,7 @@ void MainWindow::closeEvent(QCloseEvent *event){ QWidget::closeEvent(event); } -void MainWindow::receiveNotif(){ +void MainWindow::receiveNotif(int state){ // active app : InitCamera if( strcmp( applist.at(step)->metaObject()->className(), init->metaObject()->className() ) == 0 ){ @@ -69,7 +69,7 @@ void MainWindow::receiveNotif(){ } // active app : BeamerLocation else if( strcmp( applist.at(step)->metaObject()->className(), bl->metaObject()->className() ) == 0 ){ - ui->btnNext->setVisible(true); + ui->btnNext->setVisible(state); } // active app : SaveConfig else if( strcmp( applist.at(step)->metaObject()->className(), scfg->metaObject()->className() ) == 0 ){ diff --git a/app/SandboxSetup/mainwindow.h b/app/SandboxSetup/mainwindow.h index a1a86ed..d5d2de1 100644 --- a/app/SandboxSetup/mainwindow.h +++ b/app/SandboxSetup/mainwindow.h @@ -33,7 +33,7 @@ private slots: void on_btnPrev_clicked(); - void receiveNotif(); + void receiveNotif(int state); void on_btnFinish_clicked(); diff --git a/app/SandboxSetup/monitorgui.cpp b/app/SandboxSetup/monitorgui.cpp index 37d41d0..124b7dd 100644 --- a/app/SandboxSetup/monitorgui.cpp +++ b/app/SandboxSetup/monitorgui.cpp @@ -23,6 +23,7 @@ MonitorGui::MonitorGui(SandboxSetup *_setup, QWidget *parent) : loadResolutionsOf(screens[0]); showMonitorsScreenshot(screens[0]); } + ui->txtInstructions->setAlignment(Qt::AlignJustify); } MonitorGui::~MonitorGui() diff --git a/app/SandboxSetup/monitorgui.ui b/app/SandboxSetup/monitorgui.ui index 58ef531..7f9d0af 100644 --- a/app/SandboxSetup/monitorgui.ui +++ b/app/SandboxSetup/monitorgui.ui @@ -75,13 +75,13 @@ <bool>true</bool> </property> </widget> - <widget class="QTextEdit" name="textEdit"> + <widget class="QTextEdit" name="txtInstructions"> <property name="geometry"> <rect> <x>40</x> <y>290</y> - <width>481</width> - <height>121</height> + <width>551</width> + <height>101</height> </rect> </property> <property name="readOnly"> @@ -95,10 +95,22 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">You must choose the ouput matching your beamer. </p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Note :</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your screens must be in extended mode (as if you have a large desktop that covers all of your screens).</p></body></html></string> </property> </widget> + <widget class="QLabel" name="label_3"> + <property name="geometry"> + <rect> + <x>40</x> + <y>270</y> + <width>131</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Insctructions :</string> + </property> + </widget> </widget> <resources/> <connections/> diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp index f2a9a46..6f1a1a5 100644 --- a/app/SandboxSetup/projectiongui.cpp +++ b/app/SandboxSetup/projectiongui.cpp @@ -9,7 +9,7 @@ ProjectionGui::ProjectionGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *par mg = _mg; ui->setupUi(this); ui->lblFrame->setGeometry(0, 0, ui->fContainer->width(), ui->fContainer->height()); - + ui->txtInstructions->setAlignment(Qt::AlignJustify); blueScreen = new QtFullScreen(mg->getResolution(), true, this); frameTimer = new QTimer(this); diff --git a/app/SandboxSetup/projectiongui.ui b/app/SandboxSetup/projectiongui.ui index 8d5c9cb..46ab5c4 100644 --- a/app/SandboxSetup/projectiongui.ui +++ b/app/SandboxSetup/projectiongui.ui @@ -61,41 +61,60 @@ <string>Start</string> </property> </widget> - <widget class="QLabel" name="label"> + <widget class="QPushButton" name="btnStop"> + <property name="enabled"> + <bool>true</bool> + </property> <property name="geometry"> <rect> - <x>40</x> - <y>360</y> - <width>441</width> - <height>61</height> + <x>520</x> + <y>90</y> + <width>89</width> + <height>25</height> </rect> </property> <property name="text"> - <string>Project a blue screen on the previously selected output to help you setup your beamer manually</string> + <string>Stop</string> </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </widget> + <widget class="QTextEdit" name="txtInstructions"> + <property name="geometry"> + <rect> + <x>30</x> + <y>370</y> + <width>581</width> + <height>101</height> + </rect> </property> - <property name="wordWrap"> + <property name="readOnly"> <bool>true</bool> </property> - </widget> - <widget class="QPushButton" name="btnStop"> - <property name="enabled"> - <bool>true</bool> + <property name="html"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Project a blue screen on the previously selected output to help you setup your beamer and camera manually. Adjust the position and orientation of your beamer to project the blue frame in your sandbox. Then adjust the position and oritentation of your camera to capture the blue screen projected. Try to set your camera, so the camera's point of view above is mostly filled with the blue screen.</p></body></html></string> </property> + </widget> + <widget class="QLabel" name="label"> <property name="geometry"> <rect> - <x>520</x> - <y>90</y> - <width>89</width> - <height>25</height> + <x>30</x> + <y>350</y> + <width>91</width> + <height>17</height> </rect> </property> <property name="text"> - <string>Stop</string> + <string>Instructions :</string> </property> </widget> + <zorder>txtInstructions</zorder> + <zorder>fContainer</zorder> + <zorder>btnStart</zorder> + <zorder>btnStop</zorder> + <zorder>label</zorder> </widget> <resources/> <connections/> diff --git a/app/SandboxSetup/saveconfiggui.cpp b/app/SandboxSetup/saveconfiggui.cpp index fc4d33a..16f341c 100644 --- a/app/SandboxSetup/saveconfiggui.cpp +++ b/app/SandboxSetup/saveconfiggui.cpp @@ -28,5 +28,5 @@ void SaveConfigGui::saveConfig(){ } setup->getCamera()->stop(); ui->lblMessage->setText(QString(msg.c_str())); - emit sendNotif(); + emit sendNotif(0); } diff --git a/app/SandboxSetup/subapp.h b/app/SandboxSetup/subapp.h index 87be1c9..858f2c3 100644 --- a/app/SandboxSetup/subapp.h +++ b/app/SandboxSetup/subapp.h @@ -18,7 +18,7 @@ public: virtual void cancelRoutine(); signals: - void sendNotif(); + void sendNotif(int state); protected: bool endSuccess = false; diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index 72bdb57..e65277d 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -208,13 +208,13 @@ int LineLineIntersect( return (true); } - cv::Mat Beamer::editContrast(cv::Mat image, double contrast, int brightness){ cv::Mat new_image = cv::Mat::zeros( image.size(), image.type() ); double alpha = contrast; int beta = brightness; + // source : https://docs.opencv.org/2.4/doc/tutorials/core/basic_linear_transform/basic_linear_transform.html for( int y = 0; y < image.rows; y++ ) { for( int x = 0; x < image.cols; x++ ) { new_image.at<uchar>(y,x) = cv::saturate_cast<uchar>( alpha*image.at<uchar>(y,x) + beta ); -- GitLab