Commit eaf723c9e2b108f7ba8dcacddeb45091e61613ad

Authored by Scott Klum
1 parent 6163c973

Changes to fusedistance

Showing 1 changed file with 17 additions and 10 deletions
openbr/plugins/distance/fuse.cpp
@@ -31,7 +31,7 @@ class FuseDistance : public Distance @@ -31,7 +31,7 @@ class FuseDistance : public Distance
31 { 31 {
32 Q_OBJECT 32 Q_OBJECT
33 Q_ENUMS(Operation) 33 Q_ENUMS(Operation)
34 - Q_PROPERTY(QString description READ get_description WRITE set_description RESET reset_description STORED false) 34 + Q_PROPERTY(QStringList descriptions READ get_descriptions WRITE set_descriptions RESET reset_descriptions STORED false)
35 Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false) 35 Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false)
36 Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false) 36 Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false)
37 37
@@ -42,10 +42,17 @@ public: @@ -42,10 +42,17 @@ public:
42 enum Operation {Mean, Sum, Max, Min}; 42 enum Operation {Mean, Sum, Max, Min};
43 43
44 private: 44 private:
45 - BR_PROPERTY(QString, description, "L2") 45 + BR_PROPERTY(QStringList, descriptions, QStringList() << "L2")
46 BR_PROPERTY(Operation, operation, Mean) 46 BR_PROPERTY(Operation, operation, Mean)
47 BR_PROPERTY(QList<float>, weights, QList<float>()) 47 BR_PROPERTY(QList<float>, weights, QList<float>())
48 48
  49 + void init()
  50 + {
  51 + for (int i=0; i<descriptions.size(); i++) {
  52 + distances.append(make(descriptions[i]));
  53 + }
  54 + }
  55 +
49 void train(const TemplateList &src) 56 void train(const TemplateList &src)
50 { 57 {
51 // Partition the templates by matrix 58 // Partition the templates by matrix
@@ -54,12 +61,11 @@ private: @@ -54,12 +61,11 @@ private:
54 61
55 QList<TemplateList> partitionedSrc = src.partition(split); 62 QList<TemplateList> partitionedSrc = src.partition(split);
56 63
57 - while (distances.size() < partitionedSrc.size())  
58 - distances.append(make(description));  
59 -  
60 // Train on each of the partitions 64 // Train on each of the partitions
61 - for (int i=0; i<distances.size(); i++) 65 + for (int i=0; i<descriptions.size(); i++) {
  66 + distances.append(make(descriptions[i]));
62 distances[i]->train(partitionedSrc[i]); 67 distances[i]->train(partitionedSrc[i]);
  68 + }
63 } 69 }
64 70
65 float compare(const Template &a, const Template &b) const 71 float compare(const Template &a, const Template &b) const
@@ -103,10 +109,11 @@ private: @@ -103,10 +109,11 @@ private:
103 { 109 {
104 int numDistances; 110 int numDistances;
105 stream >> numDistances; 111 stream >> numDistances;
106 - while (distances.size() < numDistances)  
107 - distances.append(make(description));  
108 - foreach (Distance *distance, distances)  
109 - distance->load(stream); 112 + for (int i=0; i<descriptions.size(); i++) {
  113 + distances.append(make(descriptions[i]));
  114 + distances[i]->load(stream);
  115 + }
  116 +
110 } 117 }
111 }; 118 };
112 119