Commit b9e7e4b22bb0fd7ca3af14c6a20eabe3a9a75f16

Authored by Josh Klontz
1 parent e9169ab6

rewrote csvGallery

Showing 1 changed file with 43 additions and 11 deletions
sdk/plugins/gallery.cpp
@@ -22,13 +22,13 @@ @@ -22,13 +22,13 @@
22 #include <QSqlQuery> 22 #include <QSqlQuery>
23 #include <QSqlRecord> 23 #include <QSqlRecord>
24 #endif // BR_EMBEDDED 24 #endif // BR_EMBEDDED
  25 +#include <opencv2/highgui/highgui.hpp>
25 #include <openbr_plugin.h> 26 #include <openbr_plugin.h>
26 27
27 #include "NaturalStringCompare.h" 28 #include "NaturalStringCompare.h"
28 #include "core/bee.h" 29 #include "core/bee.h"
29 #include "core/opencvutils.h" 30 #include "core/opencvutils.h"
30 #include "core/qtutils.h" 31 #include "core/qtutils.h"
31 -#include <opencv2/highgui/highgui.hpp>  
32 32
33 namespace br 33 namespace br
34 { 34 {
@@ -339,20 +339,33 @@ class csvGallery : public Gallery @@ -339,20 +339,33 @@ class csvGallery : public Gallery
339 { 339 {
340 if (files.isEmpty()) return; 340 if (files.isEmpty()) return;
341 341
342 - QStringList keys; 342 + QMap<QString,QVariant> samples;
343 foreach (const File &file, files) 343 foreach (const File &file, files)
344 foreach (const QString &key, file.localKeys()) 344 foreach (const QString &key, file.localKeys())
345 - if (!keys.contains(key)) keys += key;  
346 - qSort(keys); 345 + if (!samples.contains(key))
  346 + samples.insert(key, file.value(key));
  347 +
  348 + QStringList lines;
  349 + lines.reserve(files.size()+1);
  350 +
  351 + { // Make header
  352 + QStringList words;
  353 + words.append("File");
  354 + foreach (const QString &key, samples.keys())
  355 + words.append(getCSVElement(key, samples[key], true));
  356 + lines.append(words.join(","));
  357 + }
347 358
348 - const int rows = files.size();  
349 - const int columns = keys.size();  
350 - QSharedPointer<Output> output(Output::make(file, keys, files)); 359 + // Make table
  360 + foreach (const File &file, files) {
  361 + QStringList words;
  362 + words.append(file.name);
  363 + foreach (const QString &key, samples.keys())
  364 + words.append(getCSVElement(key, file.value(key), false));
  365 + lines.append(words.join(","));
  366 + }
351 367
352 - for (int i=0; i<rows; i++)  
353 - for (int j=0; j<columns; j++)  
354 - if (keys[j] == "Label") output->setRelative(files[i].label(), i, j);  
355 - else output->setRelative(files[i].get<float>(keys[j], std::numeric_limits<float>::quiet_NaN()), i, j); 368 + QtUtils::writeFile(file, lines);
356 } 369 }
357 370
358 TemplateList readBlock(bool *done) 371 TemplateList readBlock(bool *done)
@@ -377,6 +390,25 @@ class csvGallery : public Gallery @@ -377,6 +390,25 @@ class csvGallery : public Gallery
377 { 390 {
378 files.append(t.file); 391 files.append(t.file);
379 } 392 }
  393 +
  394 + static QString getCSVElement(const QString &key, const QVariant &value, bool header)
  395 + {
  396 + if (value.canConvert<QString>()) {
  397 + if (header) return key;
  398 + else return value.value<QString>();
  399 + } else if (value.canConvert<QPointF>()) {
  400 + const QPointF point = value.value<QPointF>();
  401 + if (header) return key+"_X,"+key+"_Y";
  402 + else return QString::number(point.x())+","+QString::number(point.y());
  403 + } else if (value.canConvert<QRectF>()) {
  404 + const QRectF rect = value.value<QRectF>();
  405 + if (header) return key+"_X,"+key+"_Y,"+key+"_Width,"+key+"_Height";
  406 + else return QString::number(rect.x())+","+QString::number(rect.y())+","+QString::number(rect.width())+","+QString::number(rect.height());
  407 + } else {
  408 + if (header) return key;
  409 + else return QString::number(std::numeric_limits<float>::quiet_NaN());
  410 + }
  411 + }
380 }; 412 };
381 413
382 BR_REGISTER(Gallery, csvGallery) 414 BR_REGISTER(Gallery, csvGallery)