diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index adb2321a6c25a330d0915fd4b6f536cdfa946e76..05ce6410ae113f6510f52873a8ab01c758c2a0ff 100644 --- a/app/SandboxSetup/SandboxSetup.pro +++ b/app/SandboxSetup/SandboxSetup.pro @@ -29,19 +29,22 @@ SOURCES += \ monitorgui.cpp \ camerafocus.cpp \ croppingmask.cpp \ - maskedit.cpp + maskedit.cpp \ + projectiongui.cpp HEADERS += \ monitorgui.h \ camerafocus.h \ croppingmask.h \ - maskedit.h + maskedit.h \ + projectiongui.h FORMS += \ monitorgui.ui \ camerafocus.ui \ croppingmask.ui \ - maskedit.ui + maskedit.ui \ + projectiongui.ui diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index 5a4f218da5f50d6431cb41699ef99ed409ee07f8..4ce81bdceb657ef11d4eb89a1335808051d71860 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Focus</string> </property> <widget class="QDialogButtonBox" name="btnbxValidate"> <property name="geometry"> diff --git a/app/SandboxSetup/croppingmask.ui b/app/SandboxSetup/croppingmask.ui index c4b6dbc2415d5820261ab4bb30858ec216f2bc37..c1fa63cda4c8d0d5dc709fc8d30a7f57b27f4e87 100644 --- a/app/SandboxSetup/croppingmask.ui +++ b/app/SandboxSetup/croppingmask.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Crop</string> </property> <widget class="QDialogButtonBox" name="btnbxEnd"> <property name="enabled"> @@ -76,9 +76,26 @@ </layout> </widget> </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>40</x> + <y>350</y> + <width>441</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Note : Set your screens in mirror mode</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + </widget> <zorder>frame</zorder> <zorder>btnbxEnd</zorder> <zorder>btnTakePicture</zorder> + <zorder>label</zorder> </widget> <resources/> <connections> diff --git a/app/SandboxSetup/main.cpp b/app/SandboxSetup/main.cpp index 8c5d5dc517bfb9514589678d3dac1da95ad4e7b6..47b0779aa2abf6c9b379ade3a929a4f239079565 100644 --- a/app/SandboxSetup/main.cpp +++ b/app/SandboxSetup/main.cpp @@ -1,10 +1,18 @@ +#include <QApplication> + #include "monitorgui.h" #include "camerafocus.h" #include "croppingmask.h" -#include <QApplication> - +#include "projectiongui.h" #include <sandboxSetup.h> + +char wname[] = "FindBeamer"; + +void showImage(cv::Mat frame){ + cv::imshow(wname, frame); +} + int main(int argc, char *argv[]) { @@ -23,6 +31,12 @@ int main(int argc, char *argv[]) setup.setBeamerResolution(cv::Size(mg.getWidth(), mg.getHeight())); + // Setup camera and beamer physically + ProjectionGui pg(&setup, &mg); + pg.show(); + app.exec(); + + // Edit frame process profil for the setupBeamerLocation routine CameraFocus cf(&setup); cf.show(); @@ -51,10 +65,14 @@ int main(int argc, char *argv[]) // Setup the beamer location - if(setup.setupBeamerLocation()){ + cv::namedWindow(wname, CV_WINDOW_NORMAL); + cv::setWindowProperty(wname, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); + + if(setup.setupBeamerLocation(showImage)){ std::cout << "Cancel beamer position" << std::endl; return 1; } + cv::destroyAllWindows(); // Save config in file diff --git a/app/SandboxSetup/monitorgui.cpp b/app/SandboxSetup/monitorgui.cpp index d1463868f199039ed000b40666dc7c479509a480..32a82c016326b17a9c6d3e96fd75652a7b0c6f90 100644 --- a/app/SandboxSetup/monitorgui.cpp +++ b/app/SandboxSetup/monitorgui.cpp @@ -37,6 +37,7 @@ void MonitorGui::on_btnbxMonitors_accepted() { valideState = true; QString selectedRes = ui->cbxResolutions->currentText(); + outputName = ui->cbxOutputs->currentText(); std::vector<std::string> res = splitResolution(selectedRes.toStdString()); width = std::stoi(res[0]); height = std::stoi(res[1]); diff --git a/app/SandboxSetup/monitorgui.h b/app/SandboxSetup/monitorgui.h index 1b651186a3169df9732c8621ae70eabdb2580e3f..10d39f2a1fddd3d196b72e85133e4a073a19877f 100644 --- a/app/SandboxSetup/monitorgui.h +++ b/app/SandboxSetup/monitorgui.h @@ -24,6 +24,7 @@ public: int getHeight(){ return height; }; int getWidth(){ return width; }; + std::string getOutput(){ return outputName.toStdString(); }; bool isOk(){ return valideState; }; private slots: @@ -34,6 +35,7 @@ private: Ui::MonitorGui *ui; int height = 0; int width = 0; + QString outputName = ""; bool valideState = false; std::map<std::string, std::vector<std::string>> monitors; void loadResolutionsOf(QScreen* screen); diff --git a/app/SandboxSetup/monitorgui.ui b/app/SandboxSetup/monitorgui.ui index 2feee9db8b62dfde0bc15950531dee59c7161191..2fc38fc4f7bde70b7d111fe994716e3900d2df0e 100644 --- a/app/SandboxSetup/monitorgui.ui +++ b/app/SandboxSetup/monitorgui.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Screen</string> </property> <widget class="QDialogButtonBox" name="btnbxMonitors"> <property name="geometry"> diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5df47d5cc3c70a453e6f62b16ba96720d989ba87 --- /dev/null +++ b/app/SandboxSetup/projectiongui.cpp @@ -0,0 +1,65 @@ +#include "projectiongui.h" +#include "ui_projectiongui.h" + +ProjectionGui::ProjectionGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent) : + QDialog(parent), + ui(new Ui::ProjectionGui) +{ + blueScreen = new QDialog; + setup = _setup; + mg = _mg; + ui->setupUi(this); + + frameTimer = new QTimer(this); + connect(frameTimer, &QTimer::timeout, this, &ProjectionGui::refreshFrame); +} + +ProjectionGui::~ProjectionGui() +{ + delete ui; +} + +void ProjectionGui::on_btnSkip_clicked() +{ + if(cameraUsed){ + frameTimer->stop(); + setup->camera.stop(); + blueScreen->close(); + } + close(); +} + +// Note : Screens should be in extented mode, not mirror (to avoid loop noise from the capture of the screen) +void ProjectionGui::on_btnStart_clicked() +{ + QScreen *sc = QApplication::screens().at(0); + QList<QScreen *> lst = sc->virtualSiblings(); + + for(int i=0; i<lst.size(); i++){ + std::string name = lst[i]->name().toStdString(); + if(name == mg->getOutput()){ + sc = lst[i]; + break; + } + } + + // open blue screen on the selected output + blueScreen->setGeometry(sc->geometry()); + blueScreen->setStyleSheet("background-color:blue;"); + blueScreen->show(); + + setup->camera.start(); + ui->fContainer->hide(); + frameTimer->start(100); + cameraUsed = true; +} + +void ProjectionGui::refreshFrame(){ + setup->camera.captureFrame(); + cv::Mat rgb = setup->camera.getRGBFrame(); + + QImage img = QImage((uchar *)rgb.data, (int)rgb.cols, (int)rgb.rows, static_cast<int>(rgb.step.buf[0]), QImage::Format_RGB888); + QPixmap image = QPixmap::fromImage(img); + + ui->lblFrame->setPixmap(image); +} diff --git a/app/SandboxSetup/projectiongui.h b/app/SandboxSetup/projectiongui.h new file mode 100644 index 0000000000000000000000000000000000000000..4dcdeaa953228502812a4f440fe1264ddc48555c --- /dev/null +++ b/app/SandboxSetup/projectiongui.h @@ -0,0 +1,36 @@ +#ifndef PROJECTIONGUI_H +#define PROJECTIONGUI_H + +#include <QDialog> +#include <sandboxSetup.h> +#include "monitorgui.h" + +namespace Ui { +class ProjectionGui; +} + +class ProjectionGui : public QDialog +{ + Q_OBJECT + +public: + explicit ProjectionGui(SandboxSetup *setup, MonitorGui *mg, QWidget *parent = 0); + ~ProjectionGui(); + +private slots: + void on_btnSkip_clicked(); + + void on_btnStart_clicked(); + +private: + Ui::ProjectionGui *ui; + SandboxSetup *setup; + MonitorGui *mg; + QTimer *frameTimer; + QDialog *blueScreen; + bool cameraUsed = false; + + void refreshFrame(); +}; + +#endif // PROJECTIONGUI_H diff --git a/app/SandboxSetup/projectiongui.ui b/app/SandboxSetup/projectiongui.ui new file mode 100644 index 0000000000000000000000000000000000000000..402799dfff15c4a269bc5a96b596b668036f55a2 --- /dev/null +++ b/app/SandboxSetup/projectiongui.ui @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ProjectionGui</class> + <widget class="QDialog" name="ProjectionGui"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>524</width> + <height>406</height> + </rect> + </property> + <property name="windowTitle"> + <string>Setup</string> + </property> + <widget class="QFrame" name="fContainer"> + <property name="geometry"> + <rect> + <x>40</x> + <y>50</y> + <width>441</width> + <height>281</height> + </rect> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <widget class="QPushButton" name="btnStart"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="geometry"> + <rect> + <x>180</x> + <y>160</y> + <width>89</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Start</string> + </property> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>40</x> + <y>70</y> + <width>361</width> + <height>61</height> + </rect> + </property> + <property name="text"> + <string>Project a blue screen on the previously selected output to setup your beamer</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </widget> + <widget class="QPushButton" name="btnSkip"> + <property name="geometry"> + <rect> + <x>390</x> + <y>350</y> + <width>89</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Next</string> + </property> + </widget> + <widget class="QLabel" name="lblFrame"> + <property name="geometry"> + <rect> + <x>40</x> + <y>50</y> + <width>441</width> + <height>281</height> + </rect> + </property> + <property name="text"> + <string/> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + <widget class="QLabel" name="label_2"> + <property name="geometry"> + <rect> + <x>40</x> + <y>340</y> + <width>331</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Note : Setup your screens in extended mode</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="wordWrap"> + <bool>false</bool> + </property> + </widget> + <zorder>lblFrame</zorder> + <zorder>fContainer</zorder> + <zorder>btnSkip</zorder> + <zorder>label_2</zorder> + </widget> + <resources/> + <connections/> +</ui> diff --git a/inc/beamer.h b/inc/beamer.h index c1caea0a015aa67f3fc13f5802513e578ccd4678..bee44c86018cacab58eeef3088da1be27fac0436 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -59,7 +59,7 @@ class Beamer{ FrameProcessProfil* getProfil(){ return &profil; }; void setProfil(FrameProcessProfil p){ profil = p; }; - int findBeamerFrom(Camera camera); + int findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)); cv::Mat editContrast(cv::Mat image, double contrast, int brightness); std::vector<int> findCercleZ(cv::Mat &rgb, double contrast, int brightness, int ratioRadius, int upperMinThreshold, int lowerMinThreshold); void printPosition(); diff --git a/inc/sandboxSetup.h b/inc/sandboxSetup.h index 574d6c0a93a8aebd968d8c03c0e07a6ab45adb3d..0a3efe1e27e8fd0634ad110b900d886f34813998 100644 --- a/inc/sandboxSetup.h +++ b/inc/sandboxSetup.h @@ -33,7 +33,7 @@ class SandboxSetup{ void setupCroppingMask(std::vector<cv::Point> rectPoints); int setupProjection(); int setupBeamerResolution(); - int setupBeamerLocation(); + int setupBeamerLocation(void (*showImage)(cv::Mat)); int loadFrameProcessProfil(); void setBeamerResolution(cv::Size resolution); diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index bbb9198ab484bb4535eac995e3e8bebdee94f93b..218dfc93d0e5106f5842632c44e754994e36f3ae 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -13,11 +13,8 @@ Beamer::Beamer(){ */ -int Beamer::findBeamerFrom(Camera camera) +int Beamer::findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)) { - char wname[] = "FindBeamer"; - cv::namedWindow(wname, CV_WINDOW_NORMAL); - cv::setWindowProperty(wname, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); cv::Mat depth; cv::Mat rgb; cv::Mat frameImage(resolution, CV_8UC3, cv::Scalar(0, 0, 0)); @@ -61,7 +58,7 @@ int Beamer::findBeamerFrom(Camera camera) cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255)); - cv::imshow(wname, frameImage); + showImage(frameImage); // Wait for interaction char keyCode = cv::waitKey(500); @@ -87,8 +84,6 @@ int Beamer::findBeamerFrom(Camera camera) } camera.stop(); - cv::destroyAllWindows(); - cv::Point3d beamerPoint = approximatePosition(directions, bases); diff --git a/src/lib/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp index 46d0f2de797a8777a9ddd0cb2ae0dea38f4a9125..c5ed66d9998cad714dd873d79dcf1e2730d2812d 100644 --- a/src/lib/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -88,8 +88,9 @@ int SandboxSetup::setupBeamerResolution(){ // return 1 when user exits process -int SandboxSetup::setupBeamerLocation(){ - return beamer.findBeamerFrom(camera); +int SandboxSetup::setupBeamerLocation(void (*showImage)(cv::Mat)){ + + return beamer.findBeamerFrom(camera, showImage); }