From 8e184f1f84772b755022e6ddd10e0fd16d26fad7 Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Tue, 9 Jun 2020 23:03:37 +0200 Subject: [PATCH] add sliders and adapt params in CameraFocus --- app/SandboxSetup/beamerlocationgui.cpp | 20 +- app/SandboxSetup/camerafocus.cpp | 100 +++++-- app/SandboxSetup/camerafocus.h | 26 +- app/SandboxSetup/camerafocus.ui | 393 ++++++++++++++++--------- app/SandboxSetup/croppingmask.ui | 32 +- inc/beamer.h | 34 +-- src/components/beamer.cpp | 12 +- src/tools/sandboxConfig.cpp | 22 +- 8 files changed, 433 insertions(+), 206 deletions(-) diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp index aa7e0f2..644e1de 100644 --- a/app/SandboxSetup/beamerlocationgui.cpp +++ b/app/SandboxSetup/beamerlocationgui.cpp @@ -88,15 +88,17 @@ void BeamerLocationGui::routineFrame(){ rgb = camera->getColorFrame(); // Look for the circle target - double minDist = rgb.rows / (double)profil->getRadiusRatio(); - circle = beamer->findCircles( rgb, - profil->getContrast(), - profil->getBrightness(), - minDist, - profil->getCannyEdgeThreshold(), - profil->getHoughAccThreshold(), - profil->getMinRadius(), - profil->getMaxRadius() ); + double minDist = rgb.cols / (double)profil->getMinDistance(); + double minRadius = (profil->getMinRadius()>0) ? rgb.cols/(double)profil->getMinRadius() : 0; + double maxRadius = (profil->getMaxRadius()>0) ? rgb.cols/(double)profil->getMaxRadius() : 0; + circle = beamer->findCircles( rgb, + profil->getContrast(), + profil->getBrightness(), + minDist, + profil->getCannyEdgeThreshold(), + profil->getHoughAccThreshold(), + minRadius, + maxRadius ); // preview from the camera's POV cv::Mat gray, frameDisplayed; diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 49eeb61..252850e 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -85,17 +85,19 @@ void CameraFocus::refreshFrame(){ cv::Mat rgb = setup->getCamera()->getColorFrame(); std::vector<cv::Point3i> crc; - if(profil->getCannyEdgeThreshold() >= 2 && profil->getHoughAccThreshold() >= 10){ + if(profil->getCannyEdgeThreshold() > 0 && profil->getHoughAccThreshold() > 0){ - double minDist = rgb.rows / (double)profil->getRadiusRatio(); + double minDist = rgb.cols / (double)profil->getMinDistance(); + double minRadius = (profil->getMinRadius()>0) ? rgb.cols/(double)profil->getMinRadius() : 0; + double maxRadius = (profil->getMaxRadius()>0) ? rgb.cols/(double)profil->getMaxRadius() : 0; crc = setup->getBeamer()->findCircles( rgb, profil->getContrast(), profil->getBrightness(), minDist, profil->getCannyEdgeThreshold(), profil->getHoughAccThreshold(), - profil->getMinRadius(), - profil->getMaxRadius() ); + minRadius, + maxRadius ); } // Preview image for the user @@ -127,74 +129,122 @@ void CameraFocus::initCameraParams(){ FrameProcessProfil *profil = setup->getBeamer()->getProfil(); - defaultProfil.setContrast(profil->getContrast()); + /*defaultProfil.setContrast(profil->getContrast()); defaultProfil.setBrightness(profil->getBrightness()); - defaultProfil.setRadiusRatio(profil->getRadiusRatio()); + defaultProfil.setMinDistance(profil->getMinDistance()); defaultProfil.setCannyEdgeThreshold(profil->getCannyEdgeThreshold()); defaultProfil.setHoughAccThreshold(profil->getHoughAccThreshold()); defaultProfil.setMinRadius(profil->getMinRadius()); defaultProfil.setMaxRadius(profil->getMaxRadius()); - - loadProfil(profil, profil); +*/ + loadProfil(profil, &defaultProfil); } void CameraFocus::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved){ profilSaved->setContrast(profilLoaded->getContrast()); profilSaved->setBrightness(profilLoaded->getBrightness()); - profilSaved->setRadiusRatio(profilLoaded->getRadiusRatio()); + profilSaved->setMinDistance(profilLoaded->getMinDistance()); profilSaved->setCannyEdgeThreshold(profilLoaded->getCannyEdgeThreshold()); profilSaved->setHoughAccThreshold(profilLoaded->getHoughAccThreshold()); profilSaved->setMinRadius(profilLoaded->getMinRadius()); profilSaved->setMaxRadius(profilLoaded->getMaxRadius()); - ui->dbsbxContrast->setValue(profilLoaded->getContrast()); + ui->sbxContrast->setValue(profilLoaded->getContrast()); ui->sbxBrightness->setValue(profilLoaded->getBrightness()); - ui->sbxRadiusRatio->setValue(profilLoaded->getRadiusRatio()); + ui->sbxMinDistance->setValue(profilLoaded->getMinDistance()); ui->sbxCannyThreshold->setValue(profilLoaded->getCannyEdgeThreshold()); ui->sbxAccThreshold->setValue(profilLoaded->getHoughAccThreshold()); - ui->dbsbxMinRadius->setValue(profilLoaded->getMinRadius()); - ui->dbsbxMaxRadius->setValue(profilLoaded->getMaxRadius()); + ui->sbxMinRadius->setValue(profilLoaded->getMinRadius()); + ui->sbxMaxRadius->setValue(profilLoaded->getMaxRadius()); } -void CameraFocus::on_dbsbxContrast_valueChanged(double arg1) +void CameraFocus::on_btnReset_clicked() +{ + loadProfil(&defaultProfil, setup->getBeamer()-> getProfil()); +} + +void CameraFocus::on_sldContrast_sliderMoved(int position) +{ + double val = position/100.0; + setup->getBeamer()->getProfil()->setContrast(val); + ui->sbxContrast->setValue(val); +} + +void CameraFocus::on_sbxContrast_valueChanged(double arg1) { setup->getBeamer()->getProfil()->setContrast(arg1); + ui->sldContrast->setValue((int)(arg1*100)); +} + +void CameraFocus::on_sldBrightness_sliderMoved(int position) +{ + setup->getBeamer()->getProfil()->setBrightness(position); + ui->sbxBrightness->setValue(position); } void CameraFocus::on_sbxBrightness_valueChanged(int arg1) { setup->getBeamer()->getProfil()->setBrightness(arg1); + ui->sldBrightness->setValue(arg1); } -void CameraFocus::on_sbxRadiusRatio_valueChanged(int arg1) +void CameraFocus::on_sldMinDistance_sliderMoved(int position) { - setup->getBeamer()->getProfil()->setRadiusRatio(arg1); + setup->getBeamer()->getProfil()->setMinDistance((uint)position); + ui->sbxMinDistance->setValue(position); } - -void CameraFocus::on_btnReset_clicked() +void CameraFocus::on_sbxMinDistance_valueChanged(int arg1) { - loadProfil(&defaultProfil, setup->getBeamer()-> getProfil()); + setup->getBeamer()->getProfil()->setMinDistance((uint)arg1); + ui->sldMinDistance->setValue(arg1); } +void CameraFocus::on_sldCannyThreshold_sliderMoved(int position) +{ + setup->getBeamer()->getProfil()->setCannyEdgeThreshold((uint)position); + ui->sbxCannyThreshold->setValue(position); +} void CameraFocus::on_sbxCannyThreshold_valueChanged(int arg1) { - setup->getBeamer()->getProfil()->setCannyEdgeThreshold(arg1); + setup->getBeamer()->getProfil()->setCannyEdgeThreshold((uint)arg1); + ui->sldCannyThreshold->setValue(arg1); +} + +void CameraFocus::on_sldAccThreshold_sliderMoved(int position) +{ + setup->getBeamer()->getProfil()->setHoughAccThreshold((uint)position); + ui->sbxAccThreshold->setValue(position); } void CameraFocus::on_sbxAccThreshold_valueChanged(int arg1) { - setup->getBeamer()->getProfil()->setHoughAccThreshold(arg1); + setup->getBeamer()->getProfil()->setHoughAccThreshold((uint)arg1); + ui->sldAccThreshold->setValue(arg1); +} + +void CameraFocus::on_sldMinRadius_sliderMoved(int position) +{ + setup->getBeamer()->getProfil()->setMinRadius((uint)position); + ui->sbxMinRadius->setValue(position); +} + +void CameraFocus::on_sbxMinRadius_valueChanged(int arg1) +{ + setup->getBeamer()->getProfil()->setMinRadius((uint)arg1); + ui->sldMinRadius->setValue(arg1); } -void CameraFocus::on_dbsbxMinRadius_valueChanged(double arg1) +void CameraFocus::on_sldMaxRadius_sliderMoved(int position) { - setup->getBeamer()->getProfil()->setMinRadius(arg1); + setup->getBeamer()->getProfil()->setMaxRadius((uint)position); + ui->sbxMaxRadius->setValue(position); } -void CameraFocus::on_dbsbxMaxRadius_valueChanged(double arg1) +void CameraFocus::on_sbxMaxRadius_valueChanged(int arg1) { - setup->getBeamer()->getProfil()->setMaxRadius(arg1); + setup->getBeamer()->getProfil()->setMaxRadius((uint)arg1); + ui->sldMaxRadius->setValue(arg1); } diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocus.h index bcc9d78..473ab0f 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocus.h @@ -28,21 +28,35 @@ public: private slots: - void on_dbsbxContrast_valueChanged(double arg1); - void on_sbxBrightness_valueChanged(int arg1); - void on_sbxRadiusRatio_valueChanged(int arg1); - void on_btnReset_clicked(); void on_sbxCannyThreshold_valueChanged(int arg1); void on_sbxAccThreshold_valueChanged(int arg1); - void on_dbsbxMinRadius_valueChanged(double arg1); + void on_sldContrast_sliderMoved(int position); + + void on_sbxContrast_valueChanged(double arg1); + + void on_sldBrightness_sliderMoved(int position); + + void on_sldMinDistance_sliderMoved(int position); + + void on_sbxMinDistance_valueChanged(int arg1); + + void on_sldCannyThreshold_sliderMoved(int position); + + void on_sldAccThreshold_sliderMoved(int position); + + void on_sldMinRadius_sliderMoved(int position); + + void on_sbxMinRadius_valueChanged(int arg1); + + void on_sldMaxRadius_sliderMoved(int position); - void on_dbsbxMaxRadius_valueChanged(double arg1); + void on_sbxMaxRadius_valueChanged(int arg1); protected: void showEvent(QShowEvent *event); diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index 2bdba80..20a20b1 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -13,33 +13,143 @@ <property name="windowTitle"> <string>Focus</string> </property> - <widget class="QWidget" name="formLayoutWidget"> + <widget class="QLabel" name="lblFrameColor"> <property name="geometry"> <rect> - <x>100</x> - <y>360</y> - <width>611</width> - <height>231</height> + <x>20</x> + <y>70</y> + <width>381</width> + <height>211</height> </rect> </property> - <layout class="QFormLayout" name="frmlParams"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> + <property name="lineWidth"> + <number>3</number> + </property> + <property name="text"> + <string/> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + <property name="wordWrap"> + <bool>false</bool> + </property> + </widget> + <widget class="QPushButton" name="btnReset"> + <property name="geometry"> + <rect> + <x>680</x> + <y>310</y> + <width>89</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Reset</string> + </property> + </widget> + <widget class="QLabel" name="lblFrameCanny"> + <property name="geometry"> + <rect> + <x>410</x> + <y>70</y> + <width>381</width> + <height>211</height> + </rect> + </property> + <property name="lineWidth"> + <number>3</number> + </property> + <property name="text"> + <string/> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + <property name="wordWrap"> + <bool>false</bool> + </property> + </widget> + <widget class="QLabel" name="label_8"> + <property name="geometry"> + <rect> + <x>20</x> + <y>40</y> + <width>161</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Contrast + Brightness :</string> + </property> + </widget> + <widget class="QLabel" name="label_9"> + <property name="geometry"> + <rect> + <x>420</x> + <y>40</y> + <width>161</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>With Canny filter :</string> + </property> + </widget> + <widget class="QWidget" name="gridLayoutWidget"> + <property name="geometry"> + <rect> + <x>60</x> + <y>350</y> + <width>671</width> + <height>281</height> + </rect> + </property> + <layout class="QGridLayout" name="glytParams"> + <item row="3" column="2"> + <widget class="QSpinBox" name="sbxCannyThreshold"> + <property name="maximum"> + <number>255</number> + </property> + <property name="value"> + <number>100</number> + </property> + </widget> + </item> + <item row="4" column="2"> + <widget class="QSpinBox" name="sbxAccThreshold"> + <property name="maximum"> + <number>300</number> + </property> + <property name="value"> + <number>50</number> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="label_6"> <property name="text"> - <string>Contrast</string> + <string>Minimum circle radius (divisor from the camera's width)</string> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QDoubleSpinBox" name="dbsbxContrast"> + <item row="2" column="2"> + <widget class="QSpinBox" name="sbxMinDistance"> <property name="minimum"> - <double>0.010000000000000</double> + <number>1</number> </property> <property name="maximum"> - <double>255.000000000000000</double> + <number>20</number> </property> - <property name="singleStep"> - <double>0.010000000000000</double> + <property name="value"> + <number>8</number> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Contrast</string> </property> </widget> </item> @@ -50,7 +160,14 @@ </property> </widget> </item> - <item row="1" column="1"> + <item row="3" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Upper Canny threshold</string> + </property> + </widget> + </item> + <item row="1" column="2"> <widget class="QSpinBox" name="sbxBrightness"> <property name="minimum"> <number>-255</number> @@ -63,10 +180,26 @@ </property> </widget> </item> + <item row="0" column="2"> + <widget class="QDoubleSpinBox" name="sbxContrast"> + <property name="minimum"> + <double>0.010000000000000</double> + </property> + <property name="maximum"> + <double>255.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + <property name="value"> + <double>1.000000000000000</double> + </property> + </widget> + </item> <item row="2" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> - <string>Distance between circles's center based on ratio from camera's width</string> + <string>Minimum distance between circles's center (divisor from the camera's width)</string> </property> <property name="textFormat"> <enum>Qt::AutoText</enum> @@ -76,162 +209,154 @@ </property> </widget> </item> - <item row="2" column="1"> - <widget class="QSpinBox" name="sbxRadiusRatio"/> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_4"> + <item row="4" column="0"> + <widget class="QLabel" name="label_5"> <property name="text"> - <string>Upper Canny threshold</string> + <string>Hough accumulator threshold</string> </property> </widget> </item> - <item row="3" column="1"> - <widget class="QSpinBox" name="sbxCannyThreshold"> + <item row="0" column="1"> + <widget class="QSlider" name="sldContrast"> + <property name="minimum"> + <number>0</number> + </property> <property name="maximum"> - <number>255</number> + <number>500</number> + </property> + <property name="value"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_5"> + <item row="6" column="0"> + <widget class="QLabel" name="label_7"> <property name="text"> - <string>Hough accumulator threshold</string> + <string>Maximum circle radius (divisor from the camera's width)</string> </property> </widget> </item> - <item row="4" column="1"> - <widget class="QSpinBox" name="sbxAccThreshold"> + <item row="1" column="1"> + <widget class="QSlider" name="sldBrightness"> + <property name="minimum"> + <number>-255</number> + </property> <property name="maximum"> - <number>100000</number> + <number>255</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="5" column="1"> - <widget class="QDoubleSpinBox" name="dbsbxMinRadius"> + <item row="3" column="1"> + <widget class="QSlider" name="sldCannyThreshold"> + <property name="maximum"> + <number>255</number> + </property> + <property name="value"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="5" column="2"> + <widget class="QSpinBox" name="sbxMinRadius"> <property name="minimum"> - <double>0.010000000000000</double> + <number>1</number> </property> <property name="maximum"> - <double>10000.000000000000000</double> + <number>20</number> </property> - <property name="singleStep"> - <double>0.010000000000000</double> + <property name="value"> + <number>10</number> </property> </widget> </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>Minimum circle radius</string> + <item row="6" column="2"> + <widget class="QSpinBox" name="sbxMaxRadius"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>20</number> + </property> + <property name="value"> + <number>2</number> </property> </widget> </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>Maximum circle radius</string> + <item row="5" column="1"> + <widget class="QSlider" name="sldMinRadius"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>20</number> + </property> + <property name="value"> + <number>10</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> <item row="6" column="1"> - <widget class="QDoubleSpinBox" name="dbsbxMaxRadius"> + <widget class="QSlider" name="sldMaxRadius"> <property name="minimum"> - <double>0.010000000000000</double> + <number>1</number> </property> <property name="maximum"> - <double>10000.000000000000000</double> + <number>20</number> </property> - <property name="singleStep"> - <double>0.010000000000000</double> + <property name="value"> + <number>2</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QSlider" name="sldMinDistance"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>20</number> + </property> + <property name="value"> + <number>8</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QSlider" name="sldAccThreshold"> + <property name="maximum"> + <number>300</number> + </property> + <property name="value"> + <number>50</number> + </property> + <property name="sliderPosition"> + <number>50</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </item> </layout> </widget> - <widget class="QLabel" name="lblFrameColor"> - <property name="geometry"> - <rect> - <x>20</x> - <y>70</y> - <width>381</width> - <height>211</height> - </rect> - </property> - <property name="lineWidth"> - <number>3</number> - </property> - <property name="text"> - <string/> - </property> - <property name="scaledContents"> - <bool>true</bool> - </property> - <property name="wordWrap"> - <bool>false</bool> - </property> - </widget> - <widget class="QPushButton" name="btnReset"> - <property name="geometry"> - <rect> - <x>680</x> - <y>310</y> - <width>89</width> - <height>25</height> - </rect> - </property> - <property name="text"> - <string>Reset</string> - </property> - </widget> - <widget class="QLabel" name="lblFrameCanny"> - <property name="geometry"> - <rect> - <x>410</x> - <y>70</y> - <width>381</width> - <height>211</height> - </rect> - </property> - <property name="lineWidth"> - <number>3</number> - </property> - <property name="text"> - <string/> - </property> - <property name="scaledContents"> - <bool>true</bool> - </property> - <property name="wordWrap"> - <bool>false</bool> - </property> - </widget> - <widget class="QLabel" name="label_8"> - <property name="geometry"> - <rect> - <x>20</x> - <y>40</y> - <width>161</width> - <height>17</height> - </rect> - </property> - <property name="text"> - <string>Contrast + Brightness :</string> - </property> - </widget> - <widget class="QLabel" name="label_9"> - <property name="geometry"> - <rect> - <x>420</x> - <y>40</y> - <width>161</width> - <height>17</height> - </rect> - </property> - <property name="text"> - <string>With Canny filter :</string> - </property> - </widget> </widget> <resources/> <connections/> diff --git a/app/SandboxSetup/croppingmask.ui b/app/SandboxSetup/croppingmask.ui index b366809..3a09848 100644 --- a/app/SandboxSetup/croppingmask.ui +++ b/app/SandboxSetup/croppingmask.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>635</width> - <height>442</height> + <height>537</height> </rect> </property> <property name="windowTitle"> @@ -44,6 +44,36 @@ </layout> </widget> </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>40</x> + <y>370</y> + <width>161</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Instructions :</string> + </property> + </widget> + <widget class="QTextEdit" name="textEdit"> + <property name="geometry"> + <rect> + <x>60</x> + <y>400</y> + <width>441</width> + <height>121</height> + </rect> + </property> + <property name="html"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">At this point, the beamer and the blue screen should be set correctly. So now we want to determine the edges of the blue screen. To do that, be sure to have a flat surface to have a clean blue rectangle projected. (ie. you can use a cardboard as support). Then drag the corners to match the bluescreen's edges.</p></body></html></string> + </property> + </widget> </widget> <resources/> <connections/> diff --git a/inc/beamer.h b/inc/beamer.h index c0319d4..203743a 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -10,17 +10,17 @@ class FrameProcessProfil{ int brightness; // [-255, 255] // radius of the circle based on the width of the frame, where : // radius = frame.width / ratioRadius - int ratioRadius; // [1, n] - 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; + uint minDistance; // [1, n] + uint cannyEdgeThreshold; // [0, 255] the strongest the contrast in the image is, the higher this param should be + uint houghAccThreshold; // [0, n] should be set way lower than upperMin if cicles have weak contrasts at their edges + uint minRadius; + uint maxRadius; public: - 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){ + FrameProcessProfil(double c=1.0, int b=0, int d=8, uint cannyThreshold=100, uint accThreshold=50, uint minR=10, uint maxR=2){ contrast = c; brightness = b; - ratioRadius = r; + minDistance = d; cannyEdgeThreshold = cannyThreshold; houghAccThreshold = accThreshold; minRadius = minR; @@ -30,16 +30,16 @@ class FrameProcessProfil{ void setContrast(double c){ contrast = c; }; int getBrightness(){ return brightness; }; void setBrightness(int b){ brightness = b; }; - int getRadiusRatio(){ return ratioRadius; }; - void setRadiusRatio(int r){ ratioRadius = r; }; - 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; }; + uint getMinDistance(){ return minDistance; }; + void setMinDistance(uint d){ minDistance = d; }; + uint getCannyEdgeThreshold(){ return cannyEdgeThreshold; }; + void setCannyEdgeThreshold(uint cannyThreshold){ cannyEdgeThreshold = cannyThreshold; }; + uint getHoughAccThreshold(){ return houghAccThreshold; }; + void setHoughAccThreshold(uint accThreshold){ houghAccThreshold = accThreshold; }; + uint getMinRadius(){ return minRadius; }; + void setMinRadius(uint min){ minRadius = min; }; + uint getMaxRadius(){ return maxRadius; }; + void setMaxRadius(uint max){ maxRadius = max; }; }; diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index b1ed53c..72bdb57 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -38,15 +38,17 @@ int Beamer::findBeamerFrom(Camera *camera){ rgb = camera->getColorFrame(); // Look for the circle target - double minDist = rgb.rows / (double)profil.getRadiusRatio(); + double minDist = rgb.cols / (double)profil.getMinDistance(); + double minRadius = (profil.getMinRadius()>0) ? rgb.cols/(double)profil.getMinRadius() : 0; + double maxRadius = (profil.getMaxRadius()>0) ? rgb.cols/(double)profil.getMaxRadius() : 0; std::vector<cv::Point3i> circles = findCircles( rgb, profil.getContrast(), profil.getBrightness(), minDist, profil.getCannyEdgeThreshold(), profil.getHoughAccThreshold(), - profil.getMinRadius(), - profil.getMaxRadius() ); + minRadius, + maxRadius ); // Show black screen with cross cv::Mat frameImage = getCrossFrame(cross, capturedPoints.size()+1, MAX_LINEAR_LINE_POINTS, !circles.empty()); @@ -232,10 +234,6 @@ std::vector<cv::Point3i> Beamer::findCircles(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 diff --git a/src/tools/sandboxConfig.cpp b/src/tools/sandboxConfig.cpp index a903269..1d85fe5 100644 --- a/src/tools/sandboxConfig.cpp +++ b/src/tools/sandboxConfig.cpp @@ -101,7 +101,7 @@ int SandboxConfig::saveFrameProcessProfil(char *path, FrameProcessProfil profil) val["contrast"] = profil.getContrast(); val["brightness"] = profil.getBrightness(); - val["radiusRatio"] = profil.getRadiusRatio(); + val["minDistance"] = profil.getMinDistance(); val["cannyEdgeThreshold"] = profil.getCannyEdgeThreshold(); val["houghAccThreshold"] = profil.getHoughAccThreshold(); val["minRadius"] = profil.getMinRadius(); @@ -284,7 +284,7 @@ int SandboxConfig::loadFrameProcessProfil(char *path, FrameProcessProfil *profil // uncomplet data for frame process profil if(!( config[PROCESSPROFIL]["contrast"] && config[PROCESSPROFIL]["brightness"] && - config[PROCESSPROFIL]["radiusRatio"] && + config[PROCESSPROFIL]["minDistance"] && config[PROCESSPROFIL]["cannyEdgeThreshold"] && config[PROCESSPROFIL]["houghAccThreshold"] && config[PROCESSPROFIL]["minRadius"] && @@ -295,11 +295,19 @@ 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->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>()); + profil->setMinDistance(config[PROCESSPROFIL]["minDistance"].as<uint>()); + profil->setCannyEdgeThreshold(config[PROCESSPROFIL]["cannyEdgeThreshold"].as<uint>()); + profil->setHoughAccThreshold(config[PROCESSPROFIL]["houghAccThreshold"].as<uint>()); + profil->setMinRadius(config[PROCESSPROFIL]["minRadius"].as<uint>()); + profil->setMaxRadius(config[PROCESSPROFIL]["maxRadius"].as<uint>()); + +/* + std::cout << config[PROCESSPROFIL]["contrast"].as<double>(); + std::cout << config[PROCESSPROFIL]["brightness"].as<int>(); + std::cout << config[PROCESSPROFIL]["radiusRatio"].as<uint>(); + std::cout << config[PROCESSPROFIL]["contrast"].as<double>(); + std::cout << config[PROCESSPROFIL]["contrast"].as<double>(); +*/ return 0; } -- GitLab