Commit bcf2d579ea3e1c7ae9a4acb4fe9265443743751b
1 parent
2db5366c
Added filelist sorting by metadata key
Showing
5 changed files
with
41 additions
and
5 deletions
app/openbr-gui/initialize.cpp
| ... | ... | @@ -20,13 +20,13 @@ |
| 20 | 20 | |
| 21 | 21 | #include "initialize.h" |
| 22 | 22 | |
| 23 | -void br_initialize_gui() | |
| 23 | +void br_initialize_gui(const char *sdk_path) | |
| 24 | 24 | { |
| 25 | 25 | Q_INIT_RESOURCE(icons); |
| 26 | 26 | qRegisterMetaType<br::File>("br::File"); |
| 27 | 27 | qRegisterMetaType<br::FileList>("br::FileList"); |
| 28 | 28 | qRegisterMetaType<br::Template>("br::Template"); |
| 29 | 29 | qRegisterMetaType<br::TemplateList>("br::TemplateList"); |
| 30 | - br_initialize_qt(); | |
| 30 | + br_initialize_qt(sdk_path); | |
| 31 | 31 | br_set_property("log", qPrintable(QString("%1/log.txt").arg(br_scratch_path()))); |
| 32 | 32 | } | ... | ... |
app/openbr-gui/initialize.h
sdk/openbr_plugin.cpp
| ... | ... | @@ -26,6 +26,8 @@ |
| 26 | 26 | #endif // BR_DISTRIBUTED |
| 27 | 27 | #include <openbr_plugin.h> |
| 28 | 28 | |
| 29 | +#include <algorithm> | |
| 30 | + | |
| 29 | 31 | #include "version.h" |
| 30 | 32 | #include "core/bee.h" |
| 31 | 33 | #include "core/common.h" |
| ... | ... | @@ -357,6 +359,38 @@ QStringList FileList::names() const |
| 357 | 359 | return names; |
| 358 | 360 | } |
| 359 | 361 | |
| 362 | +typedef std::pair<std::string,int> metadataPair; | |
| 363 | +bool comparator( const metadataPair &l, const metadataPair &r) | |
| 364 | +{ | |
| 365 | + return l.first < r.first; | |
| 366 | +} | |
| 367 | + | |
| 368 | +void FileList::sort(const QString& key) | |
| 369 | +{ | |
| 370 | + std::vector<metadataPair> metadata; | |
| 371 | + | |
| 372 | + int i = 0; | |
| 373 | + | |
| 374 | + foreach (const File &file, *this) | |
| 375 | + { | |
| 376 | + metadataPair pair = std::make_pair(file.get(key).toString().toStdString().c_str(), i); | |
| 377 | + metadata.push_back(pair); | |
| 378 | + i++; | |
| 379 | + } | |
| 380 | + | |
| 381 | + std::sort(metadata.begin(), metadata.end(), comparator); | |
| 382 | + | |
| 383 | + for (int j = 0; j < metadata.size(); j++) | |
| 384 | + { | |
| 385 | + this->push_back(this->at(metadata[j].second)); | |
| 386 | + } | |
| 387 | + | |
| 388 | + iterator half = this->begin(); | |
| 389 | + half += metadata.size(); | |
| 390 | + | |
| 391 | + this->erase(this->begin(), half); | |
| 392 | +} | |
| 393 | + | |
| 360 | 394 | QList<float> FileList::labels() const |
| 361 | 395 | { |
| 362 | 396 | QList<float> labels; | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -118,7 +118,7 @@ void reset_##NAME() { NAME = DEFAULT; } |
| 118 | 118 | * --- | ---- | ----------- |
| 119 | 119 | * path | QString | Resolve complete file paths from file names |
| 120 | 120 | * enrollAll | bool | Enroll zero or more templates per file |
| 121 | - * separator | QString | Sperate #name into multiple files | |
| 121 | + * separator | QString | Seperate #name into multiple files | |
| 122 | 122 | * Input_Index | int | Index of a template in a template list |
| 123 | 123 | * Label | float | Classification/Regression class |
| 124 | 124 | * Confidence | float | Classification/Regression quality |
| ... | ... | @@ -135,6 +135,7 @@ void reset_##NAME() { NAME = DEFAULT; } |
| 135 | 135 | * Yaw | float | Pose |
| 136 | 136 | * Landmarks | QList<QPointF> | Landmark list |
| 137 | 137 | * ROIs | QList<Rect> | Region Of Interest (ROI) list |
| 138 | + * Age | QString | Age used for demographic filtering | |
| 138 | 139 | * _* | * | Reserved for internal use |
| 139 | 140 | */ |
| 140 | 141 | struct BR_EXPORT File |
| ... | ... | @@ -239,6 +240,7 @@ struct BR_EXPORT FileList : public QList<File> |
| 239 | 240 | |
| 240 | 241 | QStringList flat() const; /*!< \brief Returns br::File::flat() for each file in the list. */ |
| 241 | 242 | QStringList names() const; /*!< \brief Returns #br::File::name for each file in the list. */ |
| 243 | + void sort(const QString& key); /*!< \brief Sort the list based on metadata. */ | |
| 242 | 244 | QList<float> labels() const; /*!< \brief Returns br::File::label() for each file in the list. */ |
| 243 | 245 | int failures() const; /*!< \brief Returns the number of files with br::File::failed(). */ |
| 244 | 246 | }; | ... | ... |