ParametersToolBox.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include "find_object/Settings.h"
29 
30 #include "ParametersToolBox.h"
31 #include <QComboBox>
32 #include <QDoubleSpinBox>
33 #include <QLineEdit>
34 #include <QLabel>
35 #include <QGroupBox>
36 #include <QCheckBox>
37 #include <QVBoxLayout>
38 #include <QMessageBox>
39 #include <stdio.h>
41 #include <opencv2/opencv_modules.hpp>
42 
43 namespace find_object {
44 
46  QToolBox(parent)
47 {
48 }
49 
51 {
52 }
53 
54 QWidget * ParametersToolBox::getParameterWidget(const QString & key)
55 {
56  return this->findChild<QWidget*>(key);
57 }
58 
59 QStringList ParametersToolBox::resetPage(int index)
60 {
61  QStringList paramChanged;
62  const QObjectList & children = this->widget(index)->children();
63  for(int j=0; j<children.size();++j)
64  {
65  QString key = children.at(j)->objectName();
66  // ignore only the nextObjID setting, to avoid problem with saved objects
67  if(key.compare(Settings::kGeneral_nextObjID()) != 0)
68  {
69  QVariant value = Settings::getDefaultParameters().value(key, QVariant());
70  if(value.isValid())
71  {
72  Settings::setParameter(key, value);
73 
74  if(qobject_cast<QComboBox*>(children.at(j)))
75  {
76  if(((QComboBox*)children.at(j))->currentIndex() != value.toString().split(':').first().toInt())
77  {
78  ((QComboBox*)children.at(j))->setCurrentIndex(value.toString().split(':').first().toInt());
79  paramChanged.append(key);
80  }
81  }
82  else if(qobject_cast<QSpinBox*>(children.at(j)))
83  {
84  if(((QSpinBox*)children.at(j))->value() != value.toInt())
85  {
86  ((QSpinBox*)children.at(j))->setValue(value.toInt());
87  paramChanged.append(key);
88  }
89  }
90  else if(qobject_cast<QDoubleSpinBox*>(children.at(j)))
91  {
92  if(((QDoubleSpinBox*)children.at(j))->value() != value.toDouble())
93  {
94  ((QDoubleSpinBox*)children.at(j))->setValue(value.toDouble());
95  paramChanged.append(key);
96  }
97  }
98  else if(qobject_cast<QCheckBox*>(children.at(j)))
99  {
100  if(((QCheckBox*)children.at(j))->isChecked() != value.toBool())
101  {
102  ((QCheckBox*)children.at(j))->setChecked(value.toBool());
103  paramChanged.append(key);
104  }
105  }
106  else if(qobject_cast<QLineEdit*>(children.at(j)))
107  {
108  if(((QLineEdit*)children.at(j))->text().compare(value.toString()) != 0)
109  {
110  ((QLineEdit*)children.at(j))->setText(value.toString());
111  paramChanged.append(key);
112  }
113  }
114  }
115  }
116  }
117  return paramChanged;
118 }
119 
121 {
122  this->blockSignals(true);
123  QStringList paramChanged = this->resetPage(this->currentIndex());
124  this->blockSignals(false);
125  Q_EMIT parametersChanged(paramChanged);
126 }
127 
129 {
130  QStringList paramChanged;
131  this->blockSignals(true);
132  for(int i=0; i< this->count(); ++i)
133  {
134  paramChanged.append(this->resetPage(i));
135  }
136  this->blockSignals(false);
137  Q_EMIT parametersChanged(paramChanged);
138 }
139 
141 {
142  //show/hide not used parameters
143  QComboBox * descriptorBox = this->findChild<QComboBox*>(Settings::kFeature2D_2Descriptor());
144  QComboBox * detectorBox = this->findChild<QComboBox*>(Settings::kFeature2D_1Detector());
145  if(descriptorBox && detectorBox)
146  {
147  QString group = Settings::kFeature2D_2Descriptor().split('/').first();
148  QWidget * panel = 0;
149  for(int i=0; i<this->count(); ++i)
150  {
151  if(this->widget(i)->objectName().compare(group) == 0)
152  {
153  panel = this->widget(i);
154  break;
155  }
156  }
157  if(panel)
158  {
159  const QObjectList & objects = panel->children();
160  QString descriptorName = descriptorBox->currentText();
161  QString detectorName = detectorBox->currentText();
162 
163  for(int i=0; i<objects.size(); ++i)
164  {
165  if(!objects[i]->objectName().isEmpty())
166  {
167  if(objects[i]->objectName().contains(descriptorName) || objects[i]->objectName().contains(detectorName))
168  {
169  ((QWidget*)objects[i])->setVisible(true);
170  }
171  else if(objects[i]->objectName().contains("Fast") && detectorName == QString("ORB"))
172  {
173  ((QWidget*)objects[i])->setVisible(true); // ORB uses some FAST parameters
174  }
175  else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
176  {
177  ((QWidget*)objects[i])->setVisible(false);
178  }
179  }
180  }
181  }
182  }
183 
184  QComboBox * nnBox = this->findChild<QComboBox*>(Settings::kNearestNeighbor_1Strategy());
185  if(nnBox)
186  {
187  QString group = Settings::kNearestNeighbor_1Strategy().split('/').first();
188  QWidget * panel = 0;
189  for(int i=0; i<this->count(); ++i)
190  {
191  if(this->widget(i)->objectName().compare(group) == 0)
192  {
193  panel = this->widget(i);
194  break;
195  }
196  }
197  if(panel)
198  {
199  const QObjectList & objects = panel->children();
200  QString nnName = nnBox->currentText();
201 
202  for(int i=0; i<objects.size(); ++i)
203  {
204  if(!objects[i]->objectName().isEmpty())
205  {
206  if(objects[i]->objectName().contains(nnName))
207  {
208  ((QWidget*)objects[i])->setVisible(true);
209  }
210  else if(!objects[i]->objectName().split('/').at(1).at(0).isDigit())
211  {
212  ((QWidget*)objects[i])->setVisible(false);
213  if(nnBox->currentIndex() < 6 && objects[i]->objectName().split('/').at(1).contains("search"))
214  {
215  //show flann search parameters
216  ((QWidget*)objects[i])->setVisible(true);
217  }
218  }
219  else if(objects[i]->objectName().split('/').at(1).contains("Distance_type"))
220  {
221  // don't show distance when bruteforce is selected
222  ((QWidget*)objects[i])->setVisible(nnBox->currentIndex() != 6);
223  }
224  }
225  }
226  }
227  }
228 }
229 
231 {
232  this->removeItem(0); // remove dummy page used in .ui
233  QWidget * currentItem = 0;
234  const ParametersMap & parameters = Settings::getParameters();
235  for(ParametersMap::const_iterator iter=parameters.constBegin();
236  iter!=parameters.constEnd();
237  ++iter)
238  {
239  QStringList splitted = iter.key().split('/');
240  QString group = splitted.first();
241  QString name = splitted.last();
242  if(currentItem == 0 || currentItem->objectName().compare(group) != 0)
243  {
244  currentItem = new QWidget(this);
245  this->addItem(currentItem, group);
246  currentItem->setObjectName(group);
247  QVBoxLayout * layout = new QVBoxLayout(currentItem);
248  currentItem->setLayout(layout);
249  layout->setContentsMargins(0,0,0,0);
250  layout->setSpacing(0);
251  layout->addSpacerItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
252 
253  addParameter(layout, iter.key(), iter.value());
254  }
255  else
256  {
257  addParameter((QVBoxLayout*)currentItem->layout(), iter.key(), iter.value());
258  }
259  }
260 
262 }
263 
264 void ParametersToolBox::updateParameter(const QString & key)
265 {
266  QWidget * widget = this->findChild<QWidget*>(key);
267  QString type = Settings::getParametersType().value(key);
268  if(type.compare("QString") == 0)
269  {
270  QString value = Settings::getParameter(key).toString();
271  if(value.contains(';'))
272  {
273  // It's a list, just change the index
274  QStringList splitted = value.split(':');
275  ((QComboBox*)widget)->setCurrentIndex(splitted.first().toInt());
276  }
277  else
278  {
279  ((QLineEdit*)widget)->setText(value);
280  }
281  }
282  else if(type.compare("int") == 0)
283  {
284  ((QSpinBox*)widget)->setValue(Settings::getParameter(key).toInt());
285  }
286  else if(type.compare("uint") == 0)
287  {
288  ((QSpinBox*)widget)->setValue(Settings::getParameter(key).toInt());
289  }
290  else if(type.compare("double") == 0)
291  {
292  ((QDoubleSpinBox*)widget)->setValue(Settings::getParameter(key).toDouble());
293  }
294  else if(type.compare("float") == 0)
295  {
296  ((QDoubleSpinBox*)widget)->setValue(Settings::getParameter(key).toDouble());
297  }
298  else if(type.compare("bool") == 0)
299  {
300  ((QCheckBox*)widget)->setChecked(Settings::getParameter(key).toBool());
301  }
302 }
303 
304 void ParametersToolBox::addParameter(QVBoxLayout * layout,
305  const QString & key,
306  const QVariant & value)
307 {
308  QString type = Settings::getParametersType().value(key);
309  if(type.compare("QString") == 0)
310  {
311  addParameter(layout, key, value.toString());
312  }
313  else if(type.compare("int") == 0)
314  {
315  addParameter(layout, key, value.toInt());
316  }
317  else if(type.compare("uint") == 0)
318  {
319  addParameter(layout, key, value.toInt());
320  }
321  else if(type.compare("double") == 0)
322  {
323  addParameter(layout, key, value.toDouble());
324  }
325  else if(type.compare("float") == 0)
326  {
327  addParameter(layout, key, value.toDouble());
328  }
329  else if(type.compare("bool") == 0)
330  {
331  addParameter(layout, key, value.toBool());
332  }
333 }
334 
335 void ParametersToolBox::addParameter(QVBoxLayout * layout,
336  const QString & key,
337  const QString & value)
338 {
339  if(value.contains(';'))
340  {
341  QComboBox * widget = new QComboBox(this);
342  widget->setObjectName(key);
343  QStringList splitted = value.split(':');
344  widget->addItems(splitted.last().split(';'));
345 
346  if(key.compare(Settings::kFeature2D_1Detector()) == 0)
347  {
348 #if FINDOBJECT_NONFREE == 0
349  widget->setItemData(5, 0, Qt::UserRole - 1); // disable SIFT
350  widget->setItemData(7, 0, Qt::UserRole - 1); // disable SURF
351 #endif
352 #if CV_MAJOR_VERSION < 3
353  widget->setItemData(9, 0, Qt::UserRole - 1); // disable AGAST
354  widget->setItemData(10, 0, Qt::UserRole - 1); // disable KAZE
355  widget->setItemData(11, 0, Qt::UserRole - 1); // disable AKAZE
356 #else
357  widget->setItemData(0, 0, Qt::UserRole - 1); // disable Dense
358 #ifndef HAVE_OPENCV_XFEATURES2D
359  widget->setItemData(6, 0, Qt::UserRole - 1); // disable Star
360 #endif
361 #endif
362  }
363  if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
364  {
365 #if FINDOBJECT_NONFREE == 0
366  widget->setItemData(2, 0, Qt::UserRole - 1); // disable SIFT
367  widget->setItemData(3, 0, Qt::UserRole - 1); // disable SURF
368 #endif
369 #if CV_MAJOR_VERSION < 3
370  widget->setItemData(6, 0, Qt::UserRole - 1); // disable KAZE
371  widget->setItemData(7, 0, Qt::UserRole - 1); // disable AKAZE
372  widget->setItemData(8, 0, Qt::UserRole - 1); // disable LUCID
373  widget->setItemData(9, 0, Qt::UserRole - 1); // disable LATCH
374  widget->setItemData(10, 0, Qt::UserRole - 1); // disable DAISY
375 #else
376 
377 #ifndef HAVE_OPENCV_XFEATURES2D
378  widget->setItemData(0, 0, Qt::UserRole - 1); // disable Brief
379  widget->setItemData(5, 0, Qt::UserRole - 1); // disable Freak
380  widget->setItemData(8, 0, Qt::UserRole - 1); // disable LUCID
381  widget->setItemData(9, 0, Qt::UserRole - 1); // disable LATCH
382  widget->setItemData(10, 0, Qt::UserRole - 1); // disable DAISY
383 #endif
384 #endif
385  }
386  if(key.compare(Settings::kNearestNeighbor_1Strategy()) == 0)
387  {
388 #if FINDOBJECT_NONFREE == 0 && CV_MAJOR_VERSION < 3
389  // disable FLANN approaches (cannot be used with binary descriptors)
390  widget->setItemData(0, 0, Qt::UserRole - 1);
391  widget->setItemData(1, 0, Qt::UserRole - 1);
392  widget->setItemData(2, 0, Qt::UserRole - 1);
393  widget->setItemData(3, 0, Qt::UserRole - 1);
394  widget->setItemData(4, 0, Qt::UserRole - 1);
395 #endif
396  }
397  if(key.compare(Settings::kHomography_method()) == 0)
398  {
399 #if CV_MAJOR_VERSION < 3
400  // disable RHO approach
401  widget->setItemData(2, 0, Qt::UserRole - 1);
402 #endif
403  }
404 
405  widget->setCurrentIndex(splitted.first().toInt());
406  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(changeParameter(int)));
407  addParameter(layout, key, widget);
408  }
409  else
410  {
411  QLineEdit * widget = new QLineEdit(value, this);
412  widget->setObjectName(key);
413  connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
414  addParameter(layout, key, widget);
415  }
416 }
417 
418 void ParametersToolBox::addParameter(QVBoxLayout * layout,
419  const QString & key,
420  const double & value)
421 {
422  QDoubleSpinBox * widget = new QDoubleSpinBox(this);
423  int decimals = 0;
424  int decimalValue = 0;
425 
426  QString str = QString::number(Settings::getDefaultParameters().value(key).toDouble());
427  str.remove( QRegExp("0+$") );
428 
429  if(!str.isEmpty())
430  {
431  str.replace(',', '.');
432  QStringList items = str.split('.');
433  if(items.size() == 2)
434  {
435  decimals = items.back().length();
436  decimalValue = items.back().toInt();
437  }
438  }
439 
440  double def = Settings::getDefaultParameters().value(key).toDouble();
441  if(def<0.001 || (decimals >= 4 && decimalValue>0))
442  {
443  widget->setDecimals(5);
444  widget->setSingleStep(0.0001);
445  }
446  else if(def<0.01 || (decimals >= 3 && decimalValue>0))
447  {
448  widget->setDecimals(4);
449  widget->setSingleStep(0.001);
450  }
451  else if(def<0.1 || (decimals >= 2 && decimalValue>0))
452  {
453  widget->setDecimals(3);
454  widget->setSingleStep(0.01);
455  }
456  else if(def<1.0 || (decimals >= 1 && decimalValue>0))
457  {
458  widget->setDecimals(2);
459  widget->setSingleStep(0.1);
460  }
461  else
462  {
463  widget->setDecimals(1);
464  }
465 
466  if(def>0.0)
467  {
468  widget->setMaximum(def*1000000.0);
469  }
470  else if(def==0.0)
471  {
472  widget->setMaximum(1000000.0);
473  }
474  else if(def<0.0)
475  {
476  widget->setMinimum(def*1000000.0);
477  widget->setMaximum(0.0);
478  }
479  widget->setValue(value);
480  widget->setObjectName(key);
481  connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
482  addParameter(layout, key, widget);
483 }
484 
485 void ParametersToolBox::addParameter(QVBoxLayout * layout,
486  const QString & key,
487  const int & value)
488 {
489  QSpinBox * widget = new QSpinBox(this);
490  int def = Settings::getDefaultParameters().value(key).toInt();
491 
492  if(def>0)
493  {
494  widget->setMaximum(def*1000000);
495  }
496  else if(def == 0)
497  {
498  widget->setMaximum(1000000);
499  }
500  else if(def<0)
501  {
502  widget->setMinimum(def*1000000);
503  widget->setMaximum(0);
504  }
505  widget->setValue(value);
506  widget->setObjectName(key);
507  connect(widget, SIGNAL(editingFinished()), this, SLOT(changeParameter()));
508  addParameter(layout, key, widget);
509 }
510 
511 void ParametersToolBox::addParameter(QVBoxLayout * layout,
512  const QString & key,
513  const bool & value)
514 {
515  QCheckBox * widget = new QCheckBox(this);
516  widget->setChecked(value);
517  widget->setObjectName(key);
518  connect(widget, SIGNAL(toggled(bool)), this, SLOT(changeParameter(bool)));
519  addParameter(layout, key, widget);
520 }
521 
522 void ParametersToolBox::addParameter(QVBoxLayout * layout, const QString & key, QWidget * widget)
523 {
524  QHBoxLayout * hLayout = new QHBoxLayout();
525  layout->insertLayout(layout->count()-1, hLayout);
526  QString tmp = key.split('/').last();
527  if(tmp.at(0).isDigit())
528  {
529  tmp.remove(0,1);
530  }
531  QLabel * label = new QLabel(tmp, this);
532  label->setObjectName(key+"/label");
533  label->setToolTip(QString("<FONT>%1</FONT>").arg(Settings::getDescriptions().value(key, "")));
534  label->setTextInteractionFlags(Qt::TextSelectableByMouse);
535  hLayout->addWidget(label);
536  hLayout->addWidget(widget);
537 }
538 
539 void ParametersToolBox::changeParameter(const QString & value)
540 {
541  if(sender())
542  {
543  Settings::setParameter(sender()->objectName(), value);
544  QStringList paramChanged;
545  paramChanged.append(sender()->objectName());
546  Q_EMIT parametersChanged(paramChanged);
547  }
548 }
550 {
551  if(sender())
552  {
553  QDoubleSpinBox * doubleSpinBox = qobject_cast<QDoubleSpinBox*>(sender());
554  QSpinBox * spinBox = qobject_cast<QSpinBox*>(sender());
555  QLineEdit * lineEdit = qobject_cast<QLineEdit*>(sender());
556  if(doubleSpinBox)
557  {
558  Settings::setParameter(sender()->objectName(), doubleSpinBox->value());
559  }
560  else if(spinBox)
561  {
562  if(spinBox->objectName().compare(Settings::kHomography_minimumInliers()) == 0 &&
563  spinBox->value() < 4)
564  {
565  Settings::setHomography_minimumInliers(4);
566  spinBox->blockSignals(true);
567  this->updateParameter(Settings::kHomography_minimumInliers());
568  spinBox->blockSignals(false);
569  }
570  else
571  {
572  Settings::setParameter(sender()->objectName(), spinBox->value());
573  }
574  }
575  else if(lineEdit)
576  {
577  Settings::setParameter(sender()->objectName(), lineEdit->text());
578  }
579  QStringList paramChanged;
580  paramChanged.append(sender()->objectName());
581  Q_EMIT parametersChanged(paramChanged);
582  }
583 }
584 
586 {
587  if(sender())
588  {
589  // Workaround as stateChanged(int) is not always emitted, using toggled(bool) instead
590  changeParameter(sender(), value?Qt::Checked:Qt::Unchecked);
591  }
592 }
593 
595 {
596  if(sender())
597  {
598  changeParameter(sender(), value);
599  }
600 }
601 
602 void ParametersToolBox::changeParameter(QObject * sender, int value)
603 {
604  if(sender)
605  {
606  QStringList paramChanged;
607  QComboBox * comboBox = qobject_cast<QComboBox*>(sender);
608  QCheckBox * checkBox = qobject_cast<QCheckBox*>(sender);
609 
610  bool descriptorChanged = false;
611  if(comboBox && comboBox->objectName().compare(Settings::kFeature2D_1Detector()) == 0)
612  {
613  QComboBox * descriptorBox = (QComboBox*)this->getParameterWidget(Settings::kFeature2D_2Descriptor());
614  if(comboBox->objectName().compare(Settings::kFeature2D_1Detector()) == 0 &&
615  comboBox->currentText() != descriptorBox->currentText() &&
616  Settings::getFeature2D_2Descriptor().contains(comboBox->currentText()))
617  {
618  QMessageBox::StandardButton b = QMessageBox::question(this,
619  tr("Use corresponding descriptor type?"),
620  tr("Current selected detector type (\"%1\") has its own corresponding descriptor type.\n"
621  "Do you want to use its corresponding descriptor?")
622  .arg(comboBox->currentText()),
623  QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
624  if(b == QMessageBox::Yes)
625  {
626  int index = descriptorBox->findText(comboBox->currentText());
627  if(index >= 0)
628  {
629  QStringList tmp = Settings::getFeature2D_2Descriptor().split(':');
630  UASSERT(tmp.size() == 2);
631  QString newTmp = QString('0'+index)+":"+tmp.back();
632  Settings::setFeature2D_2Descriptor(newTmp);
633  descriptorBox->blockSignals(true);
634  this->updateParameter(Settings::kFeature2D_2Descriptor());
635  descriptorBox->blockSignals(false);
636  paramChanged.append(Settings::kFeature2D_2Descriptor());
637  descriptorChanged = true;
638  }
639  else
640  {
641  UERROR("Combo box detector type not found \"%s\"?!", comboBox->currentText().toStdString().c_str());
642  }
643  }
644  }
645  }
646 
647  bool nnStrategyChanged = false;
648  //verify binary issue with nearest neighbor strategy
649  if((comboBox && (comboBox->objectName().compare(Settings::kFeature2D_2Descriptor()) == 0 ||
650  comboBox->objectName().compare(Settings::kNearestNeighbor_1Strategy()) == 0)) ||
651  descriptorChanged ||
652  (checkBox && checkBox->objectName().compare(Settings::kNearestNeighbor_7ConvertBinToFloat()) == 0))
653  {
654  QComboBox * descriptorBox = (QComboBox*)this->getParameterWidget(Settings::kFeature2D_2Descriptor());
655  QComboBox * nnBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_1Strategy());
656  QComboBox * distBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_2Distance_type());
657  QCheckBox * binToFloatCheckbox = (QCheckBox*)this->getParameterWidget(Settings::kNearestNeighbor_7ConvertBinToFloat());
658  bool isBinaryDescriptor = descriptorBox->currentText().compare("ORB") == 0 ||
659  descriptorBox->currentText().compare("Brief") == 0 ||
660  descriptorBox->currentText().compare("BRISK") == 0 ||
661  descriptorBox->currentText().compare("FREAK") == 0 ||
662  descriptorBox->currentText().compare("AKAZE") == 0 ||
663  descriptorBox->currentText().compare("LATCH") == 0 ||
664  descriptorBox->currentText().compare("LUCID") == 0;
665  bool binToFloat = binToFloatCheckbox->isChecked();
666  if(isBinaryDescriptor && !binToFloat && nnBox->currentText().compare("Lsh") != 0 && nnBox->currentText().compare("BruteForce") != 0)
667  {
668  QMessageBox::warning(this,
669  tr("Warning"),
670  tr("Current selected descriptor type (\"%1\") is binary while nearest neighbor strategy is not (\"%2\").\n"
671  "Falling back to \"BruteForce\" nearest neighbor strategy with Hamming distance (by default).")
672  .arg(descriptorBox->currentText())
673  .arg(nnBox->currentText()));
674  QString tmp = Settings::getNearestNeighbor_1Strategy();
675  *tmp.begin() = '6'; // set BruteForce
676  Settings::setNearestNeighbor_1Strategy(tmp);
677  tmp = Settings::getNearestNeighbor_2Distance_type();
678  *tmp.begin() = '8'; // set HAMMING
679  Settings::setNearestNeighbor_2Distance_type(tmp);
680  nnBox->blockSignals(true);
681  distBox->blockSignals(true);
682  this->updateParameter(Settings::kNearestNeighbor_1Strategy());
683  this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
684  nnBox->blockSignals(false);
685  distBox->blockSignals(false);
686  if(sender == nnBox)
687  {
689  return;
690  }
691  nnStrategyChanged = true;
692  paramChanged.append(Settings::kNearestNeighbor_1Strategy());
693  paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
694  }
695  else if((!isBinaryDescriptor || binToFloat) && nnBox->currentText().compare("Lsh") == 0)
696  {
697  if(binToFloat)
698  {
699  QMessageBox::warning(this,
700  tr("Warning"),
701  tr("Current selected descriptor type (\"%1\") is binary, but binary to float descriptors conversion is activated while nearest neighbor strategy is (\"%2\").\n"
702  "Disabling binary to float descriptors conversion and use Hamming distance (by default).")
703  .arg(descriptorBox->currentText())
704  .arg(nnBox->currentText()));
705 
706  binToFloatCheckbox->blockSignals(true);
707  if(checkBox && checkBox->objectName().compare(Settings::kNearestNeighbor_7ConvertBinToFloat()) == 0)
708  {
709  Settings::setParameter(checkBox->objectName(), false);
710  value = 0;
711  }
712  else
713  {
714  paramChanged.append(Settings::kNearestNeighbor_7ConvertBinToFloat());
715  }
716  this->updateParameter(Settings::kNearestNeighbor_7ConvertBinToFloat());
717  binToFloatCheckbox->blockSignals(false);
718 
719  QString tmp = Settings::getNearestNeighbor_2Distance_type();
720  *tmp.begin() = '8'; // set HAMMING
721  Settings::setNearestNeighbor_2Distance_type(tmp);
722  distBox->blockSignals(true);
723  this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
724  distBox->blockSignals(false);
725  paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
726  }
727  else
728  {
729  QMessageBox::warning(this,
730  tr("Warning"),
731  tr("Current selected descriptor type (\"%1\") is not binary while nearest neighbor strategy is (\"%2\").\n"
732  "Falling back to \"KDTree\" nearest neighbor strategy with Euclidean_L2 distance (by default).")
733  .arg(descriptorBox->currentText())
734  .arg(nnBox->currentText()));
735 
736  QString tmp = Settings::getNearestNeighbor_1Strategy();
737  *tmp.begin() = '1'; // set KDTree
738  Settings::setNearestNeighbor_1Strategy(tmp);
739  tmp = Settings::getNearestNeighbor_2Distance_type();
740  *tmp.begin() = '0'; // set EUCLIDEAN_L2
741  Settings::setNearestNeighbor_2Distance_type(tmp);
742  nnBox->blockSignals(true);
743  distBox->blockSignals(true);
744  this->updateParameter(Settings::kNearestNeighbor_1Strategy());
745  this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
746  nnBox->blockSignals(false);
747  distBox->blockSignals(false);
748  if(sender == nnBox)
749  {
751  return;
752  }
753  nnStrategyChanged = true;
754  paramChanged.append(Settings::kNearestNeighbor_1Strategy());
755  paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
756  }
757  }
758  }
759 
760  // Distance issue when using nearest neighbor strategy using CV_32F type, though Lsh support all type (doesn't crash at least)
761  if(nnStrategyChanged ||
762  (comboBox && (comboBox->objectName().compare(Settings::kNearestNeighbor_1Strategy()) == 0 ||
763  comboBox->objectName().compare(Settings::kNearestNeighbor_2Distance_type()) == 0)))
764  {
765  QComboBox * nnBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_1Strategy());
766  QComboBox * distBox = (QComboBox*)this->getParameterWidget(Settings::kNearestNeighbor_2Distance_type());
767  if(nnBox->currentText().compare("BruteForce") != 0 && nnBox->currentText().compare("Lsh") != 0 && distBox->currentIndex() > 1)
768  {
769  QMessageBox::warning(this,
770  tr("Warning"),
771  tr("Current selected nearest neighbor strategy type (\"%1\") cannot handle distance strategy (\"%2\").\n"
772  "Falling back to \"EUCLIDEAN_L2\" distance strategy (by default).")
773  .arg(nnBox->currentText())
774  .arg(distBox->currentText()));
775  QString tmp = Settings::getNearestNeighbor_2Distance_type();
776  *tmp.begin() = '0'; // set index
777  Settings::setNearestNeighbor_2Distance_type(tmp);
778  distBox->blockSignals(true);
779  this->updateParameter(Settings::kNearestNeighbor_2Distance_type());
780  distBox->blockSignals(false);
781  if(sender == distBox)
782  {
784  return;
785  }
786  paramChanged.append(Settings::kNearestNeighbor_2Distance_type());
787  }
788  }
789 
790  if(comboBox)
791  {
792  QStringList items;
793  for(int i=0; i<comboBox->count(); ++i)
794  {
795  items.append(comboBox->itemText(i));
796  }
797  QString merged = QString::number(value) + QString(":") + items.join(";");
798  Settings::setParameter(sender->objectName(), merged);
799  }
800 
801  if(checkBox)
802  {
803  Settings::setParameter(sender->objectName(), value==Qt::Checked?true:false);
804  }
805 
807 
808  paramChanged.append(sender->objectName());
809  Q_EMIT parametersChanged(paramChanged);
810  }
811 }
812 
813 } // namespace find_object
static QVariant getParameter(const QString &key)
Definition: Settings.h:328
TFSIMD_FORCE_INLINE void setValue(const tfScalar &x, const tfScalar &y, const tfScalar &z)
static const ParametersType & getParametersType()
Definition: Settings.h:324
void parametersChanged(const QStringList &name)
#define UASSERT(condition)
static const ParametersMap & getParameters()
Definition: Settings.h:323
void addParameter(QVBoxLayout *layout, const QString &key, const QVariant &value)
static void setParameter(const QString &key, const QVariant &value)
Definition: Settings.h:326
static const DescriptionsMap & getDescriptions()
Definition: Settings.h:325
QMap< QString, QVariant > ParametersMap
Definition: Settings.h:41
QWidget * getParameterWidget(const QString &key)
QStringList resetPage(int index)
#define UERROR(...)
ULogger class and convenient macros.
void updateParameter(const QString &key)
static const ParametersMap & getDefaultParameters()
Definition: Settings.h:322


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 19:22:26