00001 /*!@file AppMedia/test-KalmanFilter.C - a test program for KalmanFilter.[CH] 00002 */ 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/test-KalmanFilter.C $ 00035 // $Id: test-KalmanFilter.C 14376 2011-01-11 02:44:34Z pez $ 00036 // 00037 00038 #include "Image/Image.H" 00039 #include "Image/KalmanFilter.H" 00040 #include "Util/Types.H" 00041 #include "Util/log.H" 00042 #include <cmath> 00043 #include <fstream> 00044 00045 int main(const int argc, const char** argv) 00046 { 00047 if (argc < 3) 00048 LFATAL("usage: %s inputfile.txt outputfile.txt",argv[0]); 00049 00050 std::ifstream is(argv[1]); 00051 std::ofstream os(argv[2]); 00052 00053 float pNoise = 1.0F; 00054 float mNoise = 1.0F; 00055 00056 if (argc > 3) sscanf(argv[3],"%g",&pNoise); 00057 if (argc > 4) sscanf(argv[4],"%g",&mNoise); 00058 00059 KalmanFilter KF; 00060 00061 while(is.good()) { 00062 float z; 00063 is >> z; 00064 00065 if (!KF.isInitialized()) { 00066 KF.init(z,pNoise,mNoise); 00067 KF.getStateVector().getVal(0,0); 00068 } 00069 else { 00070 KF.getEstimate(); 00071 00072 if (z < 0.0F) 00073 KF.update(); 00074 else 00075 KF.update(z); 00076 } 00077 00078 Image<float> x = KF.getStateVector(); 00079 Image<float> P = KF.getCovariances(); 00080 00081 //os << z << ' ' << pred; 00082 00083 os << z << ": "; 00084 00085 for (int i = 0; i < 3; ++i) 00086 os << ' ' << x.getVal(0,i); 00087 00088 os << " ---- "; 00089 00090 for (int i = 0; i < 3; ++i) 00091 os << ' ' << sqrt(P.getVal(i,i)); 00092 00093 os << '\n'; 00094 } 00095 00096 os.close(); 00097 is.close(); 00098 } 00099 00100 00101 // ###################################################################### 00102 /* So things look consistent in everyone's emacs... */ 00103 /* Local Variables: */ 00104 /* indent-tabs-mode: nil */ 00105 /* End: */