From 320851f03a0a07f0923cbe83167788b30b9cbe32 Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Thu, 4 Jun 2020 21:25:30 +0200 Subject: [PATCH] adapt CameraFocus parameters + add titles in config app --- app/SandboxSetup/beamerlocationgui.cpp | 12 +++- app/SandboxSetup/camerafocus.cpp | 86 ++++++++++++-------------- app/SandboxSetup/camerafocus.h | 13 ++-- app/SandboxSetup/camerafocus.ui | 70 ++++++++++++++++----- app/SandboxSetup/croppingmask.cpp | 2 +- app/SandboxSetup/initcamera.cpp | 2 +- app/SandboxSetup/mainwindow.cpp | 1 + app/SandboxSetup/mainwindow.ui | 30 +++++++-- app/SandboxSetup/monitorgui.cpp | 3 +- app/SandboxSetup/projectiongui.cpp | 2 +- app/SandboxSetup/saveconfiggui.cpp | 3 +- app/SandboxSetup/subapp.cpp | 5 +- app/SandboxSetup/subapp.h | 5 +- inc/beamer.h | 30 +++++---- inc/beamerProjection.h | 1 - src/components/beamer.cpp | 42 +++++++++---- src/tools/sandboxConfig.cpp | 18 ++++-- 17 files changed, 208 insertions(+), 117 deletions(-) diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp index ed095b8..c58637c 100644 --- a/app/SandboxSetup/beamerlocationgui.cpp +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -2,7 +2,7 @@ #include "ui_beamerlocationgui.h" BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent) : - SubApp(parent), + SubApp("Beamer location", "Error", parent), ui(new Ui::BeamerLocationGui) { setup = _setup; @@ -92,7 +92,15 @@ void BeamerLocationGui::routineFrame(){ rgb = camera->getColorFrame(); // Look for the circle target - circle = beamer->findCercleZ(rgb, profil->getContrast(), profil->getBrightness(), profil->getRadiusRatio(), profil->getUpperMinThreshold(), profil->getLowerMinThreshold()); + double minDist = rgb.rows / (double)profil->getRadiusRatio(); + circle = beamer->findCircles( rgb, + profil->getContrast(), + profil->getBrightness(), + minDist, + profil->getCannyEdgeThreshold(), + profil->getHoughAccThreshold(), + profil->getMinRadius(), + profil->getMaxRadius() ); // Show black screen with cross cv::Mat frameImage = beamer->getCrossFrame(cross, capturedPoints.size()+1, beamer->MAX_LINEAR_LINE_POINTS, !circle.empty()); diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 7845814..48978fb 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -2,7 +2,7 @@ #include "ui_camerafocus.h" CameraFocus::CameraFocus(SandboxSetup *sandbox, QWidget *parent) : - SubApp(parent), + SubApp("Camera focus", "Error", parent), ui(new Ui::CameraFocus) { ui->setupUi(this); @@ -53,14 +53,18 @@ void CameraFocus::refreshFrame(){ cv::Mat rgb = setup->getCamera()->getColorFrame(); std::vector<cv::Point3i> crc; - if(profil->getUpperMinThreshold() >= profil->getLowerMinThreshold()){ + 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); - crc = setup->getBeamer()->findCercleZ( rgb, + double minDist = rgb.rows / (double)profil->getRadiusRatio(); + crc = setup->getBeamer()->findCircles( rgb, profil->getContrast(), profil->getBrightness(), - profil->getRadiusRatio(), - profil->getUpperMinThreshold(), - profil->getLowerMinThreshold() ); + minDist, + profil->getCannyEdgeThreshold(), + profil->getHoughAccThreshold(), + profil->getMinRadius(), + profil->getMaxRadius() ); } // Preview image for the user @@ -68,7 +72,7 @@ void CameraFocus::refreshFrame(){ gray = setup->getBeamer()->editContrast(gray, (double)profil->getContrast(), (double)profil->getBrightness()); if(displayConstrasts){ - cvSobel(&gray); + cv::Canny(gray, gray, profil->getCannyEdgeThreshold(), profil->getCannyEdgeThreshold()/2); } cv::cvtColor(gray, rgbFromGray, CV_GRAY2BGR); @@ -91,8 +95,10 @@ void CameraFocus::initCameraParams(){ defaultProfil.setContrast(profil->getContrast()); defaultProfil.setBrightness(profil->getBrightness()); defaultProfil.setRadiusRatio(profil->getRadiusRatio()); - defaultProfil.setUpperMinThreshold(profil->getUpperMinThreshold()); - defaultProfil.setLowerMinThreshold(profil->getLowerMinThreshold()); + defaultProfil.setCannyEdgeThreshold(profil->getCannyEdgeThreshold()); + defaultProfil.setHoughAccThreshold(profil->getHoughAccThreshold()); + defaultProfil.setMinRadius(profil->getMinRadius()); + defaultProfil.setMaxRadius(profil->getMaxRadius()); loadProfil(profil, profil); } @@ -102,14 +108,18 @@ void CameraFocus::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfi profilSaved->setContrast(profilLoaded->getContrast()); profilSaved->setBrightness(profilLoaded->getBrightness()); profilSaved->setRadiusRatio(profilLoaded->getRadiusRatio()); - profilSaved->setUpperMinThreshold(profilLoaded->getUpperMinThreshold()); - profilSaved->setLowerMinThreshold(profilLoaded->getLowerMinThreshold()); + profilSaved->setCannyEdgeThreshold(profilLoaded->getCannyEdgeThreshold()); + profilSaved->setHoughAccThreshold(profilLoaded->getHoughAccThreshold()); + profilSaved->setMinRadius(profilLoaded->getMinRadius()); + profilSaved->setMaxRadius(profilLoaded->getMaxRadius()); ui->dbsbxContrast->setValue(profilLoaded->getContrast()); ui->sbxBrightness->setValue(profilLoaded->getBrightness()); ui->sbxRadiusRatio->setValue(profilLoaded->getRadiusRatio()); - ui->sbxUpperMin->setValue(profilLoaded->getUpperMinThreshold()); - ui->sbxLowerMin->setValue(profilLoaded->getLowerMinThreshold()); + ui->sbxCannyThreshold->setValue(profilLoaded->getCannyEdgeThreshold()); + ui->sbxAccThreshold->setValue(profilLoaded->getHoughAccThreshold()); + ui->dbsbxMinRadius->setValue(profilLoaded->getMinRadius()); + ui->dbsbxMaxRadius->setValue(profilLoaded->getMaxRadius()); } void CameraFocus::on_dbsbxContrast_valueChanged(double arg1) @@ -127,16 +137,6 @@ void CameraFocus::on_sbxRadiusRatio_valueChanged(int arg1) setup->getBeamer()->getProfil()->setRadiusRatio(arg1); } -void CameraFocus::on_sbxUpperMin_valueChanged(int arg1) -{ - setup->getBeamer()->getProfil()->setUpperMinThreshold(arg1); -} - -void CameraFocus::on_sbxLowerMin_valueChanged(int arg1) -{ - setup->getBeamer()->getProfil()->setLowerMinThreshold(arg1); -} - void CameraFocus::on_btnReset_clicked() { @@ -149,32 +149,22 @@ void CameraFocus::on_chbxDisplayContrast_clicked() } -cv::Mat* CameraFocus::cvSobel(cv::Mat *gray){ - - // From : https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html - - int scale = 1; - int delta = 0; - int ddepth = CV_16S; - cv::Mat grad, src_gray = *gray; - - /// Generate grad_x and grad_y - cv::Mat grad_x, grad_y; - cv::Mat abs_grad_x, abs_grad_y; - - /// Gradient X - //Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT ); - cv::Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT ); - cv::convertScaleAbs( grad_x, abs_grad_x ); +void CameraFocus::on_sbxCannyThreshold_valueChanged(int arg1) +{ + setup->getBeamer()->getProfil()->setCannyEdgeThreshold(arg1); +} - /// Gradient Y - //Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT ); - cv::Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT ); - cv::convertScaleAbs( grad_y, abs_grad_y ); +void CameraFocus::on_sbxAccThreshold_valueChanged(int arg1) +{ + setup->getBeamer()->getProfil()->setHoughAccThreshold(arg1); +} - /// Total Gradient (approximate) - cv::addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad ); - grad.copyTo(*gray); +void CameraFocus::on_dbsbxMinRadius_valueChanged(double arg1) +{ + setup->getBeamer()->getProfil()->setMinRadius(arg1); +} - return gray; +void CameraFocus::on_dbsbxMaxRadius_valueChanged(double arg1) +{ + setup->getBeamer()->getProfil()->setMaxRadius(arg1); } diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocus.h index 1e868eb..e893776 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocus.h @@ -31,14 +31,18 @@ private slots: void on_sbxRadiusRatio_valueChanged(int arg1); - void on_sbxUpperMin_valueChanged(int arg1); - - void on_sbxLowerMin_valueChanged(int arg1); - void on_btnReset_clicked(); void on_chbxDisplayContrast_clicked(); + void on_sbxCannyThreshold_valueChanged(int arg1); + + void on_sbxAccThreshold_valueChanged(int arg1); + + void on_dbsbxMinRadius_valueChanged(double arg1); + + void on_dbsbxMaxRadius_valueChanged(double arg1); + protected: void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); @@ -53,7 +57,6 @@ private: void refreshFrame(); void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved); void initCameraParams(); - cv::Mat* cvSobel(cv::Mat *gray); }; #endif // CAMERAFOCUS_H diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index 954c84b..d4fc16b 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>653</width> - <height>611</height> + <height>640</height> </rect> </property> <property name="windowTitle"> @@ -16,10 +16,10 @@ <widget class="QWidget" name="formLayoutWidget"> <property name="geometry"> <rect> - <x>80</x> + <x>60</x> <y>380</y> <width>481</width> - <height>171</height> + <height>231</height> </rect> </property> <layout class="QFormLayout" name="frmlParams"> @@ -82,12 +82,12 @@ <item row="3" column="0"> <widget class="QLabel" name="label_4"> <property name="text"> - <string>Upper minimum contour threshold</string> + <string>Upper Canny threshold</string> </property> </widget> </item> <item row="3" column="1"> - <widget class="QSpinBox" name="sbxUpperMin"> + <widget class="QSpinBox" name="sbxCannyThreshold"> <property name="maximum"> <number>255</number> </property> @@ -96,14 +96,54 @@ <item row="4" column="0"> <widget class="QLabel" name="label_5"> <property name="text"> - <string>Lower minimum contour threshold</string> + <string>Hough accumulator threshold</string> </property> </widget> </item> <item row="4" column="1"> - <widget class="QSpinBox" name="sbxLowerMin"> + <widget class="QSpinBox" name="sbxAccThreshold"> <property name="maximum"> - <number>255</number> + <number>100000</number> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QDoubleSpinBox" name="dbsbxMinRadius"> + <property name="minimum"> + <double>0.010000000000000</double> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Minimum circle radius</string> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>Maximum circle radius</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QDoubleSpinBox" name="dbsbxMaxRadius"> + <property name="minimum"> + <double>0.010000000000000</double> + </property> + <property name="maximum"> + <double>10000.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> </property> </widget> </item> @@ -112,10 +152,10 @@ <widget class="QLabel" name="lblFrame"> <property name="geometry"> <rect> - <x>100</x> + <x>60</x> <y>60</y> - <width>441</width> - <height>281</height> + <width>411</width> + <height>241</height> </rect> </property> <property name="lineWidth"> @@ -134,8 +174,8 @@ <widget class="QPushButton" name="btnReset"> <property name="geometry"> <rect> - <x>530</x> - <y>350</y> + <x>60</x> + <y>330</y> <width>89</width> <height>25</height> </rect> @@ -147,8 +187,8 @@ <widget class="QCheckBox" name="chbxDisplayContrast"> <property name="geometry"> <rect> - <x>80</x> - <y>30</y> + <x>500</x> + <y>60</y> <width>131</width> <height>23</height> </rect> diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 934b5dc..7bff084 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -2,7 +2,7 @@ #include "ui_croppingmask.h" CroppingMask::CroppingMask(SandboxSetup *sandbox, MonitorGui *_mg, QWidget *parent) : - SubApp(parent), + SubApp("Cropping mask", "Error", parent), ui(new Ui::CroppingMask) { diff --git a/app/SandboxSetup/initcamera.cpp b/app/SandboxSetup/initcamera.cpp index 410fe24..4861aea 100644 --- a/app/SandboxSetup/initcamera.cpp +++ b/app/SandboxSetup/initcamera.cpp @@ -18,7 +18,7 @@ void CameraStartThread::run() { InitCamera::InitCamera(SandboxSetup *_setup, QWidget *parent) : - SubApp(parent), + SubApp("Initialize configuration", "Error", parent), ui(new Ui::InitCamera) { setup = _setup; diff --git a/app/SandboxSetup/mainwindow.cpp b/app/SandboxSetup/mainwindow.cpp index ba4bca6..ba08066 100644 --- a/app/SandboxSetup/mainwindow.cpp +++ b/app/SandboxSetup/mainwindow.cpp @@ -97,6 +97,7 @@ void MainWindow::closeApp(){ void MainWindow::loadApp(){ ui->apps->addWidget(applist.at(step)); + ui->lblTitle->setText( QString( (std::to_string(step+1) + ". " + applist.at(step)->getTitle()).c_str() ) ); applist.at(step)->show(); } diff --git a/app/SandboxSetup/mainwindow.ui b/app/SandboxSetup/mainwindow.ui index 7c27178..0b29eb8 100644 --- a/app/SandboxSetup/mainwindow.ui +++ b/app/SandboxSetup/mainwindow.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>800</width> - <height>600</height> + <height>747</height> </rect> </property> <property name="focusPolicy"> @@ -21,9 +21,9 @@ <property name="geometry"> <rect> <x>0</x> - <y>0</y> + <y>50</y> <width>801</width> - <height>511</height> + <height>621</height> </rect> </property> <layout class="QVBoxLayout" name="apps"/> @@ -35,7 +35,7 @@ <property name="geometry"> <rect> <x>650</x> - <y>530</y> + <y>680</y> <width>89</width> <height>25</height> </rect> @@ -51,7 +51,7 @@ <property name="geometry"> <rect> <x>530</x> - <y>530</y> + <y>680</y> <width>89</width> <height>25</height> </rect> @@ -67,7 +67,7 @@ <property name="geometry"> <rect> <x>330</x> - <y>530</y> + <y>680</y> <width>89</width> <height>25</height> </rect> @@ -76,6 +76,24 @@ <string>Finish</string> </property> </widget> + <widget class="QLabel" name="lblTitle"> + <property name="geometry"> + <rect> + <x>30</x> + <y>10</y> + <width>421</width> + <height>31</height> + </rect> + </property> + <property name="font"> + <font> + <pointsize>13</pointsize> + </font> + </property> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> diff --git a/app/SandboxSetup/monitorgui.cpp b/app/SandboxSetup/monitorgui.cpp index 0c7d2d2..37d41d0 100644 --- a/app/SandboxSetup/monitorgui.cpp +++ b/app/SandboxSetup/monitorgui.cpp @@ -2,13 +2,12 @@ #include "ui_monitorgui.h" MonitorGui::MonitorGui(SandboxSetup *_setup, QWidget *parent) : - SubApp(parent), + SubApp("Monitors", "Cancel resolution", parent), ui(new Ui::MonitorGui) { setup = _setup; ui->setupUi(this); resolution = new QRect; - setErrorMessage("Cancel resolution"); std::string path = ".monitors.tmp"; monitors = std::map<std::string, std::vector<std::string>>(); diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp index 8dda847..c7c8dcd 100644 --- a/app/SandboxSetup/projectiongui.cpp +++ b/app/SandboxSetup/projectiongui.cpp @@ -2,7 +2,7 @@ #include "ui_projectiongui.h" ProjectionGui::ProjectionGui(SandboxSetup *_setup, MonitorGui *_mg, QWidget *parent) : - SubApp(parent), + SubApp("Projection setup", "Error", parent), ui(new Ui::ProjectionGui) { setup = _setup; diff --git a/app/SandboxSetup/saveconfiggui.cpp b/app/SandboxSetup/saveconfiggui.cpp index 987ded0..fc4d33a 100644 --- a/app/SandboxSetup/saveconfiggui.cpp +++ b/app/SandboxSetup/saveconfiggui.cpp @@ -2,11 +2,10 @@ #include "ui_saveconfiggui.h" SaveConfigGui::SaveConfigGui(SandboxSetup *_setup, QWidget *parent) : - SubApp(parent), + SubApp("Finish configuration", "Failed to save configuration", parent), ui(new Ui::SaveConfigGui) { setup = _setup; - this->setErrorMessage("Failed to save configuration"); ui->setupUi(this); } diff --git a/app/SandboxSetup/subapp.cpp b/app/SandboxSetup/subapp.cpp index 069a876..87cfe32 100644 --- a/app/SandboxSetup/subapp.cpp +++ b/app/SandboxSetup/subapp.cpp @@ -1,8 +1,9 @@ #include "subapp.h" -SubApp::SubApp(QWidget *parent) : QWidget(parent) +SubApp::SubApp(std::string _title, std::string msg, QWidget *parent) : QWidget(parent) { - error_msg = "Error"; + error_msg = msg; + title = _title; } SubApp::~SubApp() diff --git a/app/SandboxSetup/subapp.h b/app/SandboxSetup/subapp.h index b016f6a..87be1c9 100644 --- a/app/SandboxSetup/subapp.h +++ b/app/SandboxSetup/subapp.h @@ -8,11 +8,11 @@ class SubApp : public QWidget Q_OBJECT public: - explicit SubApp(QWidget *parent = 0); + explicit SubApp(std::string _title, std::string msg, QWidget *parent = 0); ~SubApp(); bool getEndState(){ return endSuccess; }; std::string getErrorMessage(){ return error_msg; }; - void setErrorMessage(std::string msg){ error_msg = msg; }; + std::string getTitle(){ return title; }; virtual bool checkRoutine(); virtual void valideRoutine(); virtual void cancelRoutine(); @@ -23,6 +23,7 @@ signals: protected: bool endSuccess = false; std::string error_msg; + std::string title; }; #endif // SUBAPP_H diff --git a/inc/beamer.h b/inc/beamer.h index 15196d8..c0319d4 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -11,16 +11,20 @@ class FrameProcessProfil{ // radius of the circle based on the width of the frame, where : // radius = frame.width / ratioRadius int ratioRadius; // [1, n] - int upperMinThreshold; // [lowerMin, 255] the strongest the contrast in the image is, the higher this param should be - int lowerMinThreshold; // [0, upperMin] should be set way lower than upperMin if cicles have weak contrasts at their edges - + int cannyEdgeThreshold; // [0, 255] the strongest the contrast in the image is, the higher this param should be + int houghAccThreshold; // [0, n] should be set way lower than upperMin if cicles have weak contrasts at their edges + double minRadius; + double maxRadius; + public: - FrameProcessProfil(double c=1.0, int b=0, int r=8, int up=200, int low=100){ + FrameProcessProfil(double c=1.0, int b=0, int r=8, int cannyThreshold=200, int accThreshold=100, double minR=0.0, double maxR=0.0){ contrast = c; brightness = b; ratioRadius = r; - upperMinThreshold = up; - lowerMinThreshold = low; + cannyEdgeThreshold = cannyThreshold; + houghAccThreshold = accThreshold; + minRadius = minR; + maxRadius = maxR; }; double getContrast(){ return contrast; }; void setContrast(double c){ contrast = c; }; @@ -28,10 +32,14 @@ class FrameProcessProfil{ void setBrightness(int b){ brightness = b; }; int getRadiusRatio(){ return ratioRadius; }; void setRadiusRatio(int r){ ratioRadius = r; }; - int getUpperMinThreshold(){ return upperMinThreshold; }; - void setUpperMinThreshold(int up){ upperMinThreshold = up; }; - int getLowerMinThreshold(){ return lowerMinThreshold; }; - void setLowerMinThreshold(int low){ lowerMinThreshold = low; }; + int getCannyEdgeThreshold(){ return cannyEdgeThreshold; }; + void setCannyEdgeThreshold(int cannyThreshold){ cannyEdgeThreshold = cannyThreshold; }; + int getHoughAccThreshold(){ return houghAccThreshold; }; + void setHoughAccThreshold(int accThreshold){ houghAccThreshold = accThreshold; }; + double getMinRadius(){ return minRadius; }; + void setMinRadius(double min){ minRadius = min; }; + double getMaxRadius(){ return maxRadius; }; + void setMaxRadius(double max){ maxRadius = max; }; }; @@ -73,7 +81,7 @@ class Beamer{ cv::Mat getCrossFrame(cv::Point2i projectedCross, int step, int max, bool circlesFound); cv::Point3d approximatePosition(std::vector<cv::Point3d> *bases, std::vector<cv::Point3d> *directions); void findLinearLineFrom(std::vector<cv::Point3f> *capturedPoints, std::vector<cv::Point3d> *bases, std::vector<cv::Point3d> *directions); - std::vector<cv::Point3i> findCercleZ(cv::Mat &rgb, double contrast, int brightness, int ratioRadius, int upperMinThreshold, int lowerMinThreshold); + std::vector<cv::Point3i> findCircles(cv::Mat &rgb, double contrast, int brightness, double centersMinDist, int cannyEdgeThreshold, int houghAccThreshold, double minRadius, double maxRadius); void printPosition(); }; diff --git a/inc/beamerProjection.h b/inc/beamerProjection.h index 18a019c..5f756ad 100644 --- a/inc/beamerProjection.h +++ b/inc/beamerProjection.h @@ -7,7 +7,6 @@ class BeamerProjection{ private: - const char *wndname = (char *)"Sandbox"; cv::Mat adjustingMatrix; cv::Point2i adjustPixel(int i, int j, float z, Camera camera, cv::Point3f beamer); diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index a7783c0..96a3358 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -38,10 +38,18 @@ int Beamer::findBeamerFrom(Camera *camera){ 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()); + double minDist = rgb.rows / (double)profil.getRadiusRatio(); + std::vector<cv::Point3i> circles = findCircles( rgb, + profil.getContrast(), + profil.getBrightness(), + minDist, + profil.getCannyEdgeThreshold(), + profil.getHoughAccThreshold(), + profil.getMinRadius(), + profil.getMaxRadius() ); // Show black screen with cross - cv::Mat frameImage = getCrossFrame(cross, capturedPoints.size()+1, MAX_LINEAR_LINE_POINTS, !circle.empty()); + cv::Mat frameImage = getCrossFrame(cross, capturedPoints.size()+1, MAX_LINEAR_LINE_POINTS, !circles.empty()); cv::imshow(wname, frameImage); @@ -53,8 +61,8 @@ int Beamer::findBeamerFrom(Camera *camera){ return 1; } else if (keyCode == ' '){ - if(!circle.empty()){ - capturedPoints.push_back( deprojectPixel(circle.at(0), &depth, camera) ); + if(!circles.empty()){ + capturedPoints.push_back( deprojectPixel(circles.at(0), &depth, camera) ); } } } @@ -209,8 +217,8 @@ cv::Mat Beamer::editContrast(cv::Mat image, double contrast, int brightness){ return new_image; } -std::vector<cv::Point3i> Beamer::findCercleZ(cv::Mat &rgb, double contrast, int brightness, int ratioRadius, int upperMinThreshold, int lowerMinThreshold) -{ +std::vector<cv::Point3i> Beamer::findCircles(cv::Mat &rgb, double contrast, int brightness, double centersMinDist, int cannyEdgeThreshold, int houghAccThreshold, double minRadius, double maxRadius){ + cv::Mat src_gray; cv::cvtColor(rgb, src_gray, CV_BGR2GRAY); /// Reduce the noise so we avoid false circle detection @@ -219,19 +227,29 @@ std::vector<cv::Point3i> Beamer::findCercleZ(cv::Mat &rgb, double contrast, int circles.clear(); src_gray = editContrast(src_gray, (double)contrast, (double)brightness); + + //cv::HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, minRadius, 75, 50, 0, 0); + // double minDist = src_gray.rows / (double)ratioRadius; + /// Apply the Hough Transform to find the circles - //source, output, method, inverse ratio of resolution, Minimum distance between detected centers, threeshold canny, threeshold center, min radius, max radius - //cv::HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, minRadius, 75, 50, 0, 0); - double minRadius = src_gray.rows / (double)ratioRadius; - cv::HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, minRadius, (double)upperMinThreshold, (double)lowerMinThreshold, 0, 0); + // source, output, method, inverse ratio of resolution, Minimum distance between detected centers, threeshold canny, threeshold center, min radius, max radius + // dp : Inverse resolution for the accumulator matrixe => image_resolution * dp = acc_resolution + // min_dist : Minimal distance between the detected centers + // param_1 : Upper threshold of the canny edge detector, determines if a pixel is an edge + // param_2 : Threshold for the center detection, after the accumulator is complet, threshold to keep only the possible centers + // min_radius : Min radius of the circles drew on the accumulator + // max_radius : Max radius of the circles drew on the accumulator + cv::HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, centersMinDist, (double)cannyEdgeThreshold, (double)houghAccThreshold, minRadius, maxRadius); + //doit tester si le cercle est bon (rayon); std::vector<cv::Point3i> result; if (!circles.empty()) { - cv::Vec3f first = circles[0]; - result.push_back( cv::Point3i(round(first[0]), round(first[1]), round(first[2])) ); + for(cv::Vec3f circle: circles){ + result.push_back( cv::Point3i(round(circle[0]), round(circle[1]), round(circle[2])) ); + } } return result; } diff --git a/src/tools/sandboxConfig.cpp b/src/tools/sandboxConfig.cpp index 548e945..a903269 100644 --- a/src/tools/sandboxConfig.cpp +++ b/src/tools/sandboxConfig.cpp @@ -102,8 +102,10 @@ int SandboxConfig::saveFrameProcessProfil(char *path, FrameProcessProfil profil) val["contrast"] = profil.getContrast(); val["brightness"] = profil.getBrightness(); val["radiusRatio"] = profil.getRadiusRatio(); - val["upperMinThreshold"] = profil.getUpperMinThreshold(); - val["lowerMinThreshold"] = profil.getLowerMinThreshold(); + val["cannyEdgeThreshold"] = profil.getCannyEdgeThreshold(); + val["houghAccThreshold"] = profil.getHoughAccThreshold(); + val["minRadius"] = profil.getMinRadius(); + val["maxRadius"] = profil.getMaxRadius(); YAML::Node config; try{ @@ -283,8 +285,10 @@ int SandboxConfig::loadFrameProcessProfil(char *path, FrameProcessProfil *profil if(!( config[PROCESSPROFIL]["contrast"] && config[PROCESSPROFIL]["brightness"] && config[PROCESSPROFIL]["radiusRatio"] && - config[PROCESSPROFIL]["upperMinThreshold"] && - config[PROCESSPROFIL]["lowerMinThreshold"] + config[PROCESSPROFIL]["cannyEdgeThreshold"] && + config[PROCESSPROFIL]["houghAccThreshold"] && + config[PROCESSPROFIL]["minRadius"] && + config[PROCESSPROFIL]["maxRadius"] )){ return 2; } @@ -292,8 +296,10 @@ int SandboxConfig::loadFrameProcessProfil(char *path, FrameProcessProfil *profil profil->setContrast(config[PROCESSPROFIL]["contrast"].as<double>()); profil->setBrightness(config[PROCESSPROFIL]["brightness"].as<int>()); profil->setRadiusRatio(config[PROCESSPROFIL]["radiusRatio"].as<int>()); - profil->setUpperMinThreshold(config[PROCESSPROFIL]["upperMinThreshold"].as<int>()); - profil->setLowerMinThreshold(config[PROCESSPROFIL]["lowerMinThreshold"].as<int>()); + profil->setCannyEdgeThreshold(config[PROCESSPROFIL]["cannyEdgeThreshold"].as<int>()); + profil->setHoughAccThreshold(config[PROCESSPROFIL]["houghAccThreshold"].as<int>()); + profil->setMinRadius(config[PROCESSPROFIL]["minRadius"].as<double>()); + profil->setMaxRadius(config[PROCESSPROFIL]["maxRadius"].as<double>()); return 0; } -- GitLab