diff options
Diffstat (limited to 'meowpp.test/src')
-rw-r--r-- | meowpp.test/src/autostitch.cpp | 26 | ||||
-rw-r--r-- | meowpp.test/src/autostitch_RansacCheck.cpp | 29 | ||||
-rw-r--r-- | meowpp.test/src/features.cpp | 29 |
3 files changed, 72 insertions, 12 deletions
diff --git a/meowpp.test/src/autostitch.cpp b/meowpp.test/src/autostitch.cpp index b62d13b..e6b473b 100644 --- a/meowpp.test/src/autostitch.cpp +++ b/meowpp.test/src/autostitch.cpp @@ -250,6 +250,8 @@ bool kmatch() { //////////////////////////// **# RANSAC #** ////////////////////////// bool ransac() { messagePrintf( 1, "RANSAC"); + aspect_t = inRange(0.000001, 9999.0, atof(usg.optionValue("match-aspect", 0).c_str())); + angle_t = inRange(0.1,999.0, atof(usg.optionValue("match-angle", 0).c_str()))/180 * PI; MyRansacCheck::usage(usg); // tmp output p0 = inRange(0.00001, 0.9999, atof(usg.optionValue("ransac-p0", 0).c_str())); @@ -258,7 +260,9 @@ bool ransac() { for (size_t j = 0, J = input_bitmap.size(); j < J; j++) { size_t num = 4u; // !!!!!!!!!!!!!!!!!!! messagePrintf( 1, "ransac %lu --- %lu", i, j); - MyRansacCheck chk(&(fpsv[i]), &(fpsv[j])); + MyRansacCheck chk(&(fpsv[i]), &(fpsv[j]), + input_bitmap[i].width(), input_bitmap[i].height(), + aspect_t, angle_t); FeaturePointIndexPairs ret = ransac(pairs[i][j], chk, num, p0, P); if (!ret.empty()) { chk.rememberVCalc(ret); @@ -288,6 +292,8 @@ bool ransac() { return true; } + + //////////////////// **# checking match again #** //////////////////// bool match_check() { q = inRange(0.00001, 0.99999, atof(usg.optionValue("prob-p1", 0).c_str())); @@ -306,9 +312,15 @@ bool match_check() { continue; } double ni = pairs[i][j].size(), nf = 0; - MyRansacCheck chk(&(fpsv[i]), &(fpsv[j])); + size_t num = 4u; + MyRansacCheck chk(&(fpsv[i]), &(fpsv[j]), + input_bitmap[i].width(), input_bitmap[i].height(), + aspect_t, angle_t); + FeaturePointIndexPairs ret = ransac(pairs[i][j], chk, num, p0, P); + chk.rememberVCalc(pairs[i][j]); - if (chk.check(aspect_t, angle_t)) { + if (chk.check()) { + chk.print(); for (size_t k = 0, K = fpsv[i].size(); k < K; k++) { Vector2D<double> to(chk.to(Vector2D<double>(fpsv[i][k](0), fpsv[i][k](1)))); @@ -370,7 +382,9 @@ bool pair_output(){ for(size_t i = 0, I = input_bitmap.size(); i < I; i++){ for(size_t j = 0, J = input_bitmap.size(); j < J; j++){ if(pairs[i][j].empty()) continue; - MyRansacCheck chk(&(fpsv[i]), &(fpsv[j])); + MyRansacCheck chk(&(fpsv[i]), &(fpsv[j]), + (double)input_bitmap[i].width(), (double)input_bitmap[i].height(), + aspect_t, angle_t); chk.rememberVCalc(pairs[i][j]); size_t index = output_bitmap.size(); output_bitmap.push_back(input_bitmap[i]); @@ -378,8 +392,8 @@ bool pair_output(){ for(ssize_t y = 0, Y = input_bitmap[i].height(); y < Y; y++) { Vector2D<double> to(chk.to(Vector2D<double>(x, y))); ssize_t x2 = to.x(), y2 = to.y(); - if (0 <= x2 && x2 <= (ssize_t)input_bitmap[j].width() && - 0 <= y2 && y2 <= (ssize_t)input_bitmap[j].height()) { + if (0 <= x2 && x2 < (ssize_t)input_bitmap[j].width() && + 0 <= y2 && y2 < (ssize_t)input_bitmap[j].height()) { output_bitmap[index].pixel(y, x, (input_bitmap[i].pixel(y, x) + input_bitmap[j].pixel(y2,x2)) / 2 ); diff --git a/meowpp.test/src/autostitch_RansacCheck.cpp b/meowpp.test/src/autostitch_RansacCheck.cpp index becc7da..e728958 100644 --- a/meowpp.test/src/autostitch_RansacCheck.cpp +++ b/meowpp.test/src/autostitch_RansacCheck.cpp @@ -4,6 +4,7 @@ #include "meowpp/math/Vector.h" #include <utility> #include <cmath> +#include <cstdio> #include <algorithm> @@ -37,9 +38,14 @@ _to(__rc._to){ MyRansacCheck::MyRansacCheck(std::vector<Vector<double> > const* __from, - std::vector<Vector<double> > const* __to): + std::vector<Vector<double> > const* __to, + double w_max, double h_max, + double rr, double aa): _from(__from), -_to(__to){ +_to(__to), +_w(w_max), +_h(h_max), +r_(rr), ang(aa) { } @@ -122,6 +128,7 @@ double MyRansacCheck::operator()(std::vector<FeaturePointIndexPair> } } ((MyRansacCheck*)this)->rememberVCalc(__sample); + if (!((MyRansacCheck*)this)->check()) return -999; size_t ret = 0; for (size_t i = 0, I = __data.size(); i < I; i++) { if (ok(__data[i])) { @@ -131,21 +138,31 @@ double MyRansacCheck::operator()(std::vector<FeaturePointIndexPair> return 0.001 + ret; } -bool MyRansacCheck::check(double r, double a) { +bool MyRansacCheck::check() { return true; Vector2D<double> v_x(a_, b_); Vector2D<double> v_y(c_, d_); - double len1 = v_x.length() * r; - double len2 = v_x.length() / r; + double xx[2] = {0, _w}, yy[2] = {0, _h}; + for (size_t i = 0; i < 2; ++i) { + for (size_t j = 0; j < 2; ++j) { + if (A_ * xx[i] + B_ * yy[j] + 1 <= 0) return false; + } + } + double len1 = v_x.length() * r_; + double len2 = v_x.length() / r_; double len = v_y.length(); if (len1 > len2) std::swap(len1, len2); if (len < len1 || len2 < len) return false; - double sn = fabs(sin(a)); + double sn = fabs(sin(ang)); double msn = fabs(v_x.cross(v_y) / v_x.length() / v_y.length()); if (msn < sn) return false; return true; } +void MyRansacCheck::print() const { + printf("%f %f %f %f %f %f %f %f 1\n", a_, b_, c_, d_, e_, f_, A_, B_); +} + Vector2D<double> MyRansacCheck::to(Vector2D<double> const& v) const { return Vector2D<double>( (v.x() * a_ + v.y() * b_ + c_) / (A_ * v.x() + B_ * v.y() + 1), diff --git a/meowpp.test/src/features.cpp b/meowpp.test/src/features.cpp new file mode 100644 index 0000000..382dffa --- /dev/null +++ b/meowpp.test/src/features.cpp @@ -0,0 +1,29 @@ +#include <cstdio> + +#include "meowpp/Usage.h" + +using namespace meow; + +Usage usg("features"); + +int setup(int argc, char** argv) { + usg.optionAdd("h" , "Display this help document"); + usg.optionAdd("help", "Display this help document"); + usg.optionAdd("i", + "Specify the input images are in a directory instead of" + " process arguments", + "pathname", + "", + false); + usg.optionAdd("o", + "Output images with denoting feature points", + return 1; +} + +int main(int argc, char** argv) { + int ret; + if ((ret = setup(argc, argv)) <= 0) return -1; + return 0; +} + + |