faster_detector.cc

00001 /*
00002 
00003     This file is part of the FAST-ER machine learning system.
00004     Copyright (C) 2008  Edward Rosten and Los Alamos National Laboratory
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License along
00017     with this program; if not, write to the Free Software Foundation, Inc.,
00018     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 //Generate a detector, and compute its repeatability for all the tests.
00057 //
00058 //@param argc Number of command line arguments
00059 //@ingroup gRepeatability
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 }

Generated on Mon Mar 2 12:47:12 2009 for FAST-ER by  doxygen 1.5.3