From fe1fc48b33ebd917553eae6e837f787b10c1589f Mon Sep 17 00:00:00 2001 From: Olga Vysotska Date: Tue, 14 Nov 2017 16:07:22 +0100 Subject: [PATCH] feature files can have arbitrary names --- src/database/list_dir.cpp | 2 +- src/database/online_database.cpp | 8 ++--- src/database/online_database.h | 2 -- src/visualizer/match_viewer.cpp | 61 ++++++++++---------------------- src/visualizer/match_viewer.h | 37 ++++++------------- 5 files changed, 32 insertions(+), 78 deletions(-) diff --git a/src/database/list_dir.cpp b/src/database/list_dir.cpp index ecfefb8..7f5b8d4 100644 --- a/src/database/list_dir.cpp +++ b/src/database/list_dir.cpp @@ -35,7 +35,7 @@ std::vector listDir(const std::string &dir_name) { struct dirent *ent; /* print all the files and directories within directory */ while ((ent = readdir(dir)) != NULL) { - file_names.push_back(ent->d_name); + file_names.push_back( dir_name + ent->d_name); } std::sort(file_names.begin(), file_names.end()); closedir(dir); diff --git a/src/database/online_database.cpp b/src/database/online_database.cpp index 6ca464a..0f0186d 100644 --- a/src/database/online_database.cpp +++ b/src/database/online_database.cpp @@ -81,11 +81,9 @@ double OnlineDatabase::getCost(int quId, int refId) { } void OnlineDatabase::setQuFeaturesFolder(const std::string &path2folder) { - _quFeaturesFolder = path2folder; _quFeaturesNames = listDir(path2folder); } void OnlineDatabase::setRefFeaturesFolder(const std::string &path2folder) { - _refFeaturesFolder = path2folder; _refFeaturesNames = listDir(path2folder); } @@ -121,7 +119,7 @@ double OnlineDatabase::computeMatchCost(int quId, int refId) { } else { // We cannot directly set const pointers, so set them through a proxy. auto tempFeaturePtr = _featureFactory.createFeature(); - tempFeaturePtr->loadFromFile(_quFeaturesFolder + _quFeaturesNames[quId]); + tempFeaturePtr->loadFromFile( _quFeaturesNames[quId]); quFeaturePtr = tempFeaturePtr; _quBuff.addFeature(quId, quFeaturePtr); } @@ -131,7 +129,7 @@ double OnlineDatabase::computeMatchCost(int quId, int refId) { } else { // We cannot directly set const pointers, so set them through a proxy. auto tempFeaturePtr = _featureFactory.createFeature(); - tempFeaturePtr->loadFromFile(_refFeaturesFolder + _refFeaturesNames[refId]); + tempFeaturePtr->loadFromFile(_refFeaturesNames[refId]); refFeaturePtr = tempFeaturePtr; _refBuff.addFeature(refId, refFeaturePtr); } @@ -163,7 +161,7 @@ iFeature::ConstPtr OnlineDatabase::getQueryFeature(int quId) { } else { // We cannot directly set const pointers, so set them through a proxy. auto tempFeaturePtr = _featureFactory.createFeature(); - tempFeaturePtr->loadFromFile(_quFeaturesFolder + _quFeaturesNames[quId]); + tempFeaturePtr->loadFromFile(_quFeaturesNames[quId]); quFeaturePtr = tempFeaturePtr; _quBuff.addFeature(quId, quFeaturePtr); } diff --git a/src/database/online_database.h b/src/database/online_database.h index 0827f19..d8793fe 100644 --- a/src/database/online_database.h +++ b/src/database/online_database.h @@ -75,8 +75,6 @@ class OnlineDatabase : public iDatabase { protected: MatchMap _matchMap; - std::string _quFeaturesFolder = ""; - std::string _refFeaturesFolder = ""; std::vector _quFeaturesNames, _refFeaturesNames; FeatureFactory _featureFactory; diff --git a/src/visualizer/match_viewer.cpp b/src/visualizer/match_viewer.cpp index ee23531..779eeae 100644 --- a/src/visualizer/match_viewer.cpp +++ b/src/visualizer/match_viewer.cpp @@ -1,25 +1,7 @@ -/** vpr_relocalization: a library for visual place recognition in changing -** environments with efficient relocalization step. -** Copyright (c) 2017 O. Vysotska, C. Stachniss, University of Bonn -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to deal -** in the Software without restriction, including without limitation the rights -** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -** copies of the Software, and to permit persons to whom the Software is -** furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -**/ +/* Copyright Olga Vysotska, year 2017. +** In case of any problems with the code please contact me. +** Email: olga.vysotska@uni-bonn.de. +*/ #include "visualizer/match_viewer.h" @@ -27,14 +9,15 @@ #include #include #include +#include MatchViewer::MatchViewer() {} bool MatchViewer::init(int width, int height) { - // if (_queryImages.empty() || _refImages.empty()) { - // printf("[ERROR][MatchViewer] Images were not set\n"); - // return false; - // } + if (_queryImages.empty() || _refImages.empty()) { + printf("[ERROR][MatchViewer] Images were not set\n"); + return false; + } this->setDragMode(QGraphicsView::ScrollHandDrag); this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); // this->setScene(&_scene); @@ -102,12 +85,7 @@ void MatchViewer::wheelEvent(QWheelEvent *event) { void MatchViewer::receivedMatch(int quId, int refId, bool hidden) { // printf("Received match %d %d \n", quId, refId); std::string qu_path, ref_path; - - qu_path = _database->getQuFeatureName(quId); - qu_path = _quImagesFolder + qu_path; - // chop out '-feature.txt' -> 12 symbols - qu_path.erase(qu_path.end() - 12, qu_path.end()); - qu_path += _imgExt; + qu_path = _queryImages[quId]; QPixmap img_qu; img_qu.load(qu_path.c_str()); @@ -132,11 +110,8 @@ void MatchViewer::receivedMatch(int quId, int refId, bool hidden) { _textItem->setZValue(1); } else { _textItem->setVisible(false); - ref_path = _database->getRefFeatureName(refId); - ref_path = _refImagesFolder + ref_path; - // chop out '-feature.txt' -> 12 symbols - ref_path.erase(ref_path.end() - 12, ref_path.end()); - ref_path += _imgExt; + + ref_path = _refImages[refId]; QPixmap img_ref; // printf("[MatchViewer] reading image %s\n", ref_path.c_str()); @@ -158,11 +133,11 @@ bool MatchViewer::isReady() const { printf("[ERROR][MatchViewer] Database is not set\n"); return false; } - if (_quImagesFolder.empty()) { + if (_queryImages.empty()) { printf("[ERROR][MatchViewer] Folder for query images is not set\n"); return false; } - if (_refImagesFolder.empty()) { + if (_refImages.empty()) { printf("[ERROR][MatchViewer] Folder for reference images is not set\n"); return false; } @@ -174,10 +149,10 @@ bool MatchViewer::isReady() const { return true; } -void MatchViewer::setQuImageDirectory(const std::string &folder) { - _quImagesFolder = folder; +void MatchViewer::setQueryImages(const std::string &folder) { + _queryImages = listDir(folder); } -void MatchViewer::setRefImageDirectory(const std::string &folder) { - _refImagesFolder = folder; +void MatchViewer::setRefImages(const std::string &folder) { + _refImages = listDir(folder); } void MatchViewer::setImageExtension(const std::string &ext) { _imgExt = ext; } diff --git a/src/visualizer/match_viewer.h b/src/visualizer/match_viewer.h index e4d875a..7462e79 100644 --- a/src/visualizer/match_viewer.h +++ b/src/visualizer/match_viewer.h @@ -1,25 +1,7 @@ -/** vpr_relocalization: a library for visual place recognition in changing -** environments with efficient relocalization step. -** Copyright (c) 2017 O. Vysotska, C. Stachniss, University of Bonn -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to deal -** in the Software without restriction, including without limitation the rights -** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -** copies of the Software, and to permit persons to whom the Software is -** furnished to do so, subject to the following conditions: -** -** The above copyright notice and this permission notice shall be included in -** all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -**/ +/* Copyright Olga Vysotska, year 2017. +** In case of any problems with the code please contact me. +** Email: olga.vysotska@uni-bonn.de. +*/ #ifndef SRC_VISUALIZER_MATCH_VIEWER_H_ #define SRC_VISUALIZER_MATCH_VIEWER_H_ @@ -31,6 +13,7 @@ #include #include #include +#include #include "database/online_database.h" #include "online_localizer/online_localizer.h" @@ -47,10 +30,10 @@ class MatchViewer : public QGraphicsView { MatchViewer(); ~MatchViewer(); - + bool setDatabase(OnlineDatabase::Ptr database); - void setQuImageDirectory(const std::string &folder); - void setRefImageDirectory(const std::string &folder); + void setQueryImages(const std::string &folder); + void setRefImages(const std::string &folder); void setImageExtension(const std::string &ext); bool isReady() const; @@ -62,8 +45,8 @@ class MatchViewer : public QGraphicsView { void receivedMatch(int quId, int refId, bool hidden); private: - std::string _refImagesFolder = ""; - std::string _quImagesFolder = ""; + std::vector _refImages; + std::vector _queryImages; std::string _imgExt = ""; // variable for storing two single images