From 752f2c4f876493db47d0b34dd150e5b967202a7c Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Fri, 5 Jun 2020 18:39:55 +0200 Subject: [PATCH] render CameraFocus in another thread --- app/SandboxSetup/camerafocus.cpp | 25 ++++++++++++++++++++++--- app/SandboxSetup/camerafocus.h | 19 +++++++++++++++++-- app/SandboxSetup/camerafocus.ui | 2 +- app/SandboxSetup/initcamera.ui | 4 ++-- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 1373039..f7df73e 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 e7effd2..5617139 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 d4fc16b..436a327 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 50ef8e2..1f7e11b 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> -- GitLab