diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index 7706c051720102cc884c63e18978972053f17cc0..f08ee3c8bb3905bd8f14c122b4665a5c5ca8d0cb 100644 --- a/app/SandboxSetup/SandboxSetup.pro +++ b/app/SandboxSetup/SandboxSetup.pro @@ -31,7 +31,8 @@ SOURCES += \ croppingmask.cpp \ maskedit.cpp \ projectiongui.cpp \ - qtfullscreen.cpp + qtfullscreen.cpp \ + beamerlocationgui.cpp HEADERS += \ monitorgui.h \ @@ -39,14 +40,16 @@ HEADERS += \ croppingmask.h \ maskedit.h \ projectiongui.h \ - qtfullscreen.h + qtfullscreen.h \ + beamerlocationgui.h FORMS += \ monitorgui.ui \ camerafocus.ui \ croppingmask.ui \ maskedit.ui \ - projectiongui.ui + projectiongui.ui \ + beamerlocationgui.ui diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp new file mode 100644 index 0000000000000000000000000000000000000000..122b1d21a634991ce8d30212f6e805cd95aaf129 --- /dev/null +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -0,0 +1,36 @@ +#include "beamerlocationgui.h" +#include "ui_beamerlocationgui.h" + +BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent) : + QDialog(parent), + ui(new Ui::BeamerLocationGui) +{ + setup = _setup; + mg = _mg; + QScreen *sc = mg->getScreen(); + winFullScreen = new QtFullScreen(sc, true); + ui->setupUi(this); +} + +BeamerLocationGui::~BeamerLocationGui() +{ + delete ui; +} + +void BeamerLocationGui::imshow(cv::Mat frame){ + winFullScreen->imShow(frame); +} + +void BeamerLocationGui::findBeamer(){ + if(ptrShowImage == nullptr){ + std::cout << "Null Pointer, showImage method must be specified with \"setPtrShowImage\" in BeamerLocationGui" << std::endl; + exit(1); + } + endSuccessfully = (setup->setupBeamerLocation(ptrShowImage)==0); + winFullScreen->close(); +} + +void BeamerLocationGui::showEvent(QShowEvent *e){ + QDialog::showEvent(e); + findBeamer(); +} diff --git a/app/SandboxSetup/beamerlocationgui.h b/app/SandboxSetup/beamerlocationgui.h new file mode 100644 index 0000000000000000000000000000000000000000..4f3968e8397f951d22573d2e717776cd5c4c32b6 --- /dev/null +++ b/app/SandboxSetup/beamerlocationgui.h @@ -0,0 +1,39 @@ +#ifndef BEAMERLOCATIONGUI_H +#define BEAMERLOCATIONGUI_H + +#include <QDialog> +#include <opencv2/opencv.hpp> +#include "qtfullscreen.h" +#include "monitorgui.h" +#include "sandboxSetup.h" + +namespace Ui { +class BeamerLocationGui; +} + +class BeamerLocationGui : public QDialog +{ + Q_OBJECT + +public: + explicit BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent = 0); + bool endedSuccessfully(){ return endSuccessfully; }; + void setPtrShowImageFn(ShowImageFn ptr){ ptrShowImage = ptr; }; + void imshow(cv::Mat); + ~BeamerLocationGui(); + +protected: + void showEvent(QShowEvent *e); + +private: + Ui::BeamerLocationGui *ui; + QtFullScreen *winFullScreen; + SandboxSetup *setup; + MonitorGui *mg; + bool endSuccessfully = false; + ShowImageFn ptrShowImage = nullptr; + + void findBeamer(); +}; + +#endif // BEAMERLOCATIONGUI_H diff --git a/app/SandboxSetup/beamerlocationgui.ui b/app/SandboxSetup/beamerlocationgui.ui new file mode 100644 index 0000000000000000000000000000000000000000..252fe300ab06bbf902f9b45c3dd7c39ac796a227 --- /dev/null +++ b/app/SandboxSetup/beamerlocationgui.ui @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BeamerLocationGui</class> + <widget class="QDialog" name="BeamerLocationGui"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <widget class="QCheckBox" name="checkBox"> + <property name="geometry"> + <rect> + <x>100</x> + <y>70</y> + <width>92</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>CheckBox</string> + </property> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 9a2f70503f8a205a73f04b57f6946310dcd4ac2a..f2baa071065f35f2adc3e4bc6a99c0f3579bc1cc 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -1,16 +1,20 @@ #include "croppingmask.h" #include "ui_croppingmask.h" -CroppingMask::CroppingMask(SandboxSetup *sandbox, QWidget *parent) : +CroppingMask::CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : QDialog(parent), ui(new Ui::CroppingMask) { setup = sandbox; + mg = _mg; ui->setupUi(this); maskEdit = new MaskEdit(ui->frame->geometry()); ui->vLayout->addWidget(maskEdit, 1); + QScreen *sc = mg->getScreen(); + projBlueScreen = new QtFullScreen(sc, true); + // TODO : try to load cropping mask from file } @@ -22,20 +26,40 @@ CroppingMask::~CroppingMask() void CroppingMask::on_btnTakePicture_clicked() { - setup->captureBlueScreen(500); - cv::Mat rgb = setup->getCamera()->getRGBFrame(); - cameraRGBFrame = rgb; + // take picture of blue screen + initFullScreen(); + cv::Mat blueMat = cv::Mat(1, 1, CV_8UC3, cv::Scalar(0, 0, 255)); + projBlueScreen->imShow(blueMat); + QTimer::singleShot(1000, this, &CroppingMask::takePicture); +} + +void CroppingMask::takePicture(){ + + setup->getCamera()->captureFrame(); + projBlueScreen->close(); + + cameraRGBFrame = setup->getCamera()->getRGBFrame(); // no config found - if(!maskValideInFrame(&rgb)){ - float y = rgb.size().height; - float x = rgb.size().width; + if(!maskValideInFrame(&cameraRGBFrame)){ + float y = cameraRGBFrame.size().height; + float x = cameraRGBFrame.size().width; rectPoints = std::vector<cv::Point>{ cv::Point(1.0/4*x, 1.0/4*y), cv::Point(1.0/4*x, 3.0/4*y), cv::Point(3.0/4*x, 3.0/4*y), cv::Point(3.0/4*x, 1.0/4*y) }; } maskEdit->updateFrame(&cameraRGBFrame, &rectPoints); } +void CroppingMask::initFullScreen(){ + + if(!blueScreenInitilized){ + blueScreenInitilized = true; + QScreen *sc = mg->getScreen(); + QRect res = sc->geometry(); + projBlueScreen->setGeometry(res.x(), res.y(), res.width(), res.height()); + } +} + bool CroppingMask::maskValideInFrame(cv::Mat *rgb){ if(rectPoints.empty()) diff --git a/app/SandboxSetup/croppingmask.h b/app/SandboxSetup/croppingmask.h index 9c3bb00093efa2f1100358a868bc8758134dba1f..b3220c05a39897e71b1b040249004dba5d5a5fc5 100644 --- a/app/SandboxSetup/croppingmask.h +++ b/app/SandboxSetup/croppingmask.h @@ -2,8 +2,12 @@ #define CROPPINGMASK_H #include <QDialog> +#include <QTimer> #include <sandboxSetup.h> +#include <opencv2/opencv.hpp> +#include "qtfullscreen.h" #include "maskedit.h" +#include "monitorgui.h" namespace Ui { class CroppingMask; @@ -14,7 +18,7 @@ class CroppingMask : public QDialog Q_OBJECT public: - explicit CroppingMask(SandboxSetup *sandbox,QWidget *parent = 0); + explicit CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); ~CroppingMask(); std::vector<cv::Point> getRectPoints(){ return rectPoints; }; bool isOk(){ return state; }; @@ -30,9 +34,14 @@ private: bool state = false; cv::Mat cameraRGBFrame; MaskEdit *maskEdit; + MonitorGui *mg; + QtFullScreen *projBlueScreen; + bool blueScreenInitilized = false; - bool maskValideInFrame(cv::Mat *rgb); + void initFullScreen(); + bool maskValideInFrame(cv::Mat *rgb); + void takePicture(); }; #endif // CROPPINGMASK_H diff --git a/app/SandboxSetup/main.cpp b/app/SandboxSetup/main.cpp index 1c9720f2675c8da764da9dc11a9261d2f3b97bf8..fb198396aa44c0fc6f778e4b728c3accb130ef4d 100644 --- a/app/SandboxSetup/main.cpp +++ b/app/SandboxSetup/main.cpp @@ -1,15 +1,113 @@ +/* +#include <QApplication> + +#include <sandboxSetup.h> +#include "monitorgui.h" +#include "camerafocus.h" +#include "croppingmask.h" +#include "projectiongui.h" +#include "beamerlocationgui.h" + +int argc = 0; +char *argv[] = {""}; +QApplication app(argc, argv); +SandboxSetup setup; +MonitorGui mg; +ProjectionGui pg(&setup, &mg); +CameraFocus cf(&setup); +CroppingMask cm(&setup, &mg); +BeamerLocationGui bl(&setup, &mg); + + + +void beamerLocationShowImage(cv::Mat frame){ + bl.imshow(frame); +} + +void exit_msg(SandboxSetup *setup, std::string msg){ + setup->getCamera()->stop(); + std::cout << msg << std::endl; + exit(1); +} + +int main(){ + + // Init + setup.getCamera()->start(); + + + // Select output screen and projection's resolutions + mg.show(); + app.exec(); + if(!mg.isOk()){ + exit_msg(&setup, "Cancel resolution"); + } + setup.getBeamer()->setResolution(cv::Size(mg.getWidth(), mg.getHeight())); + + + // Setup camera and beamer physically + pg.show(); + app.exec(); + + + // Edit frame process profil for the setupBeamerLocation routine + cf.show(); + app.exec(); + if(!cf.isOk()){ + exit_msg(&setup, "Cancel camera parameters"); + } + + + // Setup the adjust matrix and cropping mask + cm.show(); + app.exec(); + if(!cm.isOk()){ + exit_msg(&setup, "Cancel drop"); + } + + cv::Size s = setup.getCamera()->getDepthFrame().size(); + cv::Point center(s.width / 2, s.height / 2); + std::vector<cv::Point> rectPoints = cm.getRectPoints(); + + setup.setupAdjustMatrix(rectPoints, center); + setup.setupCroppingMask(rectPoints); + + + // Setup the beamer location + bl.setPtrShowImageFn(beamerLocationShowImage); + bl.show(); + app.exec(); + if(!bl.endedSuccessfully()){ + exit_msg(&setup, "Cancel beamer position"); + } + + // Save config in file + if(setup.saveConfig()){ + exit_msg(&setup, "Failed to save configuration"); + } + + setup.getCamera()->stop(); + return 0; +} +*/ + + #include <QApplication> #include "monitorgui.h" #include "camerafocus.h" #include "croppingmask.h" #include "projectiongui.h" +#include "qtfullscreen.h" #include <sandboxSetup.h> -char wname[] = "FindBeamer"; +//QScreen *sc = nullptr; +char wname[] = "Image"; void showImage(cv::Mat frame){ + //QtFullScreen *winFullScreen = new QtFullScreen(sc, true); + //winFullScreen->imShow(frame); cv::imshow(wname, frame); } @@ -24,27 +122,29 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); SandboxSetup setup; + MonitorGui mg; + ProjectionGui pg(&setup, &mg); + CameraFocus cf(&setup); + CroppingMask cm(&setup, &mg); + setup.getCamera()->start(); // Select output screen and projection's resolutions - MonitorGui mg; mg.show(); app.exec(); if(!mg.isOk()){ exit_msg(&setup, "Cancel resolution"); } setup.getBeamer()->setResolution(cv::Size(mg.getWidth(), mg.getHeight())); - + //sc = mg.getScreen(); // 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(); app.exec(); if(!cf.isOk()){ @@ -53,7 +153,6 @@ int main(int argc, char *argv[]) // Setup the adjust matrix and cropping mask - CroppingMask cm(&setup); cm.show(); app.exec(); if(!cm.isOk()){ @@ -86,3 +185,4 @@ int main(int argc, char *argv[]) setup.getCamera()->stop(); return 0; } + diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp index fab18ea5c67e0a8a8f7f06b79b72e893f3f35fee..bc39af1b93f99b615cdab45400496bf6bf27c660 100644 --- a/app/SandboxSetup/projectiongui.cpp +++ b/app/SandboxSetup/projectiongui.cpp @@ -33,7 +33,7 @@ void ProjectionGui::on_btnStart_clicked() QScreen *sc = mg->getScreen(); // open blue screen on the selected output cv::Mat blue = cv::Mat(1, 1, CV_8UC3, cv::Scalar(0, 0, 255)); - blueScreen = new QtFullScreen(sc); + blueScreen = new QtFullScreen(sc, true); blueScreen->imShow(blue); cameraUsed = true; diff --git a/app/SandboxSetup/qtfullscreen.cpp b/app/SandboxSetup/qtfullscreen.cpp index 2fc2ee532844b12526662921eef8948abd86abb8..47b8b0bdb5aa2fe3c7fa93ee971cdf758a021e6e 100644 --- a/app/SandboxSetup/qtfullscreen.cpp +++ b/app/SandboxSetup/qtfullscreen.cpp @@ -1,15 +1,23 @@ #include "qtfullscreen.h" -QtFullScreen::QtFullScreen(QScreen *_sc, QWidget *parent) : QWidget(parent) +QtFullScreen::QtFullScreen(QScreen *_sc, bool isBorderless, QWidget *parent) : QWidget(parent) { win = new QDialog; screen = _sc; win->setGeometry(screen->geometry()); + if(isBorderless) + win->setWindowState(Qt::WindowFullScreen); + image = new QLabel(win); image->setGeometry(0, 0 , win->geometry().width(), win->geometry().height()); image->setScaledContents(true); } +void QtFullScreen::setGeometry(int x, int y, int w, int h){ + win->setGeometry(x, y, w, h); + image->setGeometry(0 , 0, w, h); +} + void QtFullScreen::imShow(cv::Mat frame){ QImage src = QImage((uchar *)frame.data, (int)frame.cols, (int)frame.rows, static_cast<int>(frame.step.buf[0]), QImage::Format_RGB888); diff --git a/app/SandboxSetup/qtfullscreen.h b/app/SandboxSetup/qtfullscreen.h index a0e15a5e3beaeedad360667c76eec19ea38b9df9..c09a3fe7386076f2d3aa44877b762e6d12c393ee 100644 --- a/app/SandboxSetup/qtfullscreen.h +++ b/app/SandboxSetup/qtfullscreen.h @@ -11,9 +11,10 @@ class QtFullScreen : public QWidget { Q_OBJECT public: - explicit QtFullScreen(QScreen *sc, QWidget *parent = nullptr); + explicit QtFullScreen(QScreen *sc, bool isBorderless=false, QWidget *parent = nullptr); void imShow(cv::Mat frame); void close(); + void setGeometry(int x, int y, int w, int h); signals: diff --git a/inc/beamer.h b/inc/beamer.h index fe5dc750e0665ccabc3ce68df96d9d430ea79828..83fb6d311a9337cf8b5224574d16a592fad1e51e 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -5,6 +5,7 @@ #define ESCAPE_CHAR 27 +typedef void (*ShowImageFn)(cv::Mat); class FrameProcessProfil{ private: diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index cf1a1b5996aa0246d4c5963f04f4de1fadfe8ba1..b6aaf36badd02af7fdbc01f4fbfc1710b756f4d8 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -13,7 +13,7 @@ Beamer::Beamer(){ */ -int Beamer::findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)) +int Beamer::findBeamerFrom(Camera camera, ShowImageFn imshow) { cv::Mat depth; cv::Mat rgb; @@ -55,7 +55,7 @@ int Beamer::findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)) cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255)); - showImage(frameImage); + imshow(frameImage); // Wait for interaction char keyCode = cv::waitKey(500);