From 08179e6daab59c0637f82ca39e80e914279133e0 Mon Sep 17 00:00:00 2001 From: Jordan Cheney Date: Fri, 22 May 2015 13:39:36 -0400 Subject: [PATCH] Progress towards NPD --- openbr/plugins/representation/npd.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+), 0 deletions(-) diff --git a/openbr/plugins/representation/npd.cpp b/openbr/plugins/representation/npd.cpp index 0c1a9f9..30f1c5e 100644 --- a/openbr/plugins/representation/npd.cpp +++ b/openbr/plugins/representation/npd.cpp @@ -26,6 +26,16 @@ class NPDRepresentation : public Representation return features[idx].calc(image); } + Mat evaluate(const Mat &image, const QList &indices) const + { + int size = indices.empty() ? numFeatures() : indices.size(); + + Mat result(1, size, CV_32FC1); + for (int i = 0; i < size; i++) + result.at(i) = evaluate(image, indices.empty() ? i : indices[i]); + return result; + } + Size windowSize(int *dx, int *dy) const { if (dx && dy) @@ -33,6 +43,9 @@ class NPDRepresentation : public Representation return Size(winWidth, winHeight); } + int numFeatures() const { return features.size(); } + int maxCatCount() const { return 0; } + struct Feature { Feature() {} @@ -46,6 +59,13 @@ class NPDRepresentation : public Representation BR_REGISTER(Representation, NPDRepresentation) +inline float NPDRepresentation::Feature::calc(const Mat &image) const +{ + const int *ptr = image.ptr(); + int v1 = ptr[p[0]], v2 = ptr[p[1]]; + return v1 == 0 && v2 == 0 ? 0 : ((float)(v1 - v2)) / (v1 + v2); +} + } // namespace br #include "representation/npd.moc" -- libgit2 0.21.4