Mercurial > hg > match-vamp
comparison src/MatchPipeline.cpp @ 140:cfba9aec7569 refactors
Separate out the raw & conditioned feature outputs (previously only conditioned was available, but we want raw for our tests). Plus some optional debug output
author | Chris Cannam |
---|---|
date | Thu, 08 Jan 2015 12:11:27 +0000 |
parents | 42381e437fcd |
children | d6f22887283e 7f6f150c1edf |
comparison
equal
deleted
inserted
replaced
139:b62dbe2ba958 | 140:cfba9aec7569 |
---|---|
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "MatchPipeline.h" | 16 #include "MatchPipeline.h" |
17 | |
18 //#define DEBUG_MATCH_PIPELINE 1 | |
17 | 19 |
18 MatchPipeline::MatchPipeline(FeatureExtractor::Parameters feParams, | 20 MatchPipeline::MatchPipeline(FeatureExtractor::Parameters feParams, |
19 FeatureConditioner::Parameters fcParams, | 21 FeatureConditioner::Parameters fcParams, |
20 Matcher::Parameters matchParams) : | 22 Matcher::Parameters matchParams) : |
21 m_fe1(feParams), | 23 m_fe1(feParams), |
46 MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2) | 48 MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2) |
47 { | 49 { |
48 m_f1 = f1; | 50 m_f1 = f1; |
49 m_f2 = f2; | 51 m_f2 = f2; |
50 | 52 |
53 #ifdef DEBUG_MATCH_PIPELINE | |
54 if (m_lastFrameIn1 == 1) { | |
55 cerr << "features 1 -> "; | |
56 for (int i = 0; i < (int) m_f1.size(); ++i) { | |
57 cerr << m_f1[i] << " "; | |
58 } | |
59 cerr << endl; | |
60 } | |
61 #endif | |
62 | |
51 feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2)); | 63 feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2)); |
52 } | 64 } |
53 | 65 |
54 void | 66 void |
55 MatchPipeline::feedConditionedFeatures(const vector<double> &c1, const vector<double> &c2) | 67 MatchPipeline::feedConditionedFeatures(const vector<double> &c1, const vector<double> &c2) |
56 { | 68 { |
57 m_c1 = c1; | 69 m_c1 = c1; |
58 m_c2 = c2; | 70 m_c2 = c2; |
71 | |
72 #ifdef DEBUG_MATCH_PIPELINE | |
73 if (m_lastFrameIn1 == 1) { | |
74 cerr << "conditioned features 1 -> "; | |
75 for (int i = 0; i < (int) m_c1.size(); ++i) { | |
76 cerr << m_c1[i] << " "; | |
77 } | |
78 cerr << endl; | |
79 } | |
80 #endif | |
59 | 81 |
60 m_feeder.feed(c1, c2); | 82 m_feeder.feed(c1, c2); |
61 | 83 |
62 if (aboveThreshold(c1)) m_lastFrameIn1 = m_frameNo; | 84 if (aboveThreshold(c1)) m_lastFrameIn1 = m_frameNo; |
63 if (aboveThreshold(c2)) m_lastFrameIn2 = m_frameNo; | 85 if (aboveThreshold(c2)) m_lastFrameIn2 = m_frameNo; |
64 | 86 |
87 #ifdef DEBUG_MATCH_PIPELINE | |
88 cerr << "last frames are " << m_lastFrameIn1 << ", " << m_lastFrameIn2 | |
89 << endl; | |
90 #endif | |
91 | |
65 ++m_frameNo; | 92 ++m_frameNo; |
66 } | 93 } |
67 | 94 |
68 void | 95 void |
69 MatchPipeline::extractFeatures(vector<double> &f1, vector<double> &f2) | 96 MatchPipeline::extractFeatures(vector<double> &f1, vector<double> &f2) |
80 } | 107 } |
81 | 108 |
82 bool | 109 bool |
83 MatchPipeline::aboveThreshold(const vector<double> &f) | 110 MatchPipeline::aboveThreshold(const vector<double> &f) |
84 { | 111 { |
112 // This threshold is used only to determine when either of the | |
113 // input streams has ended -- the last frame for a stream is | |
114 // considered to be the last one that was above the | |
115 // threshold. This is different from the silence threshold in | |
116 // FeatureConditioner. | |
85 double threshold = 1e-4f; | 117 double threshold = 1e-4f; |
86 double sum = 0.f; | 118 double sum = 0.f; |
87 for (int i = 0; i < int(f.size()); ++i) { | 119 for (int i = 0; i < int(f.size()); ++i) { |
88 sum += f[i] * f[i]; | 120 sum += f[i] * f[i]; |
89 } | 121 } |
122 #ifdef DEBUG_MATCH_PIPELINE | |
123 cerr << "aboveThreshold: sum " << sum << ", threshold " << threshold | |
124 << ", returning " << (sum >= threshold) << endl; | |
125 #endif | |
90 return (sum >= threshold); | 126 return (sum >= threshold); |
91 } | 127 } |
92 | 128 |
93 void | 129 void |
94 MatchPipeline::finish() | 130 MatchPipeline::finish() |