Commit e964525cd7a962f3dd03f063c1eb8f6b9d38c3ca

Authored by Josh Klontz
1 parent e02add41

implemented Format::write functions

Showing 1 changed file with 16 additions and 4 deletions
sdk/plugins/format.cpp
@@ -24,6 +24,8 @@ @@ -24,6 +24,8 @@
24 #include <openbr_plugin.h> 24 #include <openbr_plugin.h>
25 25
26 #include "core/bee.h" 26 #include "core/bee.h"
  27 +#include "core/opencvutils.h"
  28 +#include "core/qtutils.h"
27 29
28 using namespace br; 30 using namespace br;
29 using namespace cv; 31 using namespace cv;
@@ -68,8 +70,19 @@ class csvFormat : public Format @@ -68,8 +70,19 @@ class csvFormat : public Format
68 70
69 void write(const Template &t) const 71 void write(const Template &t) const
70 { 72 {
71 - (void) t;  
72 - qFatal("csvFormat::write not supported."); 73 + const Mat &m = t.m();
  74 + if (t.size() != 1) qFatal("csvFormat::write only supports single matrix templates.");
  75 + if (m.channels() != 1) qFatal("csvFormat::write only supports single channel matrices.");
  76 +
  77 + QStringList lines; lines.reserve(m.rows);
  78 + for (int r=0; r<m.rows; r++) {
  79 + QStringList elements; elements.reserve(m.cols);
  80 + for (int c=0; c<m.cols; c++)
  81 + elements.append(OpenCVUtils::elemToString(m, r, c));
  82 + lines.append(elements.join(","));
  83 + }
  84 +
  85 + QtUtils::writeFile(file, lines);
73 } 86 }
74 }; 87 };
75 88
@@ -116,8 +129,7 @@ class DefaultFormat : public Format @@ -116,8 +129,7 @@ class DefaultFormat : public Format
116 129
117 void write(const Template &t) const 130 void write(const Template &t) const
118 { 131 {
119 - (void) t;  
120 - qFatal("csvFormat::write not supported."); 132 + imwrite(file.name.toStdString(), t);
121 } 133 }
122 }; 134 };
123 135