diff --git a/app/SandboxSetup/SandboxSetup.pro b/app/SandboxSetup/SandboxSetup.pro index 7d0de55a286cca2e28caf0dd80076cffd0522bd4..414961ac8ab92e51571a64451bceeac601a07344 100644 --- a/app/SandboxSetup/SandboxSetup.pro +++ b/app/SandboxSetup/SandboxSetup.pro @@ -34,7 +34,8 @@ SOURCES += \ qtfullscreen.cpp \ beamerlocationgui.cpp \ mainwindow.cpp \ - subapp.cpp + subapp.cpp \ + initcamera.cpp HEADERS += \ monitorgui.h \ @@ -45,7 +46,8 @@ HEADERS += \ qtfullscreen.h \ beamerlocationgui.h \ mainwindow.h \ - subapp.h + subapp.h \ + initcamera.h FORMS += \ monitorgui.ui \ @@ -54,7 +56,8 @@ FORMS += \ maskedit.ui \ projectiongui.ui \ beamerlocationgui.ui \ - mainwindow.ui + mainwindow.ui \ + initcamera.ui diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp index 0b40bc9b623132b69e37572c8bd11974a5787f76..0920b0fd2597d6b1503b82bc13e9225e91cd0b32 100644 --- a/app/SandboxSetup/beamerlocationgui.cpp +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -85,9 +85,9 @@ void BeamerLocationGui::routineFrame(){ cv::Point2i cross = crosses.at(stepCross); // capture frame - camera->captureFrame(); + camera->capture(); depth = camera->getDepthFrame(); - rgb = camera->getRGBFrame(); + rgb = camera->getColorFrame(); // Look for the circle target circle = beamer->findCercleZ(rgb, profil->getContrast(), profil->getBrightness(), profil->getRadiusRatio(), profil->getUpperMinThreshold(), profil->getLowerMinThreshold()); diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index dc46d65a7dbff5cb30f32d54271efdd1d814164b..8235dc83789cc092477904b988e867832a85fd4b 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -13,8 +13,6 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, QWidget *parent) : initCameraParams(); frameTimer = new QTimer(this); connect(frameTimer, &QTimer::timeout, this, &CameraFocus::refreshFrame); - - frameTimer->start(100); } CameraFocus::~CameraFocus() @@ -22,6 +20,16 @@ CameraFocus::~CameraFocus() delete ui; } +void CameraFocus::showEvent(QShowEvent *event){ + QWidget::showEvent(event); + + if(!warmedUp){ + setup->getCamera()->warmUpDepthLens(); + warmedUp = true; + } + frameTimer->start(100); +} + // TODO : override "checkRoutine" to ensure that the profil makes sense void CameraFocus::valideRoutine(){ @@ -38,12 +46,12 @@ void CameraFocus::cancelRoutine(){ void CameraFocus::refreshFrame(){ - setup->getCamera()->captureFrame(); + setup->getCamera()->capture(); FrameProcessProfil *profil = setup->getBeamer()->getProfil(); cv::Mat gray; cv::Mat rgbFromGray; - cv::Mat rgb = setup->getCamera()->getRGBFrame(); + cv::Mat rgb = setup->getCamera()->getColorFrame(); std::vector<cv::Point3i> crc; if(profil->getUpperMinThreshold() >= profil->getLowerMinThreshold()){ diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocus.h index 86750ad92cec0d2a9832d045316635c264fa6499..96cafdc0d4ac307099d732526dc4b6ef0426fb72 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocus.h @@ -39,12 +39,16 @@ private slots: void on_chbxDisplayContrast_clicked(); +protected: + void showEvent(QShowEvent *event); + private: Ui::CameraFocus *ui; SandboxSetup *setup; QTimer *frameTimer; FrameProcessProfil defaultProfil; bool displayConstrasts = false; + bool warmedUp = false; void refreshFrame(); void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved); diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 51ff4a9a2bb53ab61a58d579e8e24f8dc1d62c11..36c9a54873783056ad061fa9f84cf18a02d4c8b9 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -57,10 +57,10 @@ void CroppingMask::on_btnTakePicture_clicked() void CroppingMask::takePicture(){ - setup->getCamera()->captureFrame(); + setup->getCamera()->capture(); projBlueScreen->close(); - cameraRGBFrame = setup->getCamera()->getRGBFrame(); + cameraRGBFrame = setup->getCamera()->getColorFrame(); // no config found if(!maskValideInFrame(&cameraRGBFrame)){ diff --git a/app/SandboxSetup/initcamera.cpp b/app/SandboxSetup/initcamera.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8316e96ccf64cc9eb52d9932b0b88d030265bfb3 --- /dev/null +++ b/app/SandboxSetup/initcamera.cpp @@ -0,0 +1,55 @@ +#include "initcamera.h" +#include "ui_initcamera.h" + + + +CameraStartThread::CameraStartThread(Camera *c) : QThread() { + camera = c; +} + +void CameraStartThread::run() { + + camera->start(); + std::cout << "camera ready" << std::endl; + emit setupReady(); +} + + + + +InitCamera::InitCamera(SandboxSetup *_setup, QWidget *parent) : + SubApp(parent), + ui(new Ui::InitCamera) +{ + setup = _setup; + ui->setupUi(this); + + workerThread = new CameraStartThread(setup->getCamera()); + connect(workerThread, &CameraStartThread::setupReady, this, &InitCamera::setupReady); + connect(workerThread, &CameraStartThread::finished, workerThread, &QObject::deleteLater); +} + +InitCamera::~InitCamera() +{ + delete ui; + workerThread->quit(); + workerThread->wait(); +} + +void InitCamera::showEvent(QShowEvent *event){ + + QWidget::showEvent(event); + QTimer::singleShot(10, this, &InitCamera::setupCamera); +} + +void InitCamera::setupCamera(){ + + std::cout << "init camera" << std::endl; + workerThread->start(); +} + +void InitCamera::setupReady(){ + emit sendNotif(); +} + + diff --git a/app/SandboxSetup/initcamera.h b/app/SandboxSetup/initcamera.h new file mode 100644 index 0000000000000000000000000000000000000000..2157a38ad2da77b7008566dfd183b01e3dfe635d --- /dev/null +++ b/app/SandboxSetup/initcamera.h @@ -0,0 +1,52 @@ +#ifndef INITCAMERA_H +#define INITCAMERA_H + +#include <QWidget> +#include <QTimer> +#include <QThread> +#include "subapp.h" +#include <sandboxSetup.h> + +namespace Ui { +class InitCamera; +} + + +class CameraStartThread : public QThread +{ + Q_OBJECT + +public: + explicit CameraStartThread(Camera *c); + void run(); + +signals: + void setupReady(); + +private: + Camera *camera; +}; + + + +class InitCamera : public SubApp +{ + Q_OBJECT + +public: + explicit InitCamera(SandboxSetup *_setup, QWidget *parent = 0); + ~InitCamera(); + +protected: + void showEvent(QShowEvent *event); + +private: + Ui::InitCamera *ui; + SandboxSetup *setup; + CameraStartThread *workerThread; + + void setupCamera(); + void setupReady(); +}; + +#endif // INITCAMERA_H diff --git a/app/SandboxSetup/initcamera.ui b/app/SandboxSetup/initcamera.ui new file mode 100644 index 0000000000000000000000000000000000000000..50ef8e20b6dcfcdf13981d94254ac721b5b1eec0 --- /dev/null +++ b/app/SandboxSetup/initcamera.ui @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>InitCamera</class> + <widget class="QWidget" name="InitCamera"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>110</x> + <y>140</y> + <width>161</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Initializing camera...</string> + </property> + </widget> + </widget> + <resources/> + <connections/> +</ui> diff --git a/app/SandboxSetup/mainwindow.cpp b/app/SandboxSetup/mainwindow.cpp index dd551fd4ddc501b73487b9ca013d9de20be0560c..2a8eb588231495d32f7cfc95fd3b40f2044b3289 100644 --- a/app/SandboxSetup/mainwindow.cpp +++ b/app/SandboxSetup/mainwindow.cpp @@ -11,18 +11,24 @@ MainWindow::MainWindow(QWidget *parent) : ui->btnNext->setEnabled(false); setup = new SandboxSetup; + init = new InitCamera(setup); mg = new MonitorGui(setup); pg = new ProjectionGui(setup, mg); cf = new CameraFocus(setup); cm = new CroppingMask(setup, mg); bl = new BeamerLocationGui(setup, mg); + applist.push_back(init); applist.push_back(mg); applist.push_back(pg); applist.push_back(cf); applist.push_back(cm); applist.push_back(bl); + for(SubApp* app : applist){ + connect(app, &SubApp::sendNotif, this, &MainWindow::receiveNotif); + } + } MainWindow::~MainWindow() @@ -32,7 +38,7 @@ MainWindow::~MainWindow() void MainWindow::showEvent(QShowEvent *event){ QWidget::showEvent(event); - QTimer::singleShot(0, this, &MainWindow::initCamera); + loadApp(); } void MainWindow::closeEvent(QCloseEvent *event){ @@ -42,6 +48,13 @@ void MainWindow::closeEvent(QCloseEvent *event){ exit_msg("Failed setup at step " + std::to_string(step) + " : " + applist.at(step)->getErrorMessage()); } +void MainWindow::receiveNotif(){ + if(step==0){ + ui->btnNext->setEnabled(true); + nextApp(); + } +} + void MainWindow::exit_msg(std::string msg){ setup->getCamera()->stop(); std::cout << msg << std::endl; @@ -91,12 +104,10 @@ void MainWindow::prevApp(){ } void MainWindow::initCamera(){ - - std::cout << "init camera" << std::endl; - setup->getCamera()->start(); - std::cout << "camera ready" << std::endl; +/* ui->btnNext->setEnabled(true); loadApp(); +*/ } void MainWindow::finishConfig(){ @@ -111,14 +122,14 @@ void MainWindow::finishConfig(){ void MainWindow::on_btnNext_clicked() { - if(step == 0) - ui->btnPrev->setVisible(true); + //if(step == 0) + // ui->btnPrev->setVisible(true); nextApp(); } void MainWindow::on_btnPrev_clicked() { - if(step == 0) - ui->btnPrev->setVisible(false); + //if(step == 0) + // ui->btnPrev->setVisible(false); prevApp(); } diff --git a/app/SandboxSetup/mainwindow.h b/app/SandboxSetup/mainwindow.h index fed42c7f723cb4643ad10203948d496e1b128b09..075380d0b2bdbe2a315921de8faf5ad81afabd57 100644 --- a/app/SandboxSetup/mainwindow.h +++ b/app/SandboxSetup/mainwindow.h @@ -8,6 +8,7 @@ #include "projectiongui.h" #include "qtfullscreen.h" #include "beamerlocationgui.h" +#include "initcamera.h" #include <sandboxSetup.h> #include "subapp.h" @@ -30,6 +31,8 @@ private slots: void on_btnPrev_clicked(); + void receiveNotif(); + protected: void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); @@ -37,6 +40,7 @@ protected: private: Ui::MainWindow *ui; SandboxSetup *setup; + InitCamera *init; MonitorGui *mg; ProjectionGui *pg; CameraFocus *cf; diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp index fa3447b8b54cc11f6e37e6299728b2ef6d08afba..3e86c8fcc01f0321c738396458e2d3d9deb7f72d 100644 --- a/app/SandboxSetup/projectiongui.cpp +++ b/app/SandboxSetup/projectiongui.cpp @@ -9,6 +9,8 @@ ProjectionGui::ProjectionGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *par mg = _mg; ui->setupUi(this); + blueScreen = new QtFullScreen(mg->getResolution(), false); + frameTimer = new QTimer(this); connect(frameTimer, &QTimer::timeout, this, &ProjectionGui::refreshFrame); } @@ -37,10 +39,9 @@ void ProjectionGui::cancelRoutine(){ // Note : Screens should be in extented mode, not mirror (to avoid loop noise from the capture of the screen) void ProjectionGui::on_btnStart_clicked() { - QRect reso = mg->getResolution(); // open blue screen on the selected output cv::Mat blue = cv::Mat(1, 1, CV_8UC3, cv::Scalar(0, 0, 255)); - blueScreen = new QtFullScreen(reso, true); + blueScreen->setGeometry(mg->getResolution()); blueScreen->imShow(blue); cameraUsed = true; @@ -49,8 +50,8 @@ void ProjectionGui::on_btnStart_clicked() } void ProjectionGui::refreshFrame(){ - setup->getCamera()->captureFrame(); - cv::Mat rgb = setup->getCamera()->getRGBFrame(); + setup->getCamera()->capture(); + cv::Mat rgb = setup->getCamera()->getColorFrame(); 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); diff --git a/app/SandboxSetup/qtfullscreen.cpp b/app/SandboxSetup/qtfullscreen.cpp index 3213a0c1083450ae4d74b4e58e5cbb78be0c851d..d6529524a69ff288b24d3d7dc50220ceb4ce164e 100644 --- a/app/SandboxSetup/qtfullscreen.cpp +++ b/app/SandboxSetup/qtfullscreen.cpp @@ -6,6 +6,7 @@ QtFullScreen::QtFullScreen(QRect _resolution, bool _isBorderless, QWidget *paren win = new QDialog; resolution = &_resolution; isBorderless = _isBorderless; + //win->setWindowFlags(Qt::Window); win->setGeometry(*resolution); image = new QLabel(win); @@ -16,6 +17,8 @@ QtFullScreen::QtFullScreen(QRect _resolution, bool _isBorderless, QWidget *paren void QtFullScreen::showEvent(QShowEvent* event){ QWidget::showEvent( event ); + if(win->parent() != 0) + std::cout << "QtFullScreen showEvent : " << win->parent()->objectName().toStdString() << std::endl; if(p != nullptr) p->setFocus(); } @@ -36,8 +39,9 @@ void QtFullScreen::imShow(cv::Mat frame){ QPixmap px = QPixmap::fromImage(src); image->setPixmap(px); - if(isBorderless && !win->windowState().testFlag(Qt::WindowFullScreen)) + if(isBorderless && !win->windowState().testFlag(Qt::WindowFullScreen)){ win->setWindowState(Qt::WindowFullScreen); + } if(!win->isVisible()) win->show(); diff --git a/app/SandboxSetup/subapp.h b/app/SandboxSetup/subapp.h index 4edc4f0a1b8a3eeef4b20165fbfcec48e94a5cde..1549ec8378ab8b3cb65addc387031b4ab230d308 100644 --- a/app/SandboxSetup/subapp.h +++ b/app/SandboxSetup/subapp.h @@ -17,6 +17,9 @@ public: void valideRoutine(); void cancelRoutine(); +signals: + void sendNotif(); + protected: bool endSuccess = false; std::string error_msg; diff --git a/inc/camera.h b/inc/camera.h index 6f68e4c06654b0afe97eec9c82b8f3d620c395b7..15e4b599195b6c7cb689c5f3ef03cfaf0952a325 100644 --- a/inc/camera.h +++ b/inc/camera.h @@ -25,17 +25,17 @@ class Camera{ public: Camera(); - cv::Mat getDepthFrame(){ return matDepth; }; - cv::Mat getRGBFrame(){ return matRGB.clone(); }; + cv::Mat getDepthFrame(){ return matDepth.clone(); }; + cv::Mat getColorFrame(){ return matRGB.clone(); }; void setCroppingMask(cv::Rect mask){ croppingMask = mask; }; cv::Rect getCroppingMask(){ return croppingMask; }; void start(); - void warmingUp(); + void warmUpDepthLens(); void stop(); cv::Point3f deprojectPixelToPoint(float coord[], float z1); cv::Point2i projectPointToPixel(cv::Point3f point3D); - void captureFrame(); + void capture(); void printCroppingMask(); }; diff --git a/inc/sandbox.h b/inc/sandbox.h index 81e4f6f58c40d0e5588fde69b4a8640fcaa6ed12..2588e5a37b089d1d306ab318d66d4f3caf236303 100644 --- a/inc/sandbox.h +++ b/inc/sandbox.h @@ -21,7 +21,7 @@ class Sandbox{ public: Sandbox(); - cv::Mat getRGBFrame(); + cv::Mat getColorFrame(); cv::Mat getDepthFrame(); cv::Mat* adjustProjection(cv::Mat* frame); void showImage(cv::Mat* image); diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index 666b1c1f4411804c30026807f947b33d48fd1ff7..a7783c0b61028b96eec4407c6c8ab0d618da86d5 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -33,9 +33,9 @@ int Beamer::findBeamerFrom(Camera *camera){ while( capturedPoints.size() < MAX_LINEAR_LINE_POINTS ){ // capture frame - camera->captureFrame(); + camera->capture(); depth = camera->getDepthFrame(); - rgb = camera->getRGBFrame(); + rgb = camera->getColorFrame(); // Look for the circle target std::vector<cv::Point3i> circle = findCercleZ(rgb, profil.getContrast(), profil.getBrightness(), profil.getRadiusRatio(), profil.getUpperMinThreshold(), profil.getLowerMinThreshold()); diff --git a/src/components/camera.cpp b/src/components/camera.cpp index dce1c6c5b38b59b836e7d22abf763d283f433541..44442dfae15083f3a92928ee825699420ec91bc4 100644 --- a/src/components/camera.cpp +++ b/src/components/camera.cpp @@ -29,12 +29,12 @@ void Camera::start(){ for (auto i = range.min; i < range.max; i += range.step) if (std::string(sensor.get_option_value_description(RS2_OPTION_VISUAL_PRESET, i)) == "High Density") sensor.set_option(RS2_OPTION_VISUAL_PRESET, i); - warmingUp(); + //warmUpDepthLens(); } // Capture 30 frames to give autoexposure, etc. a chance to settle -void Camera::warmingUp() +void Camera::warmUpDepthLens() { for (int i = 0; i < 30; ++i) { @@ -51,7 +51,7 @@ void Camera::stop(){ } -void Camera::captureFrame(){ +void Camera::capture(){ rs2::align align(RS2_STREAM_DEPTH); auto frameset = pipe.wait_for_frames(); diff --git a/src/lib/sandbox.cpp b/src/lib/sandbox.cpp index 1c74a63a1bb25536ce76a5222b1091e750e6bde1..0284015eb43ecc415e9024655c26697f50b8fdf6 100644 --- a/src/lib/sandbox.cpp +++ b/src/lib/sandbox.cpp @@ -14,13 +14,13 @@ Sandbox::Sandbox(){ * PUBLIC */ -cv::Mat Sandbox::getRGBFrame(){ - camera.captureFrame(); - return camera.getRGBFrame()(camera.getCroppingMask()); +cv::Mat Sandbox::getColorFrame(){ + camera.capture(); + return camera.getColorFrame()(camera.getCroppingMask()); } cv::Mat Sandbox::getDepthFrame(){ - camera.captureFrame(); + camera.capture(); return camera.getDepthFrame()(camera.getCroppingMask()); } diff --git a/src/lib/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp index 246c8258de8c07a17be57839c45cc083d563e603..b78e6da63fb57c5b816cf463eab41bd31c8e4729 100644 --- a/src/lib/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -99,7 +99,7 @@ int SandboxSetup::defaultSetupProjection(){ defaultCaptureBlueScreen(300); cv::Mat frameData = camera.getDepthFrame(); - cv::Mat coloredFrame = camera.getRGBFrame(); + cv::Mat coloredFrame = camera.getColorFrame(); cv::Size s = frameData.size(); cv::Point center(s.width / 2, s.height / 2); @@ -133,7 +133,7 @@ void SandboxSetup::defaultCaptureBlueScreen(int delay){ cv::waitKey(delay); // Take picture - camera.captureFrame(); + camera.capture(); cv::destroyAllWindows(); }