38 #include "ui_mainWindow.h" 50 #include "opencv2/calib3d/calib3d.hpp" 51 #include "opencv2/imgproc/imgproc.hpp" 52 #include <opencv2/opencv_modules.hpp> 53 #if CV_MAJOR_VERSION < 3 54 #include <opencv2/gpu/gpu.hpp> 56 #include <opencv2/core/cuda.hpp> 59 #include <QtCore/QTextStream> 60 #include <QtCore/QFile> 61 #include <QtCore/QBuffer> 62 #include <QtCore/QThread> 63 #include <QtCore/QLineF> 65 #include <QFileDialog> 66 #include <QMessageBox> 67 #include <QGraphicsScene> 68 #include <QGraphicsRectItem> 71 #include <QProgressDialog> 72 #include <QCloseEvent> 75 #include <QInputDialog> 85 findObject_(findObject),
88 lowestRefreshRate_(99),
89 objectsModified_(false),
94 ui_ =
new Ui_mainWindow();
97 this->setStatusBar(
new QStatusBar());
105 ui_->likelihoodPlot->setGraphicsView(
true);
107 ui_->dockWidget_statistics->setVisible(
false);
108 ui_->dockWidget_parameters->setVisible(
false);
109 ui_->dockWidget_plot->setVisible(
false);
110 ui_->widget_controls->setVisible(
false);
115 this->restoreGeometry(geometry);
116 this->restoreState(state);
119 ui_->toolBox->setupUi();
128 ui_->toolBox->getParameterWidget(Settings::kCamera_1deviceId())->setEnabled(
false);
129 ui_->toolBox->getParameterWidget(Settings::kCamera_2imageWidth())->setEnabled(
false);
130 ui_->toolBox->getParameterWidget(Settings::kCamera_3imageHeight())->setEnabled(
false);
131 ui_->toolBox->getParameterWidget(Settings::kCamera_5mediaPath())->setEnabled(
false);
132 ui_->toolBox->getParameterWidget(Settings::kCamera_6useTcpCamera())->setEnabled(
false);
133 ui_->toolBox->getParameterWidget(Settings::kCamera_8port())->setEnabled(
false);
134 ui_->toolBox->getParameterWidget(Settings::kCamera_9queueSize())->setEnabled(
false);
135 ui_->actionCamera_from_video_file->setVisible(
false);
136 ui_->actionCamera_from_TCP_IP->setVisible(
false);
137 ui_->actionCamera_from_directory_of_images->setVisible(
false);
138 ui_->actionLoad_scene_from_file->setVisible(
false);
141 #if CV_MAJOR_VERSION < 3 142 if(cv::gpu::getCudaEnabledDeviceCount() == 0)
144 if(cv::cuda::getCudaEnabledDeviceCount() == 0)
147 #if FINDOBJECT_NONFREE == 1 148 ui_->toolBox->updateParameter(Settings::kFeature2D_SURF_gpu());
149 ui_->toolBox->getParameterWidget(Settings::kFeature2D_SURF_gpu())->setEnabled(
false);
150 ui_->toolBox->getParameterWidget(Settings::kFeature2D_SURF_keypointsRatio())->setEnabled(
false);
152 ui_->toolBox->updateParameter(Settings::kFeature2D_Fast_gpu());
153 ui_->toolBox->updateParameter(Settings::kFeature2D_ORB_gpu());
154 ui_->toolBox->updateParameter(Settings::kNearestNeighbor_BruteForce_gpu());
155 ui_->toolBox->getParameterWidget(Settings::kFeature2D_Fast_gpu())->setEnabled(
false);
156 ui_->toolBox->getParameterWidget(Settings::kFeature2D_Fast_keypointsRatio())->setEnabled(
false);
157 ui_->toolBox->getParameterWidget(Settings::kFeature2D_ORB_gpu())->setEnabled(
false);
158 ui_->toolBox->getParameterWidget(Settings::kNearestNeighbor_BruteForce_gpu())->setEnabled(
false);
161 connect((QDoubleSpinBox*)
ui_->toolBox->getParameterWidget(Settings::kCamera_4imageRate()),
162 SIGNAL(editingFinished()),
164 SLOT(updateImageRate()));
165 ui_->menuView->addAction(
ui_->dockWidget_statistics->toggleViewAction());
166 ui_->menuView->addAction(
ui_->dockWidget_parameters->toggleViewAction());
167 ui_->menuView->addAction(
ui_->dockWidget_objects->toggleViewAction());
168 ui_->menuView->addAction(
ui_->dockWidget_plot->toggleViewAction());
169 connect(
ui_->toolBox, SIGNAL(parametersChanged(
const QStringList &)),
this, SLOT(
notifyParametersChanged(
const QStringList &)));
171 ui_->imageView_source->setTextLabel(tr(
"Press \"space\" to start the camera or drop an image here..."));
172 ui_->imageView_source->setMirrorView(Settings::getGeneral_mirrorView());
173 connect((QCheckBox*)
ui_->toolBox->getParameterWidget(Settings::kGeneral_mirrorView()),
174 SIGNAL(stateChanged(
int)),
178 ui_->widget_controls->setVisible(Settings::getGeneral_controlsShown());
179 connect((QCheckBox*)
ui_->toolBox->getParameterWidget(Settings::kGeneral_controlsShown()),
180 SIGNAL(stateChanged(
int)),
185 connect(
ui_->pushButton_restoreDefaults, SIGNAL(clicked()),
ui_->toolBox, SLOT(resetCurrentPage()));
186 connect(
ui_->pushButton_updateObjects, SIGNAL(clicked()),
this, SLOT(
updateObjects()));
187 connect(
ui_->horizontalSlider_objectsSize, SIGNAL(valueChanged(
int)),
this, SLOT(
updateObjectsSize()));
189 ui_->actionStop_camera->setEnabled(
false);
190 ui_->actionPause_camera->setEnabled(
false);
191 ui_->actionSave_objects->setEnabled(
false);
192 ui_->actionSave_session->setEnabled(
false);
199 connect(
ui_->actionStop_camera, SIGNAL(triggered()),
this, SLOT(
stopProcessing()));
201 connect(
ui_->actionExit, SIGNAL(triggered()),
this, SLOT(close()));
202 connect(
ui_->actionSave_objects, SIGNAL(triggered()),
this, SLOT(
saveObjects()));
203 connect(
ui_->actionLoad_objects, SIGNAL(triggered()),
this, SLOT(
loadObjects()));
207 connect(
ui_->actionAbout, SIGNAL(triggered()),
aboutDialog_ , SLOT(exec()));
208 connect(
ui_->actionRestore_all_default_settings, SIGNAL(triggered()),
ui_->toolBox, SLOT(resetAllPages()));
209 connect(
ui_->actionRemove_all_objects, SIGNAL(triggered()),
this, SLOT(
removeAllObjects()));
210 connect(
ui_->actionSave_settings, SIGNAL(triggered()),
this, SLOT(
saveSettings()));
211 connect(
ui_->actionLoad_settings, SIGNAL(triggered()),
this, SLOT(
loadSettings()));
212 connect(
ui_->actionSave_session, SIGNAL(triggered()),
this, SLOT(
saveSession()));
213 connect(
ui_->actionLoad_session, SIGNAL(triggered()),
this, SLOT(
loadSession()));
214 connect(
ui_->actionSave_vocabulary, SIGNAL(triggered()),
this, SLOT(
saveVocabulary()));
215 connect(
ui_->actionLoad_vocabulary, SIGNAL(triggered()),
this, SLOT(
loadVocabulary()));
222 connect(
ui_->horizontalSlider_frames, SIGNAL(valueChanged(
int)),
this, SLOT(
moveCameraFrame(
int)));
223 connect(
ui_->horizontalSlider_frames, SIGNAL(valueChanged(
int)),
ui_->label_frame, SLOT(setNum(
int)));
224 ui_->pushButton_play->setVisible(
true);
225 ui_->pushButton_pause->setVisible(
false);
226 ui_->pushButton_stop->setEnabled(
false);
227 ui_->horizontalSlider_frames->setEnabled(
false);
228 ui_->label_frame->setVisible(
false);
230 ui_->objects_area->addAction(
ui_->actionAdd_object_from_scene);
231 ui_->objects_area->addAction(
ui_->actionAdd_objects_from_files);
232 ui_->objects_area->setContextMenuPolicy(Qt::ActionsContextMenu);
234 ui_->actionStart_camera->setShortcut(Qt::Key_Space);
235 ui_->actionPause_camera->setShortcut(Qt::Key_Space);
237 ui_->actionCamera_from_video_file->setChecked(!Settings::getCamera_5mediaPath().isEmpty() && !
UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()));
238 ui_->actionCamera_from_directory_of_images->setChecked(!Settings::getCamera_5mediaPath().isEmpty() &&
UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()));
239 ui_->actionCamera_from_TCP_IP->setChecked(Settings::getCamera_6useTcpCamera());
241 ui_->label_ipAddress->setTextInteractionFlags(Qt::TextSelectableByMouse);
242 ui_->label_port->setTextInteractionFlags(Qt::TextSelectableByMouse);
248 for(QMap<int, ObjSignature *>::const_iterator iter =
findObject_->
objects().constBegin();
256 ui_->actionSave_objects->setEnabled(
true);
257 ui_->actionSave_session->setEnabled(
true);
262 ui_->actionSave_session->setEnabled(
true);
266 if(Settings::getGeneral_autoStartCamera())
273 connect(
ui_->imageDrop_objects, SIGNAL(imagesReceived(
const QStringList &)),
this, SLOT(
addObjectsFromFiles(
const QStringList &)));
274 connect(
ui_->imageDrop_scene, SIGNAL(imagesReceived(
const QStringList &)),
this, SLOT(
loadSceneFromFile(
const QStringList &)));
276 ui_->imageView_source->setFocus();
281 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
296 int ret = QMessageBox::question(
this, tr(
"Save new objects"), tr(
"Do you want to save added objects?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
299 case QMessageBox::Yes:
302 case QMessageBox::Cancel:
305 case QMessageBox::No:
324 if(event->key() == Qt::Key_Space)
326 if(
ui_->actionStart_camera->isEnabled())
330 else if(
ui_->actionPause_camera->isEnabled())
351 connect(
tcpServer_, SIGNAL(addObject(
const cv::Mat &,
int,
const QString &)),
this, SLOT(
addObjectFromTcp(
const cv::Mat &,
int,
const QString &)));
357 ui_->imageView_source->setTextLabel(text);
364 QMessageBox::StandardButton b = QMessageBox::question(
this, tr(
"Loading session..."),
365 tr(
"There are some objects (%1) already loaded, they will be " 366 "deleted when loading the session. Do you want to continue?").arg(
objWidgets_.size()),
367 QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton);
368 if(b != QMessageBox::Yes)
379 ui_->actionSave_objects->setEnabled(
false);
386 for(ParametersMap::const_iterator iter = parameters.begin(); iter!= parameters.constEnd(); ++iter)
388 ui_->toolBox->updateParameter(iter.key());
398 ui_->actionSave_objects->setEnabled(
true);
399 ui_->actionSave_session->setEnabled(
true);
403 QLabel * title = this->findChild<QLabel*>(QString(
"%1title").arg(iter.value()->id()));
404 title->setText(QString(
"%1 (%2)").arg(iter.value()->id()).arg(QString::number(iter.value()->keypoints().size())));
409 QMessageBox::information(
this, tr(
"Session loaded!"), tr(
"Session \"%1\" successfully loaded (%2 objects)!").arg(path).arg(
objWidgets_.size()));
425 if(QFileInfo(path).suffix().compare(
"bin") != 0)
432 QMessageBox::information(
this, tr(
"Session saved!"), tr(
"Session \"%1\" successfully saved (%2 objects)!").arg(path).arg(
objWidgets_.size()));
443 if(QFileInfo(path).suffix().compare(
"ini") != 0)
455 if(QFileInfo(path).suffix().compare(
"ini") != 0)
465 if(!path.isEmpty() && QFileInfo(path).suffix().compare(
"ini") == 0)
471 this->restoreGeometry(geometry);
472 this->restoreState(state);
476 for(ParametersMap::const_iterator iter = parameters.begin(); iter!= parameters.constEnd(); ++iter)
478 ui_->toolBox->updateParameter(iter.key());
483 UERROR(
"Path \"%s\" not valid (should be *.ini)", path.toStdString().c_str());
489 if(!path.isEmpty() && QFileInfo(path).suffix().compare(
"ini") == 0)
495 UERROR(
"Path \"%s\" not valid (should be *.ini)", path.toStdString().c_str());
501 QList<int> loadedObjects;
502 QString formats = Settings::getGeneral_imageFormats().remove(
'*').remove(
'.');
505 paths.append(dirPath);
509 QString currentDir = paths.front();
510 UDirectory dir(currentDir.toStdString(), formats.toStdString());
513 const std::list<std::string> & names = dir.
getFileNames();
514 for(std::list<std::string>::const_iterator iter=names.begin(); iter!=names.end(); ++iter)
516 int id = this->
addObjectFromFile((currentDir.toStdString()+dir.separator()+*iter).c_str());
519 loadedObjects.push_back(
id);
529 QStringList subDirs = d.entryList(QDir::AllDirs|QDir::NoDotAndDotDot, QDir::Name);
530 for(
int i=subDirs.size()-1; i>=0; --i)
532 paths.prepend(currentDir + QDir::separator() + subDirs[i]);
537 if(loadedObjects.size())
542 return loadedObjects.size();
551 for(QMap<int, ObjWidget*>::const_iterator iter=
objWidgets_.constBegin(); iter!=
objWidgets_.constEnd(); ++iter)
553 if(iter.value()->pixmap().save(QString(
"%1/%2.png").arg(dirPath).arg(iter.key())))
559 UERROR(
"Failed to save object %d", iter.key());
569 QString dirPath = QFileDialog::getExistingDirectory(
this, tr(
"Loading objects... Select a directory."),
Settings::workingDirectory());
570 if(!dirPath.isEmpty())
573 bool recursive =
false;
574 if(d.entryList(QDir::AllDirs | QDir::NoDotAndDotDot).size())
576 QMessageBox::StandardButton b = QMessageBox::question(
578 tr(
"Loading objects..."),
579 tr(
"The current directory contains subdirectories. Load objects recursively?"),
580 QMessageBox::Yes|QMessageBox::No,
582 recursive = b == QMessageBox::Yes;
588 QMessageBox::information(
this, tr(
"Loading..."), tr(
"%1 objects loaded from \"%2\".").arg(count).arg(dirPath));
592 QMessageBox::information(
this, tr(
"Loading..."), tr(
"No objects loaded from \"%1\"!").arg(dirPath));
598 QString dirPath = QFileDialog::getExistingDirectory(
this, tr(
"Saving objects... Select a directory."),
Settings::workingDirectory());
599 if(!dirPath.isEmpty())
604 QMessageBox::information(
this, tr(
"Saving..."), tr(
"%1 objects saved to \"%2\".").arg(count).arg(dirPath));
608 QMessageBox::warning(
this, tr(
"Saving..."), tr(
"No objects saved to %1!").arg(dirPath));
617 if(!Settings::getGeneral_vocabularyFixed() ||
618 !Settings::getGeneral_invertedSearch())
620 QMessageBox::StandardButton b = QMessageBox::question(
this, tr(
"Load vocabulary..."),
621 tr(
"Parameters \"General/vocabularyFixed\" and \"General/invertedSearch\" should be enabled to load a vocabulary. " 622 "Do you want to enable them now?"),
623 QMessageBox::Cancel | QMessageBox::Yes);
624 if(b == QMessageBox::Yes)
626 Settings::setGeneral_vocabularyFixed(
true);
627 Settings::setGeneral_invertedSearch(
true);
630 if(Settings::getGeneral_vocabularyFixed() &&
631 Settings::getGeneral_invertedSearch())
633 QString path = QFileDialog::getOpenFileName(
this, tr(
"Load vocabulary..."),
Settings::workingDirectory(),
"Data (*.yaml *.xml)");
640 QMessageBox::information(
this, tr(
"Loading..."), tr(
"Vocabulary loaded from \"%1\" (%2 words).").arg(path).arg(
findObject_->
vocabulary()->
size()));
644 QMessageBox::warning(
this, tr(
"Loading..."), tr(
"Failed to load vocabulary \"%1\"!").arg(path));
654 QMessageBox::warning(
this, tr(
"Saving vocabulary..."), tr(
"Vocabulary is empty!"));
657 QString path = QFileDialog::getSaveFileName(
this, tr(
"Save vocabulary..."),
Settings::workingDirectory(),
"Data (*.yaml *.xml)");
660 if(QFileInfo(path).suffix().compare(
"yaml") != 0 && QFileInfo(path).suffix().compare(
"xml") != 0)
662 path.append(
".yaml");
666 QMessageBox::information(
this, tr(
"Saving..."), tr(
"Vocabulary saved to \"%1\" (%2 words).").arg(path).arg(
findObject_->
vocabulary()->
size()));
670 QMessageBox::warning(
this, tr(
"Saving..."), tr(
"Failed to save vocabulary \"%1\"!").arg(path));
682 ui_->actionSave_objects->setEnabled(
false);
683 ui_->actionSave_session->setEnabled(
false);
686 object->deleteLater();
687 if(Settings::getGeneral_autoUpdateObjects())
706 UERROR(
"Remove object: Object %d not found!",
id);
714 ui_->actionSave_objects->setEnabled(
false);
734 int value =
ui_->horizontalSlider_objectsSize->value();
735 if((obj->
pixmap().width()*value)/100 > 4 && (obj->
pixmap().height()*value)/100 > 4)
737 obj->setVisible(
true);
738 obj->setMinimumSize((obj->
pixmap().width()*value)/100, (obj->
pixmap().height())*value/100);
742 obj->setVisible(
false);
749 bool mirrorView = Settings::getGeneral_mirrorView();
750 ui_->imageView_source->setMirrorView(mirrorView);
753 iter.value()->setMirrorView(mirrorView);
759 ui_->widget_controls->setVisible(Settings::getGeneral_controlsShown());
766 iter.value()->setFeaturesShown(
true);
774 iter.value()->setFeaturesShown(
false);
780 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
792 if(dialog->exec() == QDialog::Accepted)
797 UASSERT(obj!=0 && signature!=0);
801 ui_->actionSave_objects->setEnabled(
true);
802 ui_->actionSave_session->setEnabled(
true);
805 ids.push_back(obj->
id());
815 connect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)), Qt::UniqueConnection);
830 for(
int i=0; i<fileNames.size(); ++i)
858 ui_->actionSave_objects->setEnabled(
true);
859 ui_->actionSave_session->setEnabled(
true);
865 QMessageBox::critical(
this, tr(
"Error adding object"), tr(
"Failed to add object from \"%1\"").arg(filePath));
874 UERROR(
"Add Object: Object %d is already added.",
id);
881 ui_->actionSave_objects->setEnabled(
true);
882 ui_->actionSave_session->setEnabled(
true);
885 ids.push_back(obj->
id());
890 UERROR(
"Add Object: Error adding object %d.",
id);
899 cv::Mat img = cv::imread(fileNames.first().toStdString().c_str());
903 ui_->label_timeRefreshRate->setVisible(
false);
910 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load scene..."),
Settings::workingDirectory(), tr(
"Image Files (%1)").arg(Settings::getGeneral_imageFormats()));
911 if(!fileName.isEmpty())
913 cv::Mat img = cv::imread(fileName.toStdString().c_str());
917 ui_->label_timeRefreshRate->setVisible(
false);
924 if(!
ui_->actionCamera_from_video_file->isChecked())
926 Settings::setCamera_5mediaPath(
"");
927 ui_->toolBox->updateParameter(Settings::kCamera_5mediaPath());
931 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Setup camera from video file..."),
Settings::workingDirectory(), tr(
"Video Files (%1)").arg(Settings::getGeneral_videoFormats()));
932 if(!fileName.isEmpty())
934 Settings::setCamera_6useTcpCamera(
false);
935 ui_->toolBox->updateParameter(Settings::kCamera_6useTcpCamera());
937 Settings::setCamera_5mediaPath(fileName);
938 ui_->toolBox->updateParameter(Settings::kCamera_5mediaPath());
944 Settings::setGeneral_controlsShown(
true);
945 ui_->toolBox->updateParameter(Settings::kGeneral_controlsShown());
948 ui_->actionCamera_from_video_file->setChecked(!Settings::getCamera_5mediaPath().isEmpty());
949 ui_->actionCamera_from_directory_of_images->setChecked(
false);
950 ui_->actionCamera_from_TCP_IP->setChecked(
false);
955 if(!
ui_->actionCamera_from_directory_of_images->isChecked())
957 Settings::setCamera_5mediaPath(
"");
958 ui_->toolBox->updateParameter(Settings::kCamera_5mediaPath());
962 QString directory = QFileDialog::getExistingDirectory(
this, tr(
"Setup camera from directory of images..."),
Settings::workingDirectory());
963 if(!directory.isEmpty())
965 Settings::setCamera_6useTcpCamera(
false);
966 ui_->toolBox->updateParameter(Settings::kCamera_6useTcpCamera());
968 Settings::setCamera_5mediaPath(directory);
969 ui_->toolBox->updateParameter(Settings::kCamera_5mediaPath());
975 Settings::setGeneral_controlsShown(
true);
976 ui_->toolBox->updateParameter(Settings::kGeneral_controlsShown());
979 ui_->actionCamera_from_directory_of_images->setChecked(!Settings::getCamera_5mediaPath().isEmpty());
980 ui_->actionCamera_from_video_file->setChecked(
false);
981 ui_->actionCamera_from_TCP_IP->setChecked(
false);
986 if(!
ui_->actionCamera_from_TCP_IP->isChecked())
988 Settings::setCamera_6useTcpCamera(
false);
989 ui_->toolBox->updateParameter(Settings::kCamera_6useTcpCamera());
994 int port = QInputDialog::getInt(
this, tr(
"Server port..."),
"Port: ", Settings::getCamera_8port(), 1, USHRT_MAX, 1, &ok);
998 int queue = QInputDialog::getInt(
this, tr(
"Queue size..."),
"Images buffer size (0 means infinite): ", Settings::getCamera_9queueSize(), 0, 2147483647, 1, &ok);
1001 Settings::setCamera_6useTcpCamera(
true);
1002 ui_->toolBox->updateParameter(Settings::kCamera_6useTcpCamera());
1003 Settings::setCamera_8port(port);
1004 ui_->toolBox->updateParameter(Settings::kCamera_8port());
1005 Settings::setCamera_9queueSize(queue);
1006 ui_->toolBox->updateParameter(Settings::kCamera_9queueSize());
1015 ui_->actionCamera_from_directory_of_images->setChecked(
false);
1016 ui_->actionCamera_from_video_file->setChecked(
false);
1017 ui_->actionCamera_from_TCP_IP->setChecked(Settings::getCamera_6useTcpCamera());
1026 QList<ObjWidget*> objs =
ui_->objects_area->findChildren<
ObjWidget*>();
1027 QVBoxLayout * vLayout =
new QVBoxLayout();
1028 ui_->toolBox->updateParameter(Settings::kGeneral_nextObjID());
1030 QLabel * title =
new QLabel(QString(
"%1 (%2)").arg(obj->
id()).arg(obj->
keypoints().size()),
this);
1031 QLabel * detectedLabel =
new QLabel(
this);
1032 title->setObjectName(QString(
"%1title").arg(obj->
id()));
1033 detectedLabel->setObjectName(QString(
"%1detection").arg(obj->
id()));
1034 QHBoxLayout * hLayout =
new QHBoxLayout();
1035 hLayout->addWidget(title);
1036 hLayout->addStretch(1);
1037 hLayout->addStretch(1);
1038 hLayout->addWidget(detectedLabel);
1039 vLayout->addLayout(hLayout);
1040 vLayout->addWidget(obj);
1043 connect(obj, SIGNAL(destroyed(QObject *)), title, SLOT(deleteLater()));
1044 connect(obj, SIGNAL(destroyed(QObject *)), detectedLabel, SLOT(deleteLater()));
1045 connect(obj, SIGNAL(destroyed(QObject *)), vLayout, SLOT(deleteLater()));
1046 ui_->verticalLayout_objects->insertLayout(
ui_->verticalLayout_objects->count()-1, vLayout);
1049 QBuffer buffer(&ba);
1050 buffer.open(QIODevice::WriteOnly);
1051 obj->
pixmap().scaledToWidth(128).save(&buffer,
"JPEG");
1055 int objectsPanelWidth =
ui_->dockWidget_objects->width();
1056 if(objectsPanelWidth > 0 && (obj->
pixmap().width()*
ui_->horizontalSlider_objectsSize->value()) / 100 > objectsPanelWidth)
1058 ui_->horizontalSlider_objectsSize->setValue((objectsPanelWidth * 100) / obj->
pixmap().width());
1076 this->statusBar()->showMessage(tr(
"Updating %1 objects...").arg(ids.size()==0?
objWidgets_.size():ids.size()));
1080 QList<int> idsTmp = ids;
1081 if(idsTmp.size() == 0)
1087 for(
int i=0; i<signatures.size(); ++i)
1089 if(idsTmp.contains(signatures[i]->id()))
1091 objWidgets_.value(signatures[i]->
id())->updateData(signatures[i]->keypoints());
1094 QLabel * title = this->findChild<QLabel*>(QString(
"%1title").arg(signatures[i]->
id()));
1095 title->setText(QString(
"%1 (%2)").arg(signatures[i]->
id()).arg(QString::number(signatures[i]->keypoints().size())));
1097 QLabel * label = this->findChild<QLabel*>(QString(
"%1detection").arg(signatures[i]->
id()));
1108 this->statusBar()->clearMessage();
1114 this->statusBar()->showMessage(tr(
"Updating vocabulary..."));
1120 QList<int> idsTmp = ids;
1121 if(idsTmp.size() == 0)
1126 for(
int i=0; i<signatures.size(); ++i)
1128 if(idsTmp.contains(signatures[i]->id()))
1130 objWidgets_.value(signatures[i]->
id())->updateWords(signatures[i]->words());
1134 ui_->label_timeIndexing->setNum(time.elapsed());
1136 if(ids.size() &&
findObject_->
vocabulary()->
size() == 0 && Settings::getGeneral_vocabularyFixed() && Settings::getGeneral_invertedSearch())
1138 QMessageBox::warning(
this, tr(
"Vocabulary update"), tr(
"\"General/VocabularyFixed=true\" and the " 1139 "vocabulary is empty. New features cannot be matched to any words in the vocabulary."));
1142 this->statusBar()->clearMessage();
1143 ui_->dockWidget_objects->update();
1148 UINFO(
"Starting camera...");
1149 bool updateStatusMessage = this->statusBar()->currentMessage().isEmpty();
1150 if(updateStatusMessage)
1152 this->statusBar()->showMessage(tr(
"Starting camera..."));
1156 connect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)), Qt::UniqueConnection);
1158 ui_->actionStop_camera->setEnabled(
true);
1159 ui_->actionPause_camera->setEnabled(
true);
1160 ui_->actionStart_camera->setEnabled(
false);
1161 ui_->actionLoad_scene_from_file->setEnabled(
false);
1162 ui_->actionCamera_from_directory_of_images->setEnabled(
false);
1163 ui_->actionCamera_from_video_file->setEnabled(
false);
1164 ui_->actionCamera_from_TCP_IP->setEnabled(
false);
1165 ui_->label_timeRefreshRate->setVisible(
true);
1168 ui_->pushButton_play->setVisible(
false);
1169 ui_->pushButton_pause->setVisible(
true);
1170 ui_->pushButton_stop->setEnabled(
true);
1174 ui_->label_frame->setVisible(
true);
1175 ui_->horizontalSlider_frames->setEnabled(
true);
1176 ui_->horizontalSlider_frames->setMaximum(totalFrames-1);
1180 ui_->label_port_image->setText(
"-");
1186 if(updateStatusMessage)
1188 this->statusBar()->showMessage(tr(
"Camera started."), 2000);
1193 if(updateStatusMessage)
1195 this->statusBar()->clearMessage();
1198 if(Settings::getCamera_6useTcpCamera())
1200 QMessageBox::critical(
this, tr(
"Camera error"), tr(
"Camera initialization failed! (with port %1)").arg(Settings::getCamera_8port()));
1204 QMessageBox::critical(
this, tr(
"Camera error"), tr(
"Camera initialization failed! (with device %1)").arg(Settings::getCamera_1deviceId()));
1213 disconnect(
camera_, SIGNAL(imageReceived(
const cv::Mat &)),
this, SLOT(
update(
const cv::Mat &)));
1217 ui_->actionStop_camera->setEnabled(
false);
1218 ui_->actionPause_camera->setEnabled(
false);
1219 ui_->actionStart_camera->setEnabled(
true);
1220 ui_->actionLoad_scene_from_file->setEnabled(
true);
1221 ui_->actionCamera_from_directory_of_images->setEnabled(
true);
1222 ui_->actionCamera_from_video_file->setEnabled(
true);
1223 ui_->actionCamera_from_TCP_IP->setEnabled(
true);
1224 ui_->pushButton_play->setVisible(
true);
1225 ui_->pushButton_pause->setVisible(
false);
1226 ui_->pushButton_stop->setEnabled(
false);
1227 ui_->horizontalSlider_frames->setEnabled(
false);
1228 ui_->horizontalSlider_frames->setValue(0);
1229 ui_->label_frame->setVisible(
false);
1230 ui_->label_port_image->setText(
"-");
1235 ui_->actionStop_camera->setEnabled(
true);
1236 ui_->actionPause_camera->setEnabled(
true);
1237 ui_->actionStart_camera->setEnabled(
false);
1240 ui_->pushButton_play->setVisible(
true);
1241 ui_->pushButton_pause->setVisible(
false);
1246 ui_->pushButton_play->setVisible(
false);
1247 ui_->pushButton_pause->setVisible(
true);
1254 if(
ui_->horizontalSlider_frames->isEnabled())
1266 if(objId>=0 && Settings::getGeneral_autoScroll())
1268 QLabel * label =
ui_->dockWidget_objects->findChild<QLabel*>(QString(
"%1title").arg(objId));
1271 ui_->objects_area->verticalScrollBar()->setValue(label->pos().y());
1280 UWARN(
"The image received is empty...");
1288 iter.value()->resetKptsColor();
1289 if(!Settings::getGeneral_invertedSearch())
1291 iter.value()->resetKptsWordID();
1295 QTime guiRefreshTime;
1300 guiRefreshTime.start();
1317 const QMap<int, QMultiMap<int, int> > & matches = info.
matches_;
1318 QMap<int, int> scores;
1319 int maxScoreId = -1;
1321 for(QMap<
int, QMultiMap<int, int> >::const_iterator jter=matches.constBegin(); jter!=matches.end();++jter)
1323 scores.insert(jter.key(), jter.value().size());
1324 if(maxScoreId == -1 || maxScore < jter.value().size())
1326 maxScoreId = jter.key();
1327 maxScore = jter.value().size();
1330 int id = jter.key();
1331 QLabel * label =
ui_->dockWidget_objects->findChild<QLabel*>(QString(
"%1detection").arg(
id));
1332 if(!Settings::getHomography_homographyComputed())
1334 label->setText(QString(
"%1 matches").arg(jter.value().size()));
1339 for(QMultiMap<int, int>::const_iterator iter = jter.value().constBegin(); iter!= jter.value().constEnd(); ++iter)
1342 ui_->imageView_source->setKptColor(iter.value(), obj->
color());
1343 if(!Settings::getGeneral_invertedSearch())
1345 obj->
setKptWordID(iter.key(),
ui_->imageView_source->words().value(iter.value(), -1));
1352 QLabel * label =
ui_->dockWidget_objects->findChild<QLabel*>(QString(
"%1detection").arg(
id));
1358 label->setText(QString(
"Too low matches (%1)").arg(jter.value().size()));
1362 label->setText(QString(
"Ignored, all inliers (%1 in %2 out)").arg(rejectedInliers.size()).arg(rejectedOutliers.size()));
1366 label->setText(QString(
"Not valid homography (%1 in %2 out)").arg(rejectedInliers.size()).arg(rejectedOutliers.size()));
1370 label->setText(QString(
"Too low inliers (%1 in %2 out)").arg(rejectedInliers.size()).arg(rejectedOutliers.size()));
1374 label->setText(QString(
"Corners not visible (%1 in %2 out)").arg(rejectedInliers.size()).arg(rejectedOutliers.size()));
1378 label->setText(QString(
"Angle too small (%1 in %2 out)").arg(rejectedInliers.size()).arg(rejectedOutliers.size()));
1389 int maxHomographyScoreId = -1;
1390 int maxHomographyScore = 0;
1391 QMultiMap<int, QMultiMap<int,int> >::const_iterator inliersIter = info.
objDetectedInliers_.constBegin();
1392 QMultiMap<int, QMultiMap<int,int> >::const_iterator outliersIter = info.
objDetectedOutliers_.constBegin();
1393 for(QMultiMap<int,QTransform>::iterator iter = info.
objDetected_.begin();
1395 ++iter, ++inliersIter, ++outliersIter)
1397 int id = iter.key();
1399 if(maxHomographyScoreId == -1 || maxHomographyScore < inliersIter.value().size())
1401 maxHomographyScoreId = id;
1402 maxHomographyScore = inliersIter.value().size();
1409 QTransform hTransform = iter.value();
1411 QRect rect = obj->
pixmap().rect();
1413 QPen rectPen(obj->
color());
1414 rectPen.setWidth(Settings::getHomography_rectBorderWidth());
1416 connect(rectItemScene, SIGNAL(hovered(
int)),
this, SLOT(
rectHovered(
int)));
1417 rectItemScene->setPen(rectPen);
1418 rectItemScene->setTransform(hTransform);
1419 ui_->imageView_source->addRect(rectItemScene);
1421 QGraphicsRectItem * rectItemObj =
new QGraphicsRectItem(rect);
1422 rectItemObj->setPen(rectPen);
1425 for(QMultiMap<int, int>::const_iterator iter = inliersIter.value().constBegin(); iter!= inliersIter.value().constEnd(); ++iter)
1428 ui_->imageView_source->setKptColor(iter.value(), obj->
color());
1429 if(!Settings::getGeneral_invertedSearch())
1431 obj->
setKptWordID(iter.key(),
ui_->imageView_source->words().value(iter.value(), -1));
1435 QLabel * label =
ui_->dockWidget_objects->findChild<QLabel*>(QString(
"%1detection").arg(
id));
1439 label->setText(QString(
"%1 objects found").arg(info.
objDetected_.count(
id)));
1443 label->setText(QString(
"%1 in %2 out").arg(inliersIter.value().size()).arg(outliersIter.value().size()));
1448 if(info.
objDetected_.size() && !Settings::getGeneral_autoScreenshotPath().isEmpty())
1450 QDir dir(Settings::getGeneral_autoScreenshotPath());
1453 QMessageBox::warning(
this, tr(
"Screenshot on detection"), tr(
"Directory \"%1\" doesn't " 1454 "exist, screenshot of the detection cannot be taken. Parameter \"%2\" is cleared.").arg(Settings::getGeneral_autoScreenshotPath()).arg(Settings::kGeneral_autoScreenshotPath()));
1455 Settings::setGeneral_autoScreenshotPath(
"");
1456 ui_->toolBox->updateParameter(Settings::kGeneral_autoScreenshotPath());
1460 QString path = Settings::getGeneral_autoScreenshotPath() + QDir::separator() + (QDateTime::currentDateTime().toString(
"yyMMddhhmmsszzz") +
".jpg");
1461 if(!
ui_->imageView_source->getSceneAsPixmap().save(path))
1463 UDEBUG(
"Failed to save screenshot \"%s\"! (%s is set)", path.toStdString().c_str(), Settings::kGeneral_autoScreenshotPath().toStdString().c_str());
1467 UINFO(
"Save screenshot \"%s\"! (%s is set)", path.toStdString().c_str(), Settings::kGeneral_autoScreenshotPath().toStdString().c_str());
1473 UDEBUG(
"Set likelihood score curve values (%d)", scores.size());
1475 QMap<int, int> inlierScores;
1476 for(QMap<int, int>::iterator iter=scores.begin(); iter!=scores.end(); ++iter)
1482 maxValue = values[0].size();
1483 for(
int i=1; i<values.size(); ++i)
1485 if(maxValue < values[i].size())
1487 maxValue = values[i].size();
1491 inlierScores.insert(iter.key(), maxValue);
1493 UDEBUG(
"Set inliers score curve values (%d)", inlierScores.size());
1495 if(
ui_->likelihoodPlot->isVisible())
1497 ui_->likelihoodPlot->update();
1504 if((maxScoreId>=0 || maxHomographyScoreId>=0) && Settings::getGeneral_autoScroll())
1506 QLabel * label =
ui_->dockWidget_objects->findChild<QLabel*>(QString(
"%1title").arg(maxHomographyScoreId>=0?maxHomographyScoreId:maxScoreId));
1509 ui_->objects_area->verticalScrollBar()->setValue(label->pos().y());
1516 UINFO(
"(%s) %d objects detected!",
1517 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str(),
1522 UINFO(
"(%s) Object %d detected!",
1523 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str(),
1526 else if(Settings::getGeneral_sendNoObjDetectedEvents())
1528 UINFO(
"(%s) No objects detected.",
1529 QTime::currentTime().toString(
"HH:mm:ss.zzz").toStdString().c_str());
1532 if(info.
objDetected_.size() > 0 || Settings::getGeneral_sendNoObjDetectedEvents())
1540 guiRefreshTime.start();
1544 this->statusBar()->showMessage(tr(
"Cannot search, objects must be updated!"));
1558 iter.value()->update();
1562 ui_->imageView_source->update();
1567 if(
ui_->horizontalSlider_frames->isEnabled())
1569 ui_->horizontalSlider_frames->blockSignals(
true);
1572 ui_->horizontalSlider_frames->blockSignals(
false);
1576 int refreshRate = qRound(1000.0
f/
float(
updateRate_.restart()));
1584 if(Settings::getCamera_4imageRate()>0.0)
1586 ui_->label_timeRefreshRate->setText(QString(
"(%1 Hz - %2 Hz)").arg(QString::number(Settings::getCamera_4imageRate())).arg(QString::number(
lowestRefreshRate_)));
1596 ui_->label_timeRefreshGUI->setNum(guiRefreshTime.elapsed());
1602 bool detectorDescriptorParamsChanged =
false;
1603 bool nearestNeighborParamsChanged =
false;
1604 bool parameterChanged =
false;
1605 for(QStringList::const_iterator iter = paramChanged.begin(); iter!=paramChanged.end(); ++iter)
1610 parameterChanged =
true;
1611 UINFO(
"Parameter changed: %s -> \"%s\"", iter->toStdString().c_str(),
Settings::getParameter(*iter).toString().toStdString().c_str());
1613 if(iter->contains(
"Feature2D"))
1615 detectorDescriptorParamsChanged =
true;
1617 else if( (iter->contains(
"NearestNeighbor") && Settings::getGeneral_invertedSearch()) ||
1618 iter->compare(Settings::kGeneral_invertedSearch()) == 0 ||
1619 (iter->compare(Settings::kGeneral_vocabularyIncremental()) == 0 && Settings::getGeneral_invertedSearch()) ||
1620 (iter->compare(Settings::kGeneral_vocabularyFixed()) == 0 && Settings::getGeneral_invertedSearch()) ||
1621 (iter->compare(Settings::kGeneral_threads()) == 0 && !Settings::getGeneral_invertedSearch()) )
1623 nearestNeighborParamsChanged =
true;
1626 if(iter->compare(Settings::kGeneral_port()) == 0 &&
1627 Settings::getGeneral_port() !=
ui_->label_port->text().toInt() &&
1628 Settings::getGeneral_port() != 0)
1635 if(detectorDescriptorParamsChanged)
1641 if(Settings::getGeneral_autoUpdateObjects())
1643 if(detectorDescriptorParamsChanged)
1647 else if(nearestNeighborParamsChanged)
1652 else if(
objWidgets_.size() && (detectorDescriptorParamsChanged || nearestNeighborParamsChanged))
1654 this->statusBar()->showMessage(tr(
"A parameter has changed... \"Update objects\" may be required."));
1657 if(parameterChanged &&
1660 !(Settings::getGeneral_autoUpdateObjects() && detectorDescriptorParamsChanged))
1663 ui_->label_timeRefreshRate->setVisible(
false);
1665 ui_->actionCamera_from_video_file->setChecked(!Settings::getCamera_5mediaPath().isEmpty() && !
UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()) && !Settings::getCamera_6useTcpCamera());
1666 ui_->actionCamera_from_directory_of_images->setChecked(!Settings::getCamera_5mediaPath().isEmpty() &&
UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()) && !Settings::getCamera_6useTcpCamera());
1667 ui_->actionCamera_from_TCP_IP->setChecked(Settings::getCamera_6useTcpCamera());
1669 if(Settings::getGeneral_debug())
void addObjectFromTcp(const cv::Mat &image, int id, const QString &filePath)
virtual void keyPressEvent(QKeyEvent *event)
void updateVocabulary(const QList< int > &ids=QList< int >())
void moveCameraFrame(int frame)
void setupCameraFromTcpIp()
static QVariant getParameter(const QString &key)
std::vector< double > values
const std::list< std::string > & getFileNames() const
void showObjectsFeatures()
std::vector< cv::KeyPoint > sceneKeypoints_
void updateObjectSize(find_object::ObjWidget *obj)
const QMap< int, ObjSignature * > & objects() const
QMultiMap< int, RejectedCode > rejectedCodes_
static void loadWindowSettings(QByteArray &windowGeometry, QByteArray &windowState, const QString &fileName=QString())
QMap< int, QMultiMap< int, int > > matches_
void setData(const QMap< int, int > &dataMap, const QMap< int, int > &weightsMap)
void addObjectsFromFiles()
static void setLevel(ULogger::Level level)
void setPen(const QPen &pen)
QHostAddress getHostAddress() const
void showObject(find_object::ObjWidget *obj)
#define UASSERT(condition)
static QString currentDetectorType()
static const ParametersMap & getParameters()
QMap< int, QByteArray > imagesMap_
void updateVocabulary(const QList< int > &ids=QList< int >())
void moveToFrame(int frame)
const cv::Mat & image() const
void setSourceImageText(const QString &text)
rtabmap::PdfPlotCurve * likelihoodCurve_
void removeObject(find_object::ObjWidget *object)
static void loadSettings(const QString &fileName=QString())
QMap< TimeStamp, float > timeStamps_
void updateDetectorExtractor()
QMap< QString, QVariant > lastObjectsUpdateParameters_
AboutDialog * aboutDialog_
bool loadVocabulary(const QString &filePath)
QMultiMap< int, QTransform > objDetected_
void updateObjects(const QList< int > &ids=QList< int >())
void notifyParametersChanged(const QStringList ¶m)
float minMatchedDistance_
QMap< QString, QVariant > ParametersMap
void update(const cv::Mat &image)
static QString currentDescriptorType()
rtabmap::PdfPlotCurve * inliersCurve_
QMultiMap< int, QMultiMap< int, int > > rejectedInliers_
static void setPrintWhere(bool printWhere)
void rectHovered(int objId)
QMultiMap< int, QMultiMap< int, int > > objDetectedInliers_
MainWindow(find_object::FindObject *findObject, find_object::Camera *camera=0, QWidget *parent=0)
static void saveWindowSettings(const QByteArray &windowGeometry, const QByteArray &windowState, const QString &fileName=QString())
static QString workingDirectory()
int addObjectFromFile(const QString &filePath)
void removeObject(int id)
virtual void closeEvent(QCloseEvent *event)
void addObjectFromScene()
const Vocabulary * vocabulary() const
bool loadSession(const QString &path)
bool saveSession(const QString &path)
QMultiMap< int, int > sceneWords_
ULogger class and convenient macros.
QMultiMap< int, QMultiMap< int, int > > rejectedOutliers_
static bool exists(const std::string &dirPath)
float maxMatchedDistance_
void setupCameraFromImagesDirectory()
QMultiMap< int, QMultiMap< int, int > > objDetectedOutliers_
int getCurrentFrameIndex()
static void saveSettings(const QString &fileName=QString())
const ObjSignature * addObject(const QString &filePath)
FINDOBJECT_EXP QImage cvtCvMat2QImage(const cv::Mat &image, bool isBgr=true)
void hideObjectsFeatures()
QMap< int, find_object::ObjWidget * > objWidgets_
bool detect(const cv::Mat &image, find_object::DetectionInfo &info) const
void objectsFound(const find_object::DetectionInfo &)
void setupCameraFromVideoFile()
void retrieveObject(ObjWidget **widget, ObjSignature **signature)
bool saveVocabulary(const QString &filePath) const