diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index f734889cd45bd7bd8103496c23d727c6d642c5b2..1aee35e79186514eeb7a3e713d26cd1ffa499d96 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 c5e45a3ea47b5b132f4ef98a85d5ccb69338d6f5..86349965ba5d0c3d5227896e96db14870e3ea593 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 d756c7f30dd06d53922a983b614df2732561936b..25d6a154b2e2363b56cd1be985aba6df0c0bc8c0 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 319f8f520c7f2a7e1ce698d5051bf8b43c9b3551..ac84b6fb1bb14708b26df670ac26734cc9ce5dd5 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 9efd457846f9bf626e7d4341fbed63d712d485f5..d9be67f168501a4de7f405decc93ee56f7bf0dab 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 564ec29cdec258f4495ed803e8c0e7cd78a4e97c..d9c2d4bbae2419460e8b3504990852224720d31f 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 f7d7133767ec43152913256cb7a32670d529d2ec..f47884218ec5da203636a43cf6dfa323505f9d7b 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 79ee3a69372a9415d6cfa12a684f0603662a1b14..7b06f0d942145f6b4bfe4f9956cc70fbafb5b50d 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 1ffe6d7dc780a3e8fedec9792723bd34ef8f17be..9724fb616dc026dd28e47876d7c7c216e473106e 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 a30f0bd0766fb3e12b2775a5cb4f401217feff1c..5dad9e9e7b8bb8a4d0c9796d6bf93ff5e6e3e7f1 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 c2fb74f66afd5cc41410aeab718c6eb089a4669f..69fa475c92bf387f21181a2154b5d622ba97d9af 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 d5d2de153b3f90553873a515c70ed790a3a9ee5f..2ef12defebf0525d893e04d3152d379985013f7d 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 3247aac86e39a944f563b75e03217695441ae1cd..0f427a489e3cd9cd9816e83b33497e38561a02df 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 e1395a582dc39bb7e9d0a0380f2fa4265360c169..b881f128ec5418eb28a9fbf7b9707c40c012fbd2 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 7f96dbc663b6d868f24bab93bc01c42e1e0e4096..bfa8670f90f2904a3dda0d2212b7a48b7c19cb5d 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 4dae00345cdfa56e1c063e29364ee7239f68d1dd..0fc9b233e774272c7bceb33d553b6263e745730d 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 2544769a6e67a8297f6fe706d54abb9bc57df47c..5449a2ae17cd8408ce3ffa3fb34ee6a876dd5a85 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 835c36db9d1c0a308ad36b20c256a7eaf6a1133d..f1eefbe5bf428a166077f2dd4f3b2cd416c876b3 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 21f37b9a08a8b86083c774a416bf4ceb0f6beb9c..194fddd85074e75a415d88a0be9933465b5ab9e5 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 e62f3dd8852258466790910e056632f3dc7b753c..f0596ca6360483fb6ea07c12fc5ea3378d803108 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 5de2e922700bda9202c569e7e5ba4e5f53b479c8..93cbfe0da7f73afdd019d767d0dcdacfc7de8acb 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; }