00001
00002
00003 #ifndef SAMS_HOUGH_HPP_
00004 #define SAMS_HOUGH_HPP_
00005
00006 #include "jafarConfig.h"
00007
00008 #ifdef HAVE_BOOST_SANDBOX
00009 #ifdef HAVE_LAPACK
00010
00011
00012 #include <cmath>
00013 #include <string>
00014 #include <utility>
00015 #include <iostream>
00016 #include <vector>
00017 #include <ext/hash_map>
00018 #include "kernel/keyValueFile.hpp"
00019 #include "jmath/jblas.hpp"
00020 #include "sams/model.hpp"
00021 #include "sams/frame.hpp"
00022 #include "sams/matching.hpp"
00023 #include "sams/hypothesis.hpp"
00024
00025
00026 namespace jafar {
00027 namespace sams {
00028
00032 class Hough {
00033 public:
00034
00036 class Params : public jafar::kernel::KeyValueFileLoad {
00037 public:
00038 int xBins;
00039 int yBins;
00040 int oBins;
00041 int sBins;
00042 double thd;
00043
00044 Params(double xBins_=8, int yBins_=8, int oBins_=8, int sBins_=8,
00045 double thd_=1.5) :
00046 xBins(xBins_), yBins(yBins_), oBins(oBins_), sBins(sBins_), thd(thd_) {};
00047
00048 protected:
00049
00050 void loadKeyValueFile(jafar::kernel::KeyValueFile const & keyValueFile) {
00051 JFR_TRACE_BEGIN;
00052 keyValueFile.getItem("xBins", xBins);
00053 keyValueFile.getItem("yBins", yBins);
00054 keyValueFile.getItem("oBins", oBins);
00055 keyValueFile.getItem("sBins", sBins);
00056 keyValueFile.getItem("thd",thd);
00057 JFR_TRACE_END("Hough::Params::loadKeyValueFile");
00058 };
00059
00060 };
00061
00062 Hough() {};
00063 Hough(Params params_) : params(params_) {};
00064 Hough(std::string const & fileName_) {
00065 params.load(fileName_);
00066 };
00067
00068 std::vector<jafar::sams::Hypothesis> process(jafar::sams::Model const & md_,
00069 jafar::sams::Frame const & fr_,
00070 std::vector<jafar::sams::Match> const & matches_);
00071
00072 jblas::mat computeRANSACSimilarityTransform(std::vector<jafar::sams::Match> & matches_,
00073 jafar::sams::Hypothesis const & hc_,
00074 double err_=-1.0,
00075 bool useHoughTrans_=true);
00076
00077 private:
00078 Params params;
00079 int nViews;
00080
00081 struct hough_bin {
00082 double wght;
00083 std::vector<int> match_idx;
00084
00085 hough_bin() : wght(0.0), match_idx() {};
00086 };
00087
00088 typedef std::vector<hough_bin> acc_type;
00089 std::vector<hough_bin> acc;
00090
00091 inline int make_linearIdx(std::vector<int> const & vIdx_, std::vector<int> const & vDims_) const {
00092 int key = vIdx_[0];
00093 int prod = 1;
00094 for(int i=1; i < vIdx_.size(); i++) {
00095 prod *= vDims_[i-1];
00096 key += prod*(vIdx_[i]);
00097 }
00098 return key;
00099 };
00100
00101 inline void make_MultipleIdx(int key_, std::vector<int>& vIdx_, std::vector<int> const & vDims_) const {
00102 int idx = key_;
00103 for(int i=vIdx_.size()-1; i >= 0; i--) {
00104 if (i > 0) {
00105 int div = 1;
00106 for(int j=0; j < i; j++)
00107 div *= vDims_[j];
00108 vIdx_[i] = idx/div;
00109 idx -= div*vIdx_[i];
00110 } else
00111 vIdx_[i] = idx;
00112 }
00113 };
00114
00115 void addValue(int vId, double dx, double dy, double dt, double ds, int mIdx);
00116
00117 std::vector<jafar::sams::Hypothesis> analyse(jafar::sams::Model const & md_, std::vector<jafar::sams::Match> const & matches_);
00118
00119 friend std::ostream& operator <<(std::ostream& s, const Hough& hough_);
00120 };
00121
00122 std::ostream& operator <<(std::ostream& s, const Hough& hough_);
00123
00124 }
00125 }
00126 #endif
00127 #endif
00128 #endif