From f5852d1afa22fb20aa97f5b0725e6847afeadf63 Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Mon, 25 May 2020 16:38:43 +0200 Subject: [PATCH] add step to setup beamer and camera physically + setable output function in findBeamer routine --- app/SandboxSetup/SandboxSetup.pro | 9 ++- app/SandboxSetup/camerafocus.ui | 2 +- app/SandboxSetup/croppingmask.ui | 19 ++++- app/SandboxSetup/main.cpp | 24 +++++- app/SandboxSetup/monitorgui.cpp | 1 + app/SandboxSetup/monitorgui.h | 2 + app/SandboxSetup/monitorgui.ui | 2 +- app/SandboxSetup/projectiongui.cpp | 65 +++++++++++++++ app/SandboxSetup/projectiongui.h | 36 +++++++++ app/SandboxSetup/projectiongui.ui | 122 +++++++++++++++++++++++++++++ inc/beamer.h | 2 +- inc/sandboxSetup.h | 2 +- src/components/beamer.cpp | 9 +-- src/lib/sandboxSetup.cpp | 5 +- 14 files changed, 280 insertions(+), 20 deletions(-) create mode 100644 app/SandboxSetup/projectiongui.cpp create mode 100644 app/SandboxSetup/projectiongui.h create mode 100644 app/SandboxSetup/projectiongui.ui diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index adb2321..05ce641 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 5a4f218..4ce81bd 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 c4b6dbc..c1fa63c 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 8c5d5dc..47b0779 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 d146386..32a82c0 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 1b65118..10d39f2 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 2feee9d..2fc38fc 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 0000000..5df47d5 --- /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 0000000..4dcdeaa --- /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 0000000..402799d --- /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 c1caea0..bee44c8 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 574d6c0..0a3efe1 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 bbb9198..218dfc9 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 46d0f2d..c5ed66d 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); } -- GitLab