00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <fstream>
00021 #include <cmath>
00022 #include <cstring>
00023 #include <cerrno>
00024 #include <vector>
00025 #include <utility>
00026 #include <algorithm>
00027
00028 #include <cvd/image.h>
00029 #include <cvd/byte.h>
00030 #include <cvd/random.h>
00031 #include <cvd/vector_image_ref.h>
00032
00033 #include <tag/stdpp.h>
00034 #include <tag/fn.h>
00035
00036 #include <sys/mman.h>
00037
00038 #include <TooN/TooN.h>
00039 #include <TooN/helpers.h>
00040
00041 #include "offsets.h"
00042 #include "faster_detector.h"
00043 #include "faster_tree.h"
00044 #include "faster_bytecode.h"
00045
00046 #include <gvars3/instances.h>
00047
00048
00049 using namespace std;
00050 using namespace CVD;
00051 using namespace tag;
00052 using namespace GVars3;
00053 using namespace TooN;
00054
00055
00056
00057
00058
00059
00060 void init()
00061 {
00062 static bool once=0;
00063
00064 if(!once)
00065 {
00066 create_offsets();
00067 once = 1;
00068 }
00069 }
00070
00071
00072 faster_learn::faster_learn(const std::string& fname)
00073 {
00074 init();
00075 ifstream i;
00076 i.open(fname.c_str());
00077
00078 if(!i.good())
00079 {
00080 cerr << "Error: " << fname << ": " << strerror(errno) << endl;
00081 exit(1);
00082 }
00083
00084 try{
00085 tree.reset(load_a_tree(i));
00086 }
00087 catch(ParseError p)
00088 {
00089 cerr << "Parse error in " << fname << endl;
00090 exit(1);
00091 }
00092
00093 if(GV3::get<bool>("faster_tree.print_tree", 0, 1))
00094 {
00095 clog << "Tree:" << endl;
00096 tree->print(clog);
00097 }
00098
00099 if(GV3::get<bool>("faster_tree.print_block", 0, 1))
00100 {
00101 block_bytecode f2 = tree->make_fast_detector(100);
00102 f2.print(clog, 100);
00103 }
00104 }
00105
00106
00107 void faster_learn::operator()(const CVD::Image<CVD::byte>& i, std::vector<CVD::ImageRef>& v, unsigned int t) const
00108 {
00109 Image<int> scratch(i.size(), 0);
00110
00111 v = tree_detect_corners(i, tree.get(), t, scratch);
00112 }