Skip to content
Snippets Groups Projects
Commit 752f2c4f authored by simon.fanetti's avatar simon.fanetti
Browse files

render CameraFocus in another thread

parent 3bbdd584
Branches
Tags
No related merge requests found
#include "camerafocus.h" #include "camerafocus.h"
#include "ui_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) : CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) :
SubApp("Camera focus", "Error", parent), SubApp("Camera focus", "Error", parent),
ui(new Ui::CameraFocus) ui(new Ui::CameraFocus)
...@@ -8,18 +19,23 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent ...@@ -8,18 +19,23 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent
ui->setupUi(this); ui->setupUi(this);
setup = sandbox; setup = sandbox;
mg = _mg; mg = _mg;
myThread = new RefreshFrame(this);
//connect(myThread, &RefreshFrame::finished, myThread, &QObject::deleteLater);
blackScreen = new QtFullScreen(mg->getResolution(), true, this); blackScreen = new QtFullScreen(mg->getResolution(), true, this);
setup->loadFrameProcessProfil(); setup->loadFrameProcessProfil();
initCameraParams(); initCameraParams();
frameTimer = new QTimer(this); frameTimer = new QTimer(this);
connect(frameTimer, &QTimer::timeout, this, &CameraFocus::refreshFrame); connect(frameTimer, &QTimer::timeout, this, &CameraFocus::startCapture);
} }
CameraFocus::~CameraFocus() CameraFocus::~CameraFocus()
{ {
delete frameTimer; delete frameTimer;
delete blackScreen; delete blackScreen;
myThread->quit();
myThread->wait();
delete myThread;
delete ui; delete ui;
} }
...@@ -38,7 +54,7 @@ void CameraFocus::closeEvent(QCloseEvent *event){ ...@@ -38,7 +54,7 @@ void CameraFocus::closeEvent(QCloseEvent *event){
QWidget::closeEvent(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(){ void CameraFocus::valideRoutine(){
...@@ -50,6 +66,10 @@ void CameraFocus::cancelRoutine(){ ...@@ -50,6 +66,10 @@ void CameraFocus::cancelRoutine(){
endSuccess = false; endSuccess = false;
} }
void CameraFocus::startCapture(){
myThread->start();
}
void CameraFocus::refreshFrame(){ void CameraFocus::refreshFrame(){
setup->getCamera()->capture(); setup->getCamera()->capture();
...@@ -61,7 +81,6 @@ void CameraFocus::refreshFrame(){ ...@@ -61,7 +81,6 @@ void CameraFocus::refreshFrame(){
std::vector<cv::Point3i> crc; std::vector<cv::Point3i> crc;
if(profil->getCannyEdgeThreshold() >= 10 && profil->getHoughAccThreshold() >= 20){ 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(); double minDist = rgb.rows / (double)profil->getRadiusRatio();
crc = setup->getBeamer()->findCircles( rgb, crc = setup->getBeamer()->findCircles( rgb,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QDialog> #include <QDialog>
#include <QTimer> #include <QTimer>
#include <QThread>
#include <QAbstractButton> #include <QAbstractButton>
#include <sandboxSetup.h> #include <sandboxSetup.h>
#include "monitorgui.h" #include "monitorgui.h"
...@@ -13,6 +14,7 @@ namespace Ui { ...@@ -13,6 +14,7 @@ namespace Ui {
class CameraFocus; class CameraFocus;
} }
class CameraFocus : public SubApp class CameraFocus : public SubApp
{ {
Q_OBJECT Q_OBJECT
...@@ -20,7 +22,7 @@ class CameraFocus : public SubApp ...@@ -20,7 +22,7 @@ class CameraFocus : public SubApp
public: public:
explicit CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0); explicit CameraFocus(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent = 0);
~CameraFocus(); ~CameraFocus();
void refreshFrame();
void valideRoutine(); void valideRoutine();
void cancelRoutine(); void cancelRoutine();
...@@ -49,17 +51,30 @@ protected: ...@@ -49,17 +51,30 @@ protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
private: private:
class RefreshFrame : public QThread
{
public:
explicit RefreshFrame(CameraFocus *camera);
void run();
private:
CameraFocus *camera;
};
Ui::CameraFocus *ui; Ui::CameraFocus *ui;
SandboxSetup *setup; SandboxSetup *setup;
MonitorGui *mg; MonitorGui *mg;
RefreshFrame *myThread;
QTimer *frameTimer; QTimer *frameTimer;
QtFullScreen *blackScreen; QtFullScreen *blackScreen;
FrameProcessProfil defaultProfil; FrameProcessProfil defaultProfil;
bool displayConstrasts = false; bool displayConstrasts = false;
void refreshFrame(); void startCapture();
void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved); void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved);
void initCameraParams(); void initCameraParams();
}; };
#endif // CAMERAFOCUS_H #endif // CAMERAFOCUS_H
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <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>
<property name="textFormat"> <property name="textFormat">
<enum>Qt::AutoText</enum> <enum>Qt::AutoText</enum>
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>110</x> <x>50</x>
<y>140</y> <y>40</y>
<width>161</width> <width>161</width>
<height>17</height> <height>17</height>
</rect> </rect>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment