diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 13730390e1f20086ccf31b84634d4446e5a42996..f7df73e6e2eeea1729c339bd25c9fecc589f6d9d 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -1,6 +1,17 @@ #include "camerafocus.h" #include "ui_camerafocus.h" + + +CameraFocus::RefreshFrame::RefreshFrame(CameraFocus *_camera) : QThread() { + camera = _camera; +} + +void CameraFocus::RefreshFrame::run() { + camera->refreshFrame(); +} + + CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : SubApp("Camera focus", "Error", parent), ui(new Ui::CameraFocus) @@ -8,18 +19,23 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent ui->setupUi(this); setup = sandbox; mg = _mg; + myThread = new RefreshFrame(this); + //connect(myThread, &RefreshFrame::finished, myThread, &QObject::deleteLater); blackScreen = new QtFullScreen(mg->getResolution(), true, this); setup->loadFrameProcessProfil(); initCameraParams(); frameTimer = new QTimer(this); - connect(frameTimer, &QTimer::timeout, this, &CameraFocus::refreshFrame); + connect(frameTimer, &QTimer::timeout, this, &CameraFocus::startCapture); } CameraFocus::~CameraFocus() { delete frameTimer; delete blackScreen; + myThread->quit(); + myThread->wait(); + delete myThread; delete ui; } @@ -38,7 +54,7 @@ void CameraFocus::closeEvent(QCloseEvent *event){ QWidget::closeEvent(event); } -// TODO : override "checkRoutine" to ensure that the profil makes sense +// TODO : override "checkRoutine" to ensure the profil makes sense void CameraFocus::valideRoutine(){ @@ -50,6 +66,10 @@ void CameraFocus::cancelRoutine(){ endSuccess = false; } +void CameraFocus::startCapture(){ + myThread->start(); +} + void CameraFocus::refreshFrame(){ setup->getCamera()->capture(); @@ -61,7 +81,6 @@ void CameraFocus::refreshFrame(){ std::vector<cv::Point3i> crc; if(profil->getCannyEdgeThreshold() >= 10 && profil->getHoughAccThreshold() >= 20){ - // std::vector<cv::Point3i> Beamer::findCircles(cv::Mat &rgb, double contrast, int brightness, double centersMinDist, int cannyEdgeThreshold, int houghAccThreshold, double minRadius, double maxRadius); double minDist = rgb.rows / (double)profil->getRadiusRatio(); crc = setup->getBeamer()->findCircles( rgb, diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocus.h index e7effd2bebb1c2b5b71971595769719a9543749a..56171394b887f719a8c1a1a61b5b8afdeceea6a3 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocus.h @@ -3,6 +3,7 @@ #include <QDialog> #include <QTimer> +#include <QThread> #include <QAbstractButton> #include <sandboxSetup.h> #include "monitorgui.h" @@ -13,6 +14,7 @@ namespace Ui { class CameraFocus; } + class CameraFocus : public SubApp { Q_OBJECT @@ -20,7 +22,7 @@ class CameraFocus : public SubApp public: explicit CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); ~CameraFocus(); - + void refreshFrame(); void valideRoutine(); void cancelRoutine(); @@ -49,17 +51,30 @@ protected: void closeEvent(QCloseEvent *event); private: + + class RefreshFrame : public QThread + { + public: + explicit RefreshFrame(CameraFocus *camera); + void run(); + + private: + CameraFocus *camera; + }; + Ui::CameraFocus *ui; SandboxSetup *setup; MonitorGui *mg; + RefreshFrame *myThread; QTimer *frameTimer; QtFullScreen *blackScreen; FrameProcessProfil defaultProfil; bool displayConstrasts = false; - void refreshFrame(); + void startCapture(); void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved); void initCameraParams(); }; + #endif // CAMERAFOCUS_H diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index d4fc16b9a482cd05420af2460e8a43b9936d6a8e..436a327d4ec3d785791407da1e053c2947d5207d 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -66,7 +66,7 @@ <item row="2" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> - <string>ratio of circle radius from camera's width</string> + <string>Distance between circles's center based on ratio from camera's width</string> </property> <property name="textFormat"> <enum>Qt::AutoText</enum> diff --git a/app/SandboxSetup/initcamera.ui b/app/SandboxSetup/initcamera.ui index 50ef8e20b6dcfcdf13981d94254ac721b5b1eec0..1f7e11b37a0ed61a41ea96cf5e6fabf7977d1cba 100644 --- a/app/SandboxSetup/initcamera.ui +++ b/app/SandboxSetup/initcamera.ui @@ -16,8 +16,8 @@ <widget class="QLabel" name="label"> <property name="geometry"> <rect> - <x>110</x> - <y>140</y> + <x>50</x> + <y>40</y> <width>161</width> <height>17</height> </rect>