diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp index 9589cf87e5af6bbe8f2c6ac17dc2ebe9fd203712..aa7e0f25294dce429d0789b114762e971e022058 100644 --- a/app/SandboxSetup/beamerlocationgui.cpp +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -1,6 +1,15 @@ #include "beamerlocationgui.h" #include "ui_beamerlocationgui.h" +BeamerLocationGui::RefreshFrame::RefreshFrame(BeamerLocationGui *_routine) : QThread() { + routine = _routine; +} + +void BeamerLocationGui::RefreshFrame::run() { + routine->routineFrame(); +} + + BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent) : SubApp("Beamer location", "Error", parent), ui(new Ui::BeamerLocationGui) @@ -11,33 +20,27 @@ BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWid mg = _mg; winFullScreen = new QtFullScreen(mg->getResolution(), true, this); ui->setupUi(this); - + myThread = new RefreshFrame(this); timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, &BeamerLocationGui::routineFrame); - + connect(timer, &QTimer::timeout, this, &BeamerLocationGui::refreshRoutine); } BeamerLocationGui::~BeamerLocationGui() { delete timer; + delete myThread; delete winFullScreen; delete ui; } void BeamerLocationGui::valideRoutine(){ - - if(timer->isActive()) - timer->stop(); - + endRoutine(); beamer->setPosition( (cv::Point3f)beamer->approximatePosition(&bases, &directions) ); - winFullScreen->close(); endSuccess = true; } void BeamerLocationGui::cancelRoutine(){ - if(timer->isActive()) - timer->stop(); - winFullScreen->close(); + endRoutine(); endSuccess = false; } @@ -56,6 +59,10 @@ void BeamerLocationGui::closeEvent(QCloseEvent *e){ QWidget::closeEvent(e); } +void BeamerLocationGui::refreshRoutine(){ + myThread->start(); +} + void BeamerLocationGui::startRoutine(){ profil = beamer->getProfil(); @@ -65,8 +72,7 @@ void BeamerLocationGui::startRoutine(){ capturedPoints = std::vector<cv::Point3f>(); circle = std::vector<cv::Point3i>(); - if(!timer->isActive()) - timer->start(500); + timer->start(200); } @@ -92,9 +98,22 @@ void BeamerLocationGui::routineFrame(){ profil->getMinRadius(), profil->getMaxRadius() ); + // preview from the camera's POV + cv::Mat gray, frameDisplayed; + cv::cvtColor(rgb, gray, CV_BGR2GRAY); + gray = setup->getBeamer()->editContrast(gray, (double)profil->getContrast(), (double)profil->getBrightness()); + cv::cvtColor(gray, frameDisplayed, CV_GRAY2RGB); + if(!circle.empty()){ + cv::circle(frameDisplayed, cv::Point(circle[0].x, circle[0].y), circle[0].z, cv::Scalar(0,255,0), 3); + } + QImage img = QImage((uchar *)frameDisplayed.data, (int)frameDisplayed.cols, (int)frameDisplayed.rows, static_cast<int>(frameDisplayed.step.buf[0]), QImage::Format_RGB888); + QPixmap px = QPixmap::fromImage(img); + // Show black screen with cross cv::Mat frameImage = beamer->getCrossFrame(cross, capturedPoints.size()+1, beamer->MAX_LINEAR_LINE_POINTS, !circle.empty()); cv::cvtColor(frameImage, frameImage, CV_BGR2RGB); + + ui->lblFrame->setPixmap(px); winFullScreen->imShow(frameImage); } } @@ -124,8 +143,10 @@ void BeamerLocationGui::userValidePoint(){ void BeamerLocationGui::endRoutine(){ - if(timer->isActive()) timer->stop(); + myThread->exit(0); + myThread->wait(); + endSuccess = (bases.size() == beamer->MAX_LINEAR_LINE_POINTS && directions.size() == beamer->MAX_LINEAR_LINE_POINTS); diff --git a/app/SandboxSetup/beamerlocationgui.h b/app/SandboxSetup/beamerlocationgui.h index 7c1a6046b206e77277d1d9f7f734fb4af015c1a5..2cf6ede1d3245a776d9b275efdca11d4d8bde353 100644 --- a/app/SandboxSetup/beamerlocationgui.h +++ b/app/SandboxSetup/beamerlocationgui.h @@ -22,6 +22,7 @@ public: ~BeamerLocationGui(); void valideRoutine(); void cancelRoutine(); + void routineFrame(); protected: void closeEvent (QCloseEvent *event); @@ -33,6 +34,16 @@ private slots: void on_btnLock_clicked(); private: + class RefreshFrame : public QThread + { + public: + explicit RefreshFrame(BeamerLocationGui *routine); + void run(); + + private: + BeamerLocationGui *routine; + }; + Ui::BeamerLocationGui *ui; QtFullScreen *winFullScreen; SandboxSetup *setup; @@ -52,11 +63,12 @@ private: std::vector<cv::Point3i> circle; int stepCross = 0; QTimer *timer; + RefreshFrame *myThread; void startRoutine(); - void routineFrame(); void userValidePoint(); void endRoutine(); + void refreshRoutine(); }; #endif // BEAMERLOCATIONGUI_H diff --git a/app/SandboxSetup/beamerlocationgui.ui b/app/SandboxSetup/beamerlocationgui.ui index cfb41be0799fbbccf65aba9078a98d94d15ca731..b414ddd0629a944f7961faa9d516ec6fab6e64d3 100644 --- a/app/SandboxSetup/beamerlocationgui.ui +++ b/app/SandboxSetup/beamerlocationgui.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>530</width> - <height>355</height> + <width>632</width> + <height>628</height> </rect> </property> <property name="windowTitle"> @@ -17,9 +17,9 @@ <property name="geometry"> <rect> <x>220</x> - <y>300</y> - <width>89</width> - <height>25</height> + <y>570</y> + <width>131</width> + <height>51</height> </rect> </property> <property name="text"> @@ -30,7 +30,7 @@ <property name="geometry"> <rect> <x>40</x> - <y>40</y> + <y>340</y> <width>201</width> <height>17</height> </rect> @@ -42,9 +42,9 @@ <widget class="QTextEdit" name="txtInstructions"> <property name="geometry"> <rect> - <x>60</x> - <y>70</y> - <width>421</width> + <x>50</x> + <y>360</y> + <width>521</width> <height>181</height> </rect> </property> @@ -56,13 +56,42 @@ <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;">- A red corss is displayed from the selected output at step 2<br />- Match the position of the cross with your white target</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- When you are ready, press the button to validate a point</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- Repeat this process 3 times for each cross you see (there will be 3 different crosses)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> - A red corss is displayed from the selected output at step 2<br /> - Match the position of the cross with your white target</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> - When you are ready, press the button to validate a point</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> - Repeat this process 3 times for each cross you see (there will be 3 different crosses)</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;">For each point you validate, change the height of your target to not save the same position twice in the process.</p></body></html></string> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> - The cross will change from red to green when it detects the target.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> - For each point you validate, change the height of your target to not save the same position twice in the process.</p></body></html></string> + </property> + </widget> + <widget class="QLabel" name="label_2"> + <property name="geometry"> + <rect> + <x>40</x> + <y>20</y> + <width>201</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Camera :</string> + </property> + </widget> + <widget class="QLabel" name="lblFrame"> + <property name="geometry"> + <rect> + <x>90</x> + <y>60</y> + <width>431</width> + <height>251</height> + </rect> + </property> + <property name="text"> + <string/> + </property> + <property name="scaledContents"> + <bool>true</bool> </property> </widget> </widget> diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 44a768f1adc26489f19fcfd4c226b589999d12d1..49eeb61b71c340f611ad5f15354a18fc3ce40869 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -33,7 +33,7 @@ CameraFocus::~CameraFocus() { delete frameTimer; delete blackScreen; - myThread->quit(); + myThread->exit(0); myThread->wait(); delete myThread; delete ui; diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 031d65d80ea6f9229e9d5b81ac24bab9fab5a9c8..0409417b42a0169aa65d23616e3cf5f5125bb52e 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -27,6 +27,7 @@ CroppingMask::~CroppingMask() } void CroppingMask::valideRoutine(){ + timer->stop(); cv::Size s = setup->getCamera()->getDepthFrame().size(); cv::Point center(s.width / 2, s.height / 2); std::vector<cv::Point> rectPoints = getRectPoints(); @@ -38,7 +39,7 @@ void CroppingMask::valideRoutine(){ } void CroppingMask::cancelRoutine(){ - + timer->stop(); endSuccess = false; } @@ -58,7 +59,6 @@ void CroppingMask::showEvent(QShowEvent *event){ void CroppingMask::closeEvent(QCloseEvent *event){ QWidget::closeEvent(event); - timer->stop(); blueScreen->close(); } diff --git a/app/SandboxSetup/monitorgui.ui b/app/SandboxSetup/monitorgui.ui index f883eea2c8237de320f4cae11f45c3289bb394d7..58ef531033c67adbc66d80e9bddc78241166953e 100644 --- a/app/SandboxSetup/monitorgui.ui +++ b/app/SandboxSetup/monitorgui.ui @@ -18,12 +18,12 @@ <rect> <x>40</x> <y>40</y> - <width>101</width> + <width>191</width> <height>21</height> </rect> </property> <property name="text"> - <string>Choose output</string> + <string>Choose beamer's output</string> </property> </widget> <widget class="QComboBox" name="cbxOutputs"> @@ -31,7 +31,7 @@ <rect> <x>40</x> <y>70</y> - <width>141</width> + <width>181</width> <height>25</height> </rect> </property> diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index c1eed70c6c3f1384a13c7cd4e1e1edc5f13d3ac8..b1ed53c8f113cc4f3bb10062605a1bd9c6495f0d 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -114,10 +114,15 @@ std::vector<cv::Point2i> Beamer::getCrossList(){ cv::Mat Beamer::getCrossFrame(cv::Point projectedCross, int step, int max, bool circlesFound){ cv::Mat frameImage(resolution, CV_8UC3, cv::Scalar(0, 0, 0)); + cv::Scalar red = cv::Scalar(0, 0, 255); cv::Scalar color = (circlesFound) ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255); - cv::line(frameImage, cv::Point(projectedCross.x, 0), cv::Point(projectedCross.x, frameImage.rows - 1), color, 4); - cv::line(frameImage, cv::Point(0, projectedCross.y), cv::Point(frameImage.cols - 1, projectedCross.y), color, 4); + cv::line(frameImage, cv::Point(projectedCross.x, 0), cv::Point(projectedCross.x, frameImage.rows - 1), red, 4); + cv::line(frameImage, cv::Point(0, projectedCross.y), cv::Point(frameImage.cols - 1, projectedCross.y), red, 4); + cv::rectangle( frameImage, + cv::Point(getWidth()/2 -30, getHeight()/2 -20), + cv::Point(getWidth()/2 -10, getHeight()/2), + color, cv::FILLED, 8, 0 ); cv::putText( frameImage, std::to_string(step) + "/" + std::to_string(max), cv::Point( getWidth()/2, getHeight()/2 ),