aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp.test/src/match_MatchChk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp.test/src/match_MatchChk.cpp')
-rw-r--r--meowpp.test/src/match_MatchChk.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/meowpp.test/src/match_MatchChk.cpp b/meowpp.test/src/match_MatchChk.cpp
new file mode 100644
index 0000000..6b8239c
--- /dev/null
+++ b/meowpp.test/src/match_MatchChk.cpp
@@ -0,0 +1,102 @@
+#include "match.h"
+#include "meowpp/oo/ObjSelector.h"
+
+using namespace meow;
+using namespace std;
+
+
+class MatchChk_Prob: public MatchChk {
+private:
+ double p1_, p0_, pmin_;
+public:
+ MatchChk_Prob(): p1_(0.7), p0_(0.01), pmin_(0.97) {
+ }
+ bool check(vector<Vector2D<double> > const& fps1,
+ size_t w1,
+ size_t h1,
+ vector<Vector2D<double> > const& fps2,
+ size_t w2,
+ size_t h2,
+ vector<Pair > const& pairs,
+ MatchInfo const& info) {
+ double m_ni = log(p1_ * (1 - p0_)) - log(p0_ * (1 - p1_));
+ double c = log(pmin_) - log(1 - pmin_);
+ double m_nf = log(1 - p0_) - log(1 - p1_);
+ // ni * ?? > c + nf * ??
+ double ni = info.pairs.size();
+ double nf = 0;
+ for (size_t i = 0; i < fps1.size(); ++i) {
+ Vector2D<double> v(
+ (fps1[i].dot(info.x_axis) + info.x_offset) / (fps1[i].dot(info.depth) + 1),
+ (fps1[i].dot(info.y_axis) + info.y_offset) / (fps1[i].dot(info.depth) + 1)
+ );
+ if (0 <= v.x() && v.x() < w2 && 0 <= v.y() && v.y() < h2) {
+ ++nf;
+ }
+ }
+ //printf("nf = %f, ni = %f\n", nf, ni);
+ return (ni * m_ni > c + nf * m_nf);
+ }
+ string description() const {
+ return string("prob module");
+ }
+ Usage usage() const {
+ Usage tmp;
+ tmp.optionAdd("prob-p1",
+ "p1",
+ "floating number",
+ stringPrintf("%.3f", p1_),
+ false);
+ tmp.optionAdd("prob-p0",
+ "p0",
+ "floating number",
+ stringPrintf("%.3f", p0_),
+ false);
+ tmp.optionAdd("prob-pmin",
+ "pmin",
+ "floating number",
+ stringPrintf("%.3f", pmin_),
+ false);
+ return tmp;
+ }
+ bool usage(Usage const& usg) {
+ p1_ = inRange(0.00001, 0.99999, atof(usg.optionValue("prob-p1" , 0).c_str()));
+ p0_ = inRange(0.00001, 0.99999, atof(usg.optionValue("prob-p0" , 0).c_str()));
+ pmin_ = inRange(0.00001, 0.99999, atof(usg.optionValue("prob-pmin", 0).c_str()));
+ return true;
+ }
+ ObjBase* create() const {
+ return new MatchChk_Prob();
+ }
+};
+
+static ObjSelector<kMatchChk_ID> __("prob-module", new MatchChk_Prob, true);
+
+class MatchChk_Nothing: public MatchChk {
+private:
+public:
+ bool check(vector<Vector2D<double> > const& fps1,
+ size_t w1,
+ size_t h1,
+ vector<Vector2D<double> > const& fps2,
+ size_t w2,
+ size_t h2,
+ vector<Pair > const& pairs,
+ MatchInfo const& info) {
+ return true;
+ }
+ string description() const {
+ return string("always true");
+ }
+ Usage usage() const {
+ return Usage("");
+ }
+ bool usage(Usage const& usg) {
+ return true;
+ }
+ ObjBase* create() const {
+ return new MatchChk_Nothing();
+ }
+};
+
+static ObjSelector<kMatchChk_ID> ___("nothing", new MatchChk_Nothing, true);