From 2c7f31d6399d28563f4161da9a89bd772030d1f5 Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Thu, 6 Aug 2020 19:12:08 +0200 Subject: [PATCH] cleaning --- app/SandboxSetup/SandboxSetup.pro | 24 ++--- .../{camerafocus.cpp => camerafocusgui.cpp} | 68 ++++++------ .../{camerafocus.h => camerafocusgui.h} | 20 ++-- .../{camerafocus.ui => camerafocusgui.ui} | 102 +++++++++--------- .../{croppingmask.cpp => croppingmaskgui.cpp} | 38 +++---- .../{croppingmask.h => croppingmaskgui.h} | 14 +-- .../{croppingmask.ui => croppingmaskgui.ui} | 4 +- .../{initcamera.cpp => initcameragui.cpp} | 20 ++-- .../{initcamera.h => initcameragui.h} | 16 +-- .../{initcamera.ui => initcameragui.ui} | 4 +- app/SandboxSetup/mainwindow.cpp | 6 +- app/SandboxSetup/mainwindow.h | 12 +-- app/SandboxSetup/monitorgui.cpp | 4 +- inc/beamer.h | 1 - inc/projection.h | 12 ++- inc/sandboxConfig.h | 2 +- inc/sandboxSetup.h | 4 +- src/components/beamer.cpp | 36 ++----- src/components/projection.cpp | 10 +- src/lib/sandboxSetup.cpp | 24 +++-- src/tools/sandboxConfig.cpp | 7 +- 21 files changed, 214 insertions(+), 214 deletions(-) rename app/SandboxSetup/{camerafocus.cpp => camerafocusgui.cpp} (81%) rename app/SandboxSetup/{camerafocus.h => camerafocusgui.h} (82%) rename app/SandboxSetup/{camerafocus.ui => camerafocusgui.ui} (97%) rename app/SandboxSetup/{croppingmask.cpp => croppingmaskgui.cpp} (77%) rename app/SandboxSetup/{croppingmask.h => croppingmaskgui.h} (79%) rename app/SandboxSetup/{croppingmask.ui => croppingmaskgui.ui} (97%) rename app/SandboxSetup/{initcamera.cpp => initcameragui.cpp} (67%) rename app/SandboxSetup/{initcamera.h => initcameragui.h} (67%) rename app/SandboxSetup/{initcamera.ui => initcameragui.ui} (88%) diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index f734889..1aee35e 100644 --- a/app/SandboxSetup/SandboxSetup.pro +++ b/app/SandboxSetup/SandboxSetup.pro @@ -27,40 +27,40 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ monitorgui.cpp \ - camerafocus.cpp \ - croppingmask.cpp \ maskedit.cpp \ projectiongui.cpp \ qtfullscreen.cpp \ beamerlocationgui.cpp \ mainwindow.cpp \ subapp.cpp \ - initcamera.cpp \ - saveconfiggui.cpp + saveconfiggui.cpp \ + initcameragui.cpp \ + camerafocusgui.cpp \ + croppingmaskgui.cpp HEADERS += \ monitorgui.h \ - camerafocus.h \ - croppingmask.h \ maskedit.h \ projectiongui.h \ qtfullscreen.h \ beamerlocationgui.h \ mainwindow.h \ subapp.h \ - initcamera.h \ - saveconfiggui.h + saveconfiggui.h \ + camerafocusgui.h \ + croppingmaskgui.h \ + initcameragui.h FORMS += \ monitorgui.ui \ - camerafocus.ui \ - croppingmask.ui \ maskedit.ui \ projectiongui.ui \ beamerlocationgui.ui \ mainwindow.ui \ - initcamera.ui \ - saveconfiggui.ui + saveconfiggui.ui \ + camerafocusgui.ui \ + croppingmaskgui.ui \ + initcameragui.ui INCLUDEPATH += ../../inc diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocusgui.cpp similarity index 81% rename from app/SandboxSetup/camerafocus.cpp rename to app/SandboxSetup/camerafocusgui.cpp index c5e45a3..8634996 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocusgui.cpp @@ -1,20 +1,20 @@ -#include "camerafocus.h" -#include "ui_camerafocus.h" +#include "camerafocusgui.h" +#include "ui_camerafocusgui.h" -CameraFocus::RefreshFrame::RefreshFrame(CameraFocus *_camera) : QThread() { +CameraFocusGui::RefreshFrame::RefreshFrame(CameraFocusGui *_camera) : QThread() { camera = _camera; } -void CameraFocus::RefreshFrame::run() { +void CameraFocusGui::RefreshFrame::run() { camera->refreshFrame(); } -CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : +CameraFocusGui::CameraFocusGui(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : SubApp("Camera focus", "Error", parent), - ui(new Ui::CameraFocus) + ui(new Ui::CameraFocusGui) { ui->setupUi(this); setup = sandbox; @@ -24,10 +24,10 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent setup->loadFrameProcessProfil(); frameTimer = new QTimer(this); - connect(frameTimer, &QTimer::timeout, this, &CameraFocus::startCapture); + connect(frameTimer, &QTimer::timeout, this, &CameraFocusGui::startCapture); } -CameraFocus::~CameraFocus() +CameraFocusGui::~CameraFocusGui() { delete frameTimer; delete blackScreen; @@ -37,7 +37,7 @@ CameraFocus::~CameraFocus() delete ui; } -void CameraFocus::showEvent(QShowEvent *event){ +void CameraFocusGui::showEvent(QShowEvent *event){ QWidget::showEvent(event); initCameraParams(); @@ -49,7 +49,7 @@ void CameraFocus::showEvent(QShowEvent *event){ frameTimer->start(100); } -void CameraFocus::closeEvent(QCloseEvent *event){ +void CameraFocusGui::closeEvent(QCloseEvent *event){ frameTimer->stop(); blackScreen->close(); @@ -58,21 +58,21 @@ void CameraFocus::closeEvent(QCloseEvent *event){ // TODO : override "checkRoutine" to ensure the profil makes sense -void CameraFocus::valideRoutine(){ +void CameraFocusGui::valideRoutine(){ endSuccess = true; } -void CameraFocus::cancelRoutine(){ +void CameraFocusGui::cancelRoutine(){ endSuccess = false; } -void CameraFocus::startCapture(){ +void CameraFocusGui::startCapture(){ myThread->start(); } -void CameraFocus::refreshFrame(){ +void CameraFocusGui::refreshFrame(){ setup->getCamera()->capture(); FrameProcessProfil *profil = setup->getBeamer()->getProfil(); @@ -121,13 +121,13 @@ void CameraFocus::refreshFrame(){ } -void CameraFocus::initCameraParams(){ +void CameraFocusGui::initCameraParams(){ FrameProcessProfil *profil = setup->getBeamer()->getProfil(); loadProfil(profil, &defaultProfil); } -void CameraFocus::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved){ +void CameraFocusGui::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved){ // save profil profilSaved->setContrast(profilLoaded->getContrast()); @@ -167,97 +167,97 @@ void CameraFocus::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfi } -void CameraFocus::on_btnReset_clicked() +void CameraFocusGui::on_btnReset_clicked() { loadProfil(&defaultProfil, setup->getBeamer()-> getProfil()); } -void CameraFocus::on_sldContrast_sliderMoved(int position) +void CameraFocusGui::on_sldContrast_sliderMoved(int position) { double val = position/100.0; setup->getBeamer()->getProfil()->setContrast(val); ui->sbxContrast->setValue(val); } -void CameraFocus::on_sbxContrast_valueChanged(double arg1) +void CameraFocusGui::on_sbxContrast_valueChanged(double arg1) { setup->getBeamer()->getProfil()->setContrast(arg1); ui->sldContrast->setValue((int)(arg1*100)); } -void CameraFocus::on_sldBrightness_sliderMoved(int position) +void CameraFocusGui::on_sldBrightness_sliderMoved(int position) { setup->getBeamer()->getProfil()->setBrightness(position); ui->sbxBrightness->setValue(position); } -void CameraFocus::on_sbxBrightness_valueChanged(int arg1) +void CameraFocusGui::on_sbxBrightness_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setBrightness(arg1); ui->sldBrightness->setValue(arg1); } -void CameraFocus::on_sldMinDistance_sliderMoved(int position) +void CameraFocusGui::on_sldMinDistance_sliderMoved(int position) { setup->getBeamer()->getProfil()->setMinDistance((uint)position); ui->sbxMinDistance->setValue(position); } -void CameraFocus::on_sbxMinDistance_valueChanged(int arg1) +void CameraFocusGui::on_sbxMinDistance_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setMinDistance((uint)arg1); ui->sldMinDistance->setValue(arg1); } -void CameraFocus::on_sldCannyThreshold_sliderMoved(int position) +void CameraFocusGui::on_sldCannyThreshold_sliderMoved(int position) { setup->getBeamer()->getProfil()->setCannyEdgeThreshold((uint)position); ui->sbxCannyThreshold->setValue(position); } -void CameraFocus::on_sbxCannyThreshold_valueChanged(int arg1) +void CameraFocusGui::on_sbxCannyThreshold_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setCannyEdgeThreshold((uint)arg1); ui->sldCannyThreshold->setValue(arg1); } -void CameraFocus::on_sldAccThreshold_sliderMoved(int position) +void CameraFocusGui::on_sldAccThreshold_sliderMoved(int position) { setup->getBeamer()->getProfil()->setHoughAccThreshold((uint)position); ui->sbxAccThreshold->setValue(position); } -void CameraFocus::on_sbxAccThreshold_valueChanged(int arg1) +void CameraFocusGui::on_sbxAccThreshold_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setHoughAccThreshold((uint)arg1); ui->sldAccThreshold->setValue(arg1); } -void CameraFocus::on_sldMinRadius_sliderMoved(int position) +void CameraFocusGui::on_sldMinRadius_sliderMoved(int position) { setup->getBeamer()->getProfil()->setMinRadius((uint)position); ui->sbxMinRadius->setValue(position); } -void CameraFocus::on_sbxMinRadius_valueChanged(int arg1) +void CameraFocusGui::on_sbxMinRadius_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setMinRadius((uint)arg1); ui->sldMinRadius->setValue(arg1); } -void CameraFocus::on_sldMaxRadius_sliderMoved(int position) +void CameraFocusGui::on_sldMaxRadius_sliderMoved(int position) { setup->getBeamer()->getProfil()->setMaxRadius((uint)position); ui->sbxMaxRadius->setValue(position); } -void CameraFocus::on_sbxMaxRadius_valueChanged(int arg1) +void CameraFocusGui::on_sbxMaxRadius_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setMaxRadius((uint)arg1); ui->sldMaxRadius->setValue(arg1); } -void CameraFocus::on_ckbxTargetSize_clicked(bool checked) +void CameraFocusGui::on_ckbxTargetSize_clicked(bool checked) { std::vector<QWidget *> lst = { ui->lblMinRadius, ui->sldMinRadius, ui->sbxMinRadius, ui->lblMaxRadius, ui->sldMaxRadius, ui->sbxMaxRadius }; @@ -272,7 +272,7 @@ void CameraFocus::on_ckbxTargetSize_clicked(bool checked) } -void CameraFocus::switchMode(bool isRestricted){ +void CameraFocusGui::switchMode(bool isRestricted){ if(isRestricted){ ui->sldContrast->setMaximum(500); @@ -301,7 +301,7 @@ void CameraFocus::switchMode(bool isRestricted){ } } -void CameraFocus::on_ckbxAdvanced_clicked(bool checked) +void CameraFocusGui::on_ckbxAdvanced_clicked(bool checked) { switchMode(!checked); } diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocusgui.h similarity index 82% rename from app/SandboxSetup/camerafocus.h rename to app/SandboxSetup/camerafocusgui.h index d756c7f..25d6a15 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocusgui.h @@ -1,5 +1,5 @@ -#ifndef CAMERAFOCUS_H -#define CAMERAFOCUS_H +#ifndef CAMERAFOCUSGUI_H +#define CAMERAFOCUSGUI_H #include <QDialog> #include <QTimer> @@ -11,17 +11,17 @@ #include "subapp.h" namespace Ui { -class CameraFocus; +class CameraFocusGui; } -class CameraFocus : public SubApp +class CameraFocusGui : public SubApp { Q_OBJECT public: - explicit CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); - ~CameraFocus(); + explicit CameraFocusGui(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); + ~CameraFocusGui(); void refreshFrame(); void valideRoutine(); void cancelRoutine(); @@ -71,14 +71,14 @@ private: class RefreshFrame : public QThread { public: - explicit RefreshFrame(CameraFocus *camera); + explicit RefreshFrame(CameraFocusGui *camera); void run(); private: - CameraFocus *camera; + CameraFocusGui *camera; }; - Ui::CameraFocus *ui; + Ui::CameraFocusGui *ui; SandboxSetup *setup; MonitorGui *mg; RefreshFrame *myThread; @@ -93,4 +93,4 @@ private: }; -#endif // CAMERAFOCUS_H +#endif // CAMERAFOCUSGUI_H diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocusgui.ui similarity index 97% rename from app/SandboxSetup/camerafocus.ui rename to app/SandboxSetup/camerafocusgui.ui index 319f8f5..ac84b6f 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocusgui.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>CameraFocus</class> - <widget class="QWidget" name="CameraFocus"> + <class>CameraFocusGui</class> + <widget class="QWidget" name="CameraFocusGui"> <property name="geometry"> <rect> <x>0</x> @@ -106,22 +106,6 @@ </rect> </property> <layout class="QGridLayout" name="glytParams"> - <item row="3" column="1"> - <widget class="QSlider" name="sldMinDistance"> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>100</number> - </property> - <property name="value"> - <number>15</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> <item row="2" column="2"> <widget class="QSpinBox" name="sbxBrightness"> <property name="minimum"> @@ -142,7 +126,7 @@ </property> </widget> </item> - <item row="7" column="2"> + <item row="8" column="2"> <widget class="QSpinBox" name="sbxMinRadius"> <property name="enabled"> <bool>false</bool> @@ -165,7 +149,7 @@ </property> </widget> </item> - <item row="8" column="2"> + <item row="9" column="2"> <widget class="QSpinBox" name="sbxMaxRadius"> <property name="enabled"> <bool>false</bool> @@ -188,7 +172,7 @@ </property> </widget> </item> - <item row="7" column="0"> + <item row="8" column="0"> <widget class="QLabel" name="lblMinRadius"> <property name="enabled"> <bool>false</bool> @@ -205,7 +189,7 @@ </property> </widget> </item> - <item row="7" column="1"> + <item row="8" column="1"> <widget class="QSlider" name="sldMinRadius"> <property name="enabled"> <bool>false</bool> @@ -224,19 +208,6 @@ </property> </widget> </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Minimum distance between circles's center (% of the camera's width)</string> - </property> - <property name="textFormat"> - <enum>Qt::AutoText</enum> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> <item row="4" column="2"> <widget class="QSpinBox" name="sbxCannyThreshold"> <property name="maximum"> @@ -263,20 +234,7 @@ </property> </widget> </item> - <item row="3" column="2"> - <widget class="QSpinBox" name="sbxMinDistance"> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>100</number> - </property> - <property name="value"> - <number>15</number> - </property> - </widget> - </item> - <item row="8" column="0"> + <item row="9" column="0"> <widget class="QLabel" name="lblMaxRadius"> <property name="enabled"> <bool>false</bool> @@ -354,7 +312,7 @@ </property> </widget> </item> - <item row="8" column="1"> + <item row="9" column="1"> <widget class="QSlider" name="sldMaxRadius"> <property name="enabled"> <bool>false</bool> @@ -373,7 +331,7 @@ </property> </widget> </item> - <item row="6" column="0"> + <item row="7" column="0"> <widget class="QCheckBox" name="ckbxTargetSize"> <property name="text"> <string>Target's size known</string> @@ -387,6 +345,48 @@ </property> </widget> </item> + <item row="6" column="1"> + <widget class="QSlider" name="sldMinDistance"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="value"> + <number>15</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="6" column="2"> + <widget class="QSpinBox" name="sbxMinDistance"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="value"> + <number>15</number> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Minimum distance between circles's center (% of the camera's width)</string> + </property> + <property name="textFormat"> + <enum>Qt::AutoText</enum> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> </widget> diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmaskgui.cpp similarity index 77% rename from app/SandboxSetup/croppingmask.cpp rename to app/SandboxSetup/croppingmaskgui.cpp index 9efd457..d9be67f 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmaskgui.cpp @@ -1,9 +1,9 @@ -#include "croppingmask.h" -#include "ui_croppingmask.h" +#include "croppingmaskgui.h" +#include "ui_croppingmaskgui.h" -CroppingMask::CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : +CroppingMaskGui::CroppingMaskGui(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : SubApp("Cropping mask", "Error", parent), - ui(new Ui::CroppingMask) + ui(new Ui::CroppingMaskGui) { setup = sandbox; @@ -16,38 +16,38 @@ CroppingMask::CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *pare blueScreen = new QtFullScreen(mg->getResolution(), true, this); timer = new QTimer(this); - connect(timer, &QTimer::timeout, this, &CroppingMask::refreshFrame); + connect(timer, &QTimer::timeout, this, &CroppingMaskGui::refreshFrame); } -CroppingMask::~CroppingMask() +CroppingMaskGui::~CroppingMaskGui() { delete blueScreen; delete maskEdit; delete ui; } -void CroppingMask::valideRoutine(){ +void CroppingMaskGui::valideRoutine(){ timer->stop(); setup->getCamera()->capture(); std::vector<cv::Point> rectPoints = getRectPoints(); cv::Mat depthFrame = setup->getCamera()->getDepthFrame(); - setup->setupCroppingMask(rectPoints); + setup->setupCroppingMask(rectPoints, rectPoints[0]); cv::Rect mask = setup->getCamera()->getCroppingMask(); cv::Point2i centerProjection = cv::Point2i(mask.width/2, mask.height/2); - setup->setupAdjustMatrix(rectPoints, centerProjection); + setup->setupAdjustMatrix(rectPoints, cv::Point2i(0,0)); setup->getProjection()->setDistanceTopSandbox(depthFrame.at<float>(centerProjection)); endSuccess = true; } -void CroppingMask::cancelRoutine(){ +void CroppingMaskGui::cancelRoutine(){ timer->stop(); endSuccess = false; } -void CroppingMask::showEvent(QShowEvent *event){ +void CroppingMaskGui::showEvent(QShowEvent *event){ QWidget::showEvent(event); // show blue screen @@ -61,12 +61,12 @@ void CroppingMask::showEvent(QShowEvent *event){ timer->start(100); } -void CroppingMask::closeEvent(QCloseEvent *event){ +void CroppingMaskGui::closeEvent(QCloseEvent *event){ QWidget::closeEvent(event); blueScreen->close(); } -void CroppingMask::init(){ +void CroppingMaskGui::init(){ setup->getCamera()->capture(); cameraColoredFrame = setup->getCamera()->getColorFrame(); @@ -75,12 +75,14 @@ void CroppingMask::init(){ if(rectPoints.empty()){ if(!setup->loadCroppingMaskAndAdjustingMatrix()){ cv::Rect mask = setup->getCamera()->getCroppingMask(); + cv::Point2i centerRotation = cv::Point2i(mask.x, mask.y); + double angle = setup->getProjection()->getAngleRotation(); std::vector<cv::Point2i> pts = { cv::Point2i(mask.x, mask.y), cv::Point2i(mask.x, mask.y+mask.height), cv::Point2i(mask.x+mask.width, mask.y+mask.height), cv::Point2i(mask.x+mask.width, mask.y) }; for(cv::Point2i pt : pts){ - loadedMask.push_back(setup->getProjection()->revertRotatePixel(pt)); + loadedMask.push_back(setup->getProjection()->revertRotatePixel(centerRotation, angle, pt)); } rectPoints = loadedMask; } @@ -96,13 +98,13 @@ void CroppingMask::init(){ maskEdit->updateFrame(&cameraColoredFrame, &rectPoints); } -void CroppingMask::refreshFrame(){ +void CroppingMaskGui::refreshFrame(){ setup->getCamera()->capture(); cameraColoredFrame = setup->getCamera()->getColorFrame(); maskEdit->updateFrame(&cameraColoredFrame); } -bool CroppingMask::maskValideInFrame(cv::Mat_<cv::Vec3b> *rgb){ +bool CroppingMaskGui::maskValideInFrame(cv::Mat_<cv::Vec3b> *rgb){ if(rectPoints.empty()) return false; @@ -119,7 +121,7 @@ bool CroppingMask::maskValideInFrame(cv::Mat_<cv::Vec3b> *rgb){ } -void CroppingMask::on_btnClear_clicked() +void CroppingMaskGui::on_btnClear_clicked() { if(cameraColoredFrame.size().height != 0 && cameraColoredFrame.size().width != 0){ float y = cameraColoredFrame.size().height; @@ -129,7 +131,7 @@ void CroppingMask::on_btnClear_clicked() } } -void CroppingMask::on_btnReset_clicked() +void CroppingMaskGui::on_btnReset_clicked() { if(!loadedMask.empty()){ rectPoints = loadedMask; diff --git a/app/SandboxSetup/croppingmask.h b/app/SandboxSetup/croppingmaskgui.h similarity index 79% rename from app/SandboxSetup/croppingmask.h rename to app/SandboxSetup/croppingmaskgui.h index 564ec29..d9c2d4b 100644 --- a/app/SandboxSetup/croppingmask.h +++ b/app/SandboxSetup/croppingmaskgui.h @@ -1,5 +1,5 @@ -#ifndef CROPPINGMASK_H -#define CROPPINGMASK_H +#ifndef CROPPINGMASKGUI_H +#define CROPPINGMASKGUI_H #include <QDialog> #include <QTimer> @@ -11,16 +11,16 @@ #include "subapp.h" namespace Ui { -class CroppingMask; +class CroppingMaskGui; } -class CroppingMask : public SubApp +class CroppingMaskGui : public SubApp { Q_OBJECT public: - explicit CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); - ~CroppingMask(); + explicit CroppingMaskGui(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); + ~CroppingMaskGui(); std::vector<cv::Point2i> getRectPoints(){ return rectPoints; }; void valideRoutine(); void cancelRoutine(); @@ -35,7 +35,7 @@ private slots: void on_btnReset_clicked(); private: - Ui::CroppingMask *ui; + Ui::CroppingMaskGui *ui; SandboxSetup *setup; std::vector<cv::Point2i> rectPoints; std::vector<cv::Point2i> loadedMask; diff --git a/app/SandboxSetup/croppingmask.ui b/app/SandboxSetup/croppingmaskgui.ui similarity index 97% rename from app/SandboxSetup/croppingmask.ui rename to app/SandboxSetup/croppingmaskgui.ui index f7d7133..f478842 100644 --- a/app/SandboxSetup/croppingmask.ui +++ b/app/SandboxSetup/croppingmaskgui.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>CroppingMask</class> - <widget class="QWidget" name="CroppingMask"> + <class>CroppingMaskGui</class> + <widget class="QWidget" name="CroppingMaskGui"> <property name="geometry"> <rect> <x>0</x> diff --git a/app/SandboxSetup/initcamera.cpp b/app/SandboxSetup/initcameragui.cpp similarity index 67% rename from app/SandboxSetup/initcamera.cpp rename to app/SandboxSetup/initcameragui.cpp index 79ee3a6..7b06f0d 100644 --- a/app/SandboxSetup/initcamera.cpp +++ b/app/SandboxSetup/initcameragui.cpp @@ -1,5 +1,5 @@ -#include "initcamera.h" -#include "ui_initcamera.h" +#include "initcameragui.h" +#include "ui_initcameragui.h" @@ -16,20 +16,20 @@ void CameraStartThread::run() { -InitCamera::InitCamera(SandboxSetup *_setup, QWidget *parent) : +InitCameraGui::InitCameraGui(SandboxSetup *_setup, QWidget *parent) : SubApp("Initialize configuration", "Error", parent), - ui(new Ui::InitCamera) + ui(new Ui::InitCameraGui) { setup = _setup; ui->setupUi(this); ui->label->setText(QString("Initializing device...")); workerThread = new CameraStartThread(setup->getCamera()); - connect(workerThread, &CameraStartThread::setupReady, this, &InitCamera::setupReady); + connect(workerThread, &CameraStartThread::setupReady, this, &InitCameraGui::setupReady); connect(workerThread, &CameraStartThread::finished, workerThread, &QObject::deleteLater); } -InitCamera::~InitCamera() +InitCameraGui::~InitCameraGui() { workerThread->quit(); workerThread->wait(); @@ -37,18 +37,18 @@ InitCamera::~InitCamera() delete ui; } -void InitCamera::showEvent(QShowEvent *event){ +void InitCameraGui::showEvent(QShowEvent *event){ QWidget::showEvent(event); - QTimer::singleShot(10, this, &InitCamera::setupCamera); + QTimer::singleShot(10, this, &InitCameraGui::setupCamera); } -void InitCamera::setupCamera(){ +void InitCameraGui::setupCamera(){ workerThread->start(); } -void InitCamera::setupReady(int err){ +void InitCameraGui::setupReady(int err){ if(err){ QString msg = "No device found"; ui->label->setText(msg); diff --git a/app/SandboxSetup/initcamera.h b/app/SandboxSetup/initcameragui.h similarity index 67% rename from app/SandboxSetup/initcamera.h rename to app/SandboxSetup/initcameragui.h index 1ffe6d7..9724fb6 100644 --- a/app/SandboxSetup/initcamera.h +++ b/app/SandboxSetup/initcameragui.h @@ -1,5 +1,5 @@ -#ifndef INITCAMERA_H -#define INITCAMERA_H +#ifndef INITCAMERAGUI_H +#define INITCAMERAGUI_H #include <QWidget> #include <QTimer> @@ -8,7 +8,7 @@ #include <sandboxSetup.h> namespace Ui { -class InitCamera; +class InitCameraGui; } @@ -29,19 +29,19 @@ private: -class InitCamera : public SubApp +class InitCameraGui : public SubApp { Q_OBJECT public: - explicit InitCamera(SandboxSetup *_setup, QWidget *parent = 0); - ~InitCamera(); + explicit InitCameraGui(SandboxSetup *_setup, QWidget *parent = 0); + ~InitCameraGui(); protected: void showEvent(QShowEvent *event); private: - Ui::InitCamera *ui; + Ui::InitCameraGui *ui; SandboxSetup *setup; CameraStartThread *workerThread; @@ -49,4 +49,4 @@ private: void setupReady(int err); }; -#endif // INITCAMERA_H +#endif // INITCAMERAGUI_H diff --git a/app/SandboxSetup/initcamera.ui b/app/SandboxSetup/initcameragui.ui similarity index 88% rename from app/SandboxSetup/initcamera.ui rename to app/SandboxSetup/initcameragui.ui index a30f0bd..5dad9e9 100644 --- a/app/SandboxSetup/initcamera.ui +++ b/app/SandboxSetup/initcameragui.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>InitCamera</class> - <widget class="QWidget" name="InitCamera"> + <class>InitCameraGui</class> + <widget class="QWidget" name="InitCameraGui"> <property name="geometry"> <rect> <x>0</x> diff --git a/app/SandboxSetup/mainwindow.cpp b/app/SandboxSetup/mainwindow.cpp index c2fb74f..69fa475 100644 --- a/app/SandboxSetup/mainwindow.cpp +++ b/app/SandboxSetup/mainwindow.cpp @@ -12,11 +12,11 @@ MainWindow::MainWindow(QWidget *parent) : ui->btnFinish->setVisible(false); setup = new SandboxSetup; - init = new InitCamera(setup); + init = new InitCameraGui(setup); mg = new MonitorGui(setup); pg = new ProjectionGui(setup, mg); - cf = new CameraFocus(setup, mg); - cm = new CroppingMask(setup, mg); + cf = new CameraFocusGui(setup, mg); + cm = new CroppingMaskGui(setup, mg); bl = new BeamerLocationGui(setup, mg); scfg = new SaveConfigGui(setup); diff --git a/app/SandboxSetup/mainwindow.h b/app/SandboxSetup/mainwindow.h index d5d2de1..2ef12de 100644 --- a/app/SandboxSetup/mainwindow.h +++ b/app/SandboxSetup/mainwindow.h @@ -8,12 +8,12 @@ #include "subapp.h" #include "monitorgui.h" -#include "camerafocus.h" -#include "croppingmask.h" +#include "camerafocusgui.h" +#include "croppingmaskgui.h" #include "projectiongui.h" #include "qtfullscreen.h" #include "beamerlocationgui.h" -#include "initcamera.h" +#include "initcameragui.h" #include "saveconfiggui.h" namespace Ui { @@ -44,11 +44,11 @@ protected: private: Ui::MainWindow *ui; SandboxSetup *setup; - InitCamera *init; + InitCameraGui *init; MonitorGui *mg; ProjectionGui *pg; - CameraFocus *cf; - CroppingMask *cm; + CameraFocusGui *cf; + CroppingMaskGui *cm; BeamerLocationGui *bl; SaveConfigGui *scfg; int step = 0; diff --git a/app/SandboxSetup/monitorgui.cpp b/app/SandboxSetup/monitorgui.cpp index 3247aac..0f427a4 100644 --- a/app/SandboxSetup/monitorgui.cpp +++ b/app/SandboxSetup/monitorgui.cpp @@ -89,10 +89,12 @@ void MonitorGui::initMonitorMap(){ XRRScreenResources *screen = XRRGetScreenResources (dp, DefaultRootWindow(dp)); // 4 display ports + // physical caracteristics ? for(int i=0; i<screen->ncrtc; i++){ XRRCrtcInfo *info = XRRGetCrtcInfo (dp, screen, screen->crtcs[i]); - // 2 display port ON + // 2 display port ON (main monitor + beamer) + // display connected with modes vs display unconnected with no modes ? for(int j=0; j<info->noutput; j++){ XRROutputInfo *output = XRRGetOutputInfo(dp, screen, info->outputs[j]); diff --git a/inc/beamer.h b/inc/beamer.h index e1395a5..b881f12 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -17,7 +17,6 @@ class Beamer{ ~Beamer(); const unsigned int MAX_LINEAR_LINE_POINTS = 3; //number of point to calculate 1 vector - const double LINEAR_REGRESSION_FACT = -20.0; // used for linear regression cv::Point3f getPosition(){ return beamerPosition; }; void setPosition(cv::Point3f pos){ beamerPosition = pos; }; diff --git a/inc/projection.h b/inc/projection.h index 7f96dbc..bfa8670 100644 --- a/inc/projection.h +++ b/inc/projection.h @@ -8,6 +8,8 @@ class Projection{ private: cv::Mat_<float> adjustingMatrix; + // based angle to find adjustingMatrix + double angleRotation = 0.0; float distanceTopSandbox; // resized depth frame to dst resolution @@ -32,13 +34,15 @@ class Projection{ public: Projection(); - void setAdjustingMatrix(cv::Mat_<float> matrix){ adjustingMatrix = matrix; } - cv::Mat_<float> getAdjustingMatrix(){ return adjustingMatrix; } + void setAdjustingMatrix(cv::Mat_<float> matrix){ adjustingMatrix = matrix; }; + cv::Mat_<float> getAdjustingMatrix(){ return adjustingMatrix; }; + void setAngleRotation(double angle){ angleRotation = angle; }; + double getAngleRotation(){ return angleRotation; }; void setDistanceTopSandbox(float dist){ distanceTopSandbox = dist; }; float getDistanceTopSandbox(){ return distanceTopSandbox; }; - cv::Point2i rotatePixel(cv::Point2i pixel); - cv::Point2i revertRotatePixel(cv::Point2i pixel); + cv::Point2i rotatePixel(cv::Point2i center, double angle, cv::Point2i pixel); + cv::Point2i revertRotatePixel(cv::Point2i center, double angle, cv::Point2i pixel); void adjustFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Vec3b> &src, cv::Mat_<cv::Vec3b> &dst, Camera *camera, cv::Point3f beamer_pos); void printAdjustingMatrix(); diff --git a/inc/sandboxConfig.h b/inc/sandboxConfig.h index 4dae003..0fc9b23 100644 --- a/inc/sandboxConfig.h +++ b/inc/sandboxConfig.h @@ -19,7 +19,7 @@ class SandboxConfig{ SandboxConfig(){}; public: - static int saveAdjustingMatrixInto(char *path, cv::Mat_<float> matrix); + static int saveAdjustingMatrixInto(char *path, cv::Mat_<float> matrix, double angle); static int saveDistanceToSandboxTopInto(char *path, float distance); static int saveCroppingMaskInto(char *path, cv::Rect mask); static int saveBeamerPositionInto(char *path, cv::Point3f position); diff --git a/inc/sandboxSetup.h b/inc/sandboxSetup.h index 2544769..5449a2a 100644 --- a/inc/sandboxSetup.h +++ b/inc/sandboxSetup.h @@ -10,10 +10,12 @@ class SandboxSetup{ private: char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml"; + double rotation_angle = 0.0; Projection *projection; Camera *camera; Beamer *beamer; + double getAngle(std::vector<cv::Point2i> rectPoints); double toDegrees(double radians); public: @@ -36,7 +38,7 @@ class SandboxSetup{ // edit variables of config => not persistant void setupAdjustMatrix(std::vector<cv::Point2i> rectPoints, cv::Point2i center); - void setupCroppingMask(std::vector<cv::Point2i> rectPoints); + void setupCroppingMask(std::vector<cv::Point2i> rectPoints, cv::Point2i center); }; #endif diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index 835c36d..f1eefbe 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -51,7 +51,7 @@ cv::Mat Beamer::editContrast(cv::Mat image, double contrast, int brightness){ return new_image; } - +// TODO : modifier pour avoir une matrice gray_scale en param à la place de rgb std::vector<cv::Point3i> Beamer::findCircles(cv::Mat &rgb, double contrast, int brightness, double centersMinDist, int cannyEdgeThreshold, int houghAccThreshold, double minRadius, double maxRadius){ cv::Mat src_gray; @@ -92,16 +92,21 @@ cv::Mat Beamer::buildCrossFrame(cv::Point projectedCross, int step, int max, boo 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); + + // draw the little red/green square at the center of the frame cv::rectangle( frameImage, cv::Point(getWidth()/2 -30, getHeight()/2 -20), cv::Point(getWidth()/2 -10, getHeight()/2), color, cv::FILLED, 8, 0 ); + + // draw the steps cv::putText( frameImage, std::to_string(step) + "/" + std::to_string(max), cv::Point( getWidth()/2, getHeight()/2 ), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255)); + return frameImage; } @@ -182,35 +187,10 @@ int Beamer::LineLineIntersect( return (true); } -/* -cv::Point3d Beamer::approximatePosition(std::vector<cv::Point3d> *bases, std::vector<cv::Point3d> *directions){ - - cv::Point3d pa, pb; - double mua; - double mub; - std::vector<cv::Point3d> beamerPoints; - int selected[3][2] = { {0,1}, {0,2}, {1,2} }; - - for(int i=0; i < 3; i++){ - LineLineIntersect( directions->at(selected[i][0]), - bases->at(selected[i][0]), - directions->at(selected[i][1]), - bases->at(selected[i][1]), - &pa, &pb, &mua, &mub); - beamerPoints.push_back(pa); - beamerPoints.push_back(pb); - } - cv::Point3d beamerPoint(0.0, 0.0, 0.0); - for (unsigned int i = 0; i < beamerPoints.size(); i++){ - beamerPoint += beamerPoints[i]; - } - beamerPoint /= (double)beamerPoints.size(); - - return beamerPoint; -} +/* +* Approxime la position du beamer en 3D en ce basant sur 3 droites */ - cv::Point3d Beamer::approximatePosition(std::vector<cv::Point3d> *bases, std::vector<cv::Point3d> *directions){ cv::Point3d pa, pb; diff --git a/src/components/projection.cpp b/src/components/projection.cpp index 21f37b9..194fddd 100644 --- a/src/components/projection.cpp +++ b/src/components/projection.cpp @@ -10,18 +10,20 @@ Projection::Projection(){ distanceTopSandbox = 1.0f; } -cv::Point2i Projection::rotatePixel(cv::Point2i pixel){ +cv::Point2i Projection::rotatePixel(cv::Point2i center, double angle, cv::Point2i pixel){ + cv::Mat_<float> matRotation = cv::getRotationMatrix2D(center, angle, 1); cv::Mat tmp = (cv::Mat_<cv::Vec2f>(1, 1) << cv::Vec2f(pixel.x, pixel.y)); - cv::transform(tmp, tmp, adjustingMatrix); + cv::transform(tmp, tmp, matRotation); return cv::Point2i(tmp.at<cv::Vec2f>(0, 0)); } -cv::Point2i Projection::revertRotatePixel(cv::Point2i pixel){ +cv::Point2i Projection::revertRotatePixel(cv::Point2i center, double angle, cv::Point2i pixel){ + cv::Mat_<float> matRotation = cv::getRotationMatrix2D(center, angle, 1); cv::Mat tmp = (cv::Mat_<cv::Vec2f>(1, 1) << cv::Vec2f(pixel.x, pixel.y)); cv::Mat invMat; - cv::invertAffineTransform(adjustingMatrix, invMat); + cv::invertAffineTransform(matRotation, invMat); cv::transform(tmp, tmp, invMat); return cv::Point2i(tmp.at<cv::Vec2f>(0, 0)); } diff --git a/src/lib/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp index e62f3dd..f0596ca 100644 --- a/src/lib/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -20,7 +20,7 @@ SandboxSetup::~SandboxSetup(){ // return 1 when config can't be saved in file int SandboxSetup::saveConfig(char *path){ - if(SandboxConfig::saveAdjustingMatrixInto(path, projection->getAdjustingMatrix())) + if(SandboxConfig::saveAdjustingMatrixInto(path, projection->getAdjustingMatrix(), projection->getAngleRotation())) return 1; if(SandboxConfig::saveDistanceToSandboxTopInto(path, projection->getDistanceTopSandbox())) @@ -77,10 +77,10 @@ int SandboxSetup::loadFrameProcessProfil(){ void SandboxSetup::setupAdjustMatrix(std::vector<cv::Point2i> rectPoints, cv::Point2i center){ // Set adjusting matrix for the projection - int widthTop = rectPoints[3].x - rectPoints[0].x; - double angle = atan((double)(rectPoints[3].y - rectPoints[0].y) / widthTop); - cv::Mat_<float> matRotation = cv::getRotationMatrix2D(center, toDegrees(angle), 1); + double angle = getAngle(rectPoints); + cv::Mat_<float> matRotation = cv::getRotationMatrix2D(center, angle, 1); projection->setAdjustingMatrix(matRotation); + projection->setAngleRotation(angle); } @@ -90,13 +90,14 @@ void SandboxSetup::setupAdjustMatrix(std::vector<cv::Point2i> rectPoints, cv::Po * pts[2] : bottom right * pts[3] : top right */ -void SandboxSetup::setupCroppingMask(std::vector<cv::Point2i> rectPoints){ +void SandboxSetup::setupCroppingMask(std::vector<cv::Point2i> rectPoints, cv::Point2i center){ // Set cropping mask - cv::Point2i ptl = projection->rotatePixel(rectPoints[0]); - cv::Point2i pbl = projection->rotatePixel(rectPoints[1]); - cv::Point2i pbr = projection->rotatePixel(rectPoints[2]); - cv::Point2i ptr = projection->rotatePixel(rectPoints[3]); + double angle = getAngle(rectPoints); + cv::Point2i ptl = projection->rotatePixel(center, angle, rectPoints[0]); + cv::Point2i pbl = projection->rotatePixel(center, angle, rectPoints[1]); + cv::Point2i pbr = projection->rotatePixel(center, angle, rectPoints[2]); + cv::Point2i ptr = projection->rotatePixel(center, angle, rectPoints[3]); cv::Point2i pbot = (pbl.y < pbr.y) ? pbl : pbr; int widthTop = ptr.x - ptl.x; @@ -111,6 +112,11 @@ void SandboxSetup::setupCroppingMask(std::vector<cv::Point2i> rectPoints){ // +double SandboxSetup::getAngle(std::vector<cv::Point2i> rectPoints){ + int widthTop = rectPoints[3].x - rectPoints[0].x; + return toDegrees(atan((double)(rectPoints[3].y - rectPoints[0].y) / widthTop)); +} + double SandboxSetup::toDegrees(double radians){ return radians * (180.0 / M_PI); } diff --git a/src/tools/sandboxConfig.cpp b/src/tools/sandboxConfig.cpp index 5de2e92..93cbfe0 100644 --- a/src/tools/sandboxConfig.cpp +++ b/src/tools/sandboxConfig.cpp @@ -3,7 +3,7 @@ static int saveConfigIn(char *path, YAML::Node config); -int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat_<float> matrix){ +int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat_<float> matrix, double angle){ // convert matrix into a one layer vector YAML::Node vec = YAML::Load("[]"); @@ -15,6 +15,7 @@ int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat_<float> matrix){ YAML::Node val; + val["angle"] = angle; val["width"] = matrix.cols; val["height"] = matrix.rows; val["matrix"] = vec; @@ -161,10 +162,11 @@ int SandboxConfig::loadAdjustingMatrixFrom(char *path, Projection *projection){ }; // uncomplet data for adjusting matrix - if(!(config[SCFG_MATRIX]["width"] && config[SCFG_MATRIX]["height"] && config[SCFG_MATRIX]["matrix"])){ + if(!(config[SCFG_MATRIX]["angle"] && config[SCFG_MATRIX]["width"] && config[SCFG_MATRIX]["height"] && config[SCFG_MATRIX]["matrix"])){ return 2; } + double angle = config[SCFG_MATRIX]["angle"].as<double>(); int height = config[SCFG_MATRIX]["height"].as<int>(); int width = config[SCFG_MATRIX]["width"].as<int>(); std::vector<float> values = config[SCFG_MATRIX]["matrix"].as<std::vector<float>>(); @@ -185,6 +187,7 @@ int SandboxConfig::loadAdjustingMatrixFrom(char *path, Projection *projection){ } projection->setAdjustingMatrix(matrix); + projection->setAngleRotation(angle); return 0; } -- GitLab