Commit 46bec4ccfa1ad93c357237e0eb0271acf81c8729

Authored by Scott Klum
2 parents 7f9ce2db ea944804

Merge branch 'master' of https://github.com/biometrics/openbr

sdk/plugins/compare.cpp
@@ -42,7 +42,7 @@ public: @@ -42,7 +42,7 @@ public:
42 INF, 42 INF,
43 L1, 43 L1,
44 L2, 44 L2,
45 - CosineSimilarity }; 45 + Cosine };
46 46
47 private: 47 private:
48 BR_PROPERTY(Metric, metric, L2) 48 BR_PROPERTY(Metric, metric, L2)
@@ -76,8 +76,8 @@ private: @@ -76,8 +76,8 @@ private:
76 case L2: 76 case L2:
77 result = norm(a, b, NORM_L2); 77 result = norm(a, b, NORM_L2);
78 break; 78 break;
79 - case CosineSimilarity:  
80 - result = cosineSimilarity(a, b); 79 + case Cosine:
  80 + result = cosine(a, b);
81 break; 81 break;
82 default: 82 default:
83 qFatal("Invalid metric"); 83 qFatal("Invalid metric");
@@ -89,33 +89,29 @@ private: @@ -89,33 +89,29 @@ private:
89 return -log(result+1); 89 return -log(result+1);
90 } 90 }
91 91
92 - static float cosineSimilarity(const Mat &a, const Mat &b) 92 + static float cosine(const Mat &a, const Mat &b)
93 { 93 {
94 - assert((a.type() == CV_32FC1) && (b.type() == CV_32FC1));  
95 - assert((a.rows == b.rows) && (a.cols == b.cols));  
96 -  
97 - float denom = 0;  
98 - float tnum = 0;  
99 - float qnum = 0; 94 + float dot = 0;
  95 + float magA = 0;
  96 + float magB = 0;
100 97
101 for (int row=0; row<a.rows; row++) { 98 for (int row=0; row<a.rows; row++) {
102 for (int col=0; col<a.cols; col++) { 99 for (int col=0; col<a.cols; col++) {
103 - float target = a.at<float>(row,col);  
104 - float query = b.at<float>(row,col); 100 + const float target = a.at<float>(row,col);
  101 + const float query = b.at<float>(row,col);
105 102
106 - denom += target * query;  
107 - tnum += target * target;  
108 - qnum += query * query; 103 + dot += target * query;
  104 + magA += target * target;
  105 + magB += query * query;
109 } 106 }
110 } 107 }
111 108
112 - return denom / (sqrt(tnum)*sqrt(qnum)); 109 + return dot / (sqrt(magA)*sqrt(magB));
113 } 110 }
114 }; 111 };
115 112
116 BR_REGISTER(Distance, Dist) 113 BR_REGISTER(Distance, Dist)
117 114
118 -  
119 /*! 115 /*!
120 * \ingroup distances 116 * \ingroup distances
121 * \brief Fast 8-bit L1 distance 117 * \brief Fast 8-bit L1 distance
sdk/plugins/regions.cpp
@@ -79,23 +79,29 @@ BR_REGISTER(Transform, ByRow) @@ -79,23 +79,29 @@ BR_REGISTER(Transform, ByRow)
79 class Cat : public UntrainableMetaTransform 79 class Cat : public UntrainableMetaTransform
80 { 80 {
81 Q_OBJECT 81 Q_OBJECT
  82 + Q_PROPERTY(int partitions READ get_partitions WRITE set_partitions RESET reset_partitions)
  83 + BR_PROPERTY(int, partitions, 1)
82 84
83 void project(const Template &src, Template &dst) const 85 void project(const Template &src, Template &dst) const
84 { 86 {
85 - int vals = 0;  
86 - foreach (const cv::Mat &m, src)  
87 - vals += m.total() * m.channels();  
88 -  
89 - Mat cat(1, (int)vals, CV_32FC1);  
90 - int offset = 0;  
91 - foreach (const cv::Mat &m, src) {  
92 - size_t size = m.total() * m.elemSize();  
93 - memcpy(&cat.data[offset], m.ptr(), size);  
94 - offset += size;  
95 - }  
96 -  
97 dst.file = src.file; 87 dst.file = src.file;
98 - dst = cat; 88 +
  89 + if (src.size() % partitions != 0)
  90 + qFatal("Cat %d partitions does not evenly divide %d matrices.", partitions, src.size());
  91 + QVector<int> sizes(partitions, 0);
  92 + for (int i=0; i<src.size(); i++)
  93 + sizes[i%partitions] += src[i].total() * src[i].channels();
  94 +
  95 + foreach (int size, sizes)
  96 + dst.append(Mat(1, size, CV_32FC1));
  97 +
  98 + QVector<int> offsets(partitions, 0);
  99 + for (int i=0; i<src.size(); i++) {
  100 + size_t size = src[i].total() * src[i].elemSize();
  101 + int j = i%partitions;
  102 + memcpy(&dst[j].data[offsets[j]], src[i].ptr(), size);
  103 + offsets[j] += size;
  104 + }
99 } 105 }
100 }; 106 };
101 107
1 -Subproject commit 1031e9e416427f5dd8e9f4e7ff4dd74632626c22 1 +Subproject commit 19d116e16c35c55691e68ff137a48beb1f8ebf64
share/openbr/openbr.bib
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 @misc{mburge, 24 @misc{mburge,
25 Author = {Dr. Mark J. Burge}, 25 Author = {Dr. Mark J. Burge},
26 Howpublished = {https://github.com/mburge}, 26 Howpublished = {https://github.com/mburge},
27 - Title = {mburge at ieee.org}} 27 + Title = {mburge at gmail.com}}
28 28
29 @misc{bklare, 29 @misc{bklare,
30 Author = {Dr. Brendan F. Klare}, 30 Author = {Dr. Brendan F. Klare},