Commit 08179e6daab59c0637f82ca39e80e914279133e0

Authored by Jordan Cheney
1 parent 23bd6de4

Progress towards NPD

openbr/plugins/representation/npd.cpp
... ... @@ -26,6 +26,16 @@ class NPDRepresentation : public Representation
26 26 return features[idx].calc(image);
27 27 }
28 28  
  29 + Mat evaluate(const Mat &image, const QList<int> &indices) const
  30 + {
  31 + int size = indices.empty() ? numFeatures() : indices.size();
  32 +
  33 + Mat result(1, size, CV_32FC1);
  34 + for (int i = 0; i < size; i++)
  35 + result.at<float>(i) = evaluate(image, indices.empty() ? i : indices[i]);
  36 + return result;
  37 + }
  38 +
29 39 Size windowSize(int *dx, int *dy) const
30 40 {
31 41 if (dx && dy)
... ... @@ -33,6 +43,9 @@ class NPDRepresentation : public Representation
33 43 return Size(winWidth, winHeight);
34 44 }
35 45  
  46 + int numFeatures() const { return features.size(); }
  47 + int maxCatCount() const { return 0; }
  48 +
36 49 struct Feature
37 50 {
38 51 Feature() {}
... ... @@ -46,6 +59,13 @@ class NPDRepresentation : public Representation
46 59  
47 60 BR_REGISTER(Representation, NPDRepresentation)
48 61  
  62 +inline float NPDRepresentation::Feature::calc(const Mat &image) const
  63 +{
  64 + const int *ptr = image.ptr<int>();
  65 + int v1 = ptr[p[0]], v2 = ptr[p[1]];
  66 + return v1 == 0 && v2 == 0 ? 0 : ((float)(v1 - v2)) / (v1 + v2);
  67 +}
  68 +
49 69 } // namespace br
50 70  
51 71 #include "representation/npd.moc"
... ...