changeset 135:42381e437fcd refactors

The finder is supposed to use normalised path-cost when calculation expand direction (as in Java implementation). Also, provide a way to query the forward path.
author Chris Cannam
date Thu, 18 Dec 2014 17:56:54 +0000
parents 046f51a2ca25
children 2cbf6237c822
files src/Finder.cpp src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h src/MatchPipeline.cpp src/MatchPipeline.h src/Matcher.cpp src/Matcher.h
diffstat 7 files changed, 47 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/Finder.cpp	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/Finder.cpp	Thu Dec 18 17:56:54 2014 +0000
@@ -54,7 +54,7 @@
         rowRange.second = row+1;	// don't cheat by looking at future :)
     }
     for (int index = rowRange.first; index < rowRange.second; index++) {
-        double tmp = m_m->getPathCost(index, col);
+        double tmp = m_m->getNormalisedPathCost(index, col);
         if (tmp < min) {
             min = tmp;
             bestRow = index;
@@ -66,7 +66,7 @@
         colRange.second = col+1;	// don't cheat by looking at future :)
     }
     for (int index = colRange.first; index < colRange.second; index++) {
-        double tmp = m_m->getPathCost(row, index);
+        double tmp = m_m->getNormalisedPathCost(row, index);
         if (tmp < min) {
             min = tmp;
             bestCol = index;
@@ -74,6 +74,8 @@
         }
     }
 
+//    cerr << "at [" << row << "," << col << "] (cost " << m_m->getPathCost(row, col) << ") blocksize = " << m_m->getBlockSize() << " best is [" << bestRow << "," << bestCol << "] (cost " << min << ")" << endl;
+    
     if (bestRow == row) {
         if (bestCol == col) {
             return Matcher::AdvanceBoth;
--- a/src/MatchFeatureFeeder.cpp	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/MatchFeatureFeeder.cpp	Thu Dec 18 17:56:54 2014 +0000
@@ -91,6 +91,9 @@
             break;
         }
     }
+
+    m_fpx.push_back(m_pm2->getFrameCount());
+    m_fpy.push_back(m_pm1->getFrameCount());
 }
 
 void
--- a/src/MatchFeatureFeeder.h	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/MatchFeatureFeeder.h	Thu Dec 18 17:56:54 2014 +0000
@@ -47,7 +47,19 @@
      * Indicate that both inputs have come to an end.
      */
     void finish();
-    
+
+    /**
+     * Return the forward path, that is, the estimate of the
+     * lowest-cost path that was generated (possibly in real-time)
+     * while initially tracking the inputs. This is the path that is
+     * used to determine the shape of the search zone within which the
+     * eventual reverse path will be sought by the Finder.
+     */
+    void retrieveForwardPath(std::vector<int> &pathx, std::vector<int> &pathy) {
+        pathx = m_fpx;
+        pathy = m_fpy;
+    }
+
     Finder *getFinder() { return m_finder; }
 
 protected:
@@ -61,6 +73,9 @@
 
     std::queue<std::vector<double> > m_q1;
     std::queue<std::vector<double> > m_q2;
+
+    vector<int> m_fpx;
+    vector<int> m_fpy;
 };
 
 #endif
--- a/src/MatchPipeline.cpp	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/MatchPipeline.cpp	Thu Dec 18 17:56:54 2014 +0000
@@ -97,6 +97,12 @@
     getFinder()->setDurations(m_lastFrameIn1, m_lastFrameIn2);
 }
 
+MatchFeatureFeeder *
+MatchPipeline::getFeeder()
+{
+    return &m_feeder;
+}
+
 Finder *
 MatchPipeline::getFinder()
 {
--- a/src/MatchPipeline.h	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/MatchPipeline.h	Thu Dec 18 17:56:54 2014 +0000
@@ -88,6 +88,7 @@
      */
     void finish();
 
+    MatchFeatureFeeder *getFeeder();
     Finder *getFinder();
     
 private:
--- a/src/Matcher.cpp	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/Matcher.cpp	Thu Dec 18 17:56:54 2014 +0000
@@ -154,6 +154,13 @@
 }
 
 double
+Matcher::getNormalisedPathCost(int i, int j)
+{
+    // normalised for path length. 1+ prevents division by zero here
+    return getPathCost(i, j) / (1 + i + j);
+}
+
+double
 Matcher::getPathCost(int i, int j)
 {
     if (m_firstPM) {
--- a/src/Matcher.h	Thu Dec 11 15:16:15 2014 +0000
+++ b/src/Matcher.h	Thu Dec 18 17:56:54 2014 +0000
@@ -224,6 +224,16 @@
      *  @param value the cost of the minimum cost path to set for this location
      */
     void setPathCost(int i, int j, Advance dir, double value);
+    
+    /** Retrieves a value from the minimum cost matrix, normalised for
+     *  path length.
+     *
+     *  @param i the frame number of this Matcher
+     *  @param j the frame number of the other Matcher
+     *  @return the cost of the minimum cost path to this location,
+     *     normalised by the Manhattan distance from 0,0 to i,j
+     */
+    double getNormalisedPathCost(int i, int j);
 
     /** Retrieves an advance direction from the matrix.
      *