00001 /*!@file Apps/BorderWatch/BorderWatchGui.C Simple GUI for BorderWatch results */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 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: Laurent Itti 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Apps/BorderWatch/BorderWatchGui.C $ 00035 // $Id: BorderWatchGui.C 13059 2010-03-26 08:14:32Z itti $ 00036 // 00037 00038 #include "QtUtil/Util.H" // for argv2qt() 00039 #include "Apps/BorderWatch/BorderWatchQt.qt.H" 00040 #include "Apps/BorderWatch/BorderWatchData.H" 00041 #include "Component/ModelManager.H" 00042 #include "Component/ModelOptionDef.H" 00043 #include "Image/Image.H" 00044 #include "Media/FrameSeries.H" 00045 #include "Raster/GenericFrame.H" 00046 00047 #include <QtGui/QApplication> 00048 #include <fstream> 00049 00050 const ModelOptionCateg MOC_BORDERWATCH = { 00051 MOC_SORTPRI_3, "BorderWatch-Related Options" }; 00052 00053 const ModelOptionDef OPT_LogFile = 00054 { MODOPT_ARG_STRING, "LogFile", &MOC_BORDERWATCH, OPTEXP_CORE, 00055 "File name of the log file generated by BorderWatch application", 00056 "logfile", '\0', "<file.log>", "" }; 00057 00058 //! BorderWatch GUI, use with --in=movie.asf --logfile=file.log 00059 int main(int argc, const char **argv) 00060 { 00061 // Instantiate a ModelManager: 00062 ModelManager manager("Attention Model"); 00063 00064 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00065 manager.addSubComponent(ifs); 00066 00067 OModelParam<std::string> optLogFile(&OPT_LogFile, &manager); 00068 00069 manager.exportOptions(MC_RECURSE); 00070 00071 // Parse command-line: 00072 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return 1; 00073 00074 if (optLogFile.getVal().empty()) LFATAL("You need to provide a log file with --logfile=<file.log>"); 00075 00076 // let's get all our ModelComponent instances started: 00077 manager.start(); 00078 00079 // Load up the log file: 00080 LINFO("Loading logfile data from %s", optLogFile.getVal().c_str()); 00081 std::vector<BorderWatchData> logdata; 00082 std::ifstream inlog(optLogFile.getVal().c_str()); 00083 if (inlog.is_open() == false) LFATAL("Cannot open %s for reading", optLogFile.getVal().c_str()); 00084 BorderWatchData d; 00085 while (true) { inlog >> d; if (inlog.eof()) break; else logdata.push_back(d); } 00086 inlog.close(); 00087 LINFO(" %"ZU" log entries.", logdata.size()); 00088 00089 // Load up the movie frames: 00090 LINFO("Loading movie frames..."); 00091 std::vector<GenericFrame> frames; 00092 while (true) { 00093 // grab the images: 00094 ifs->updateNext(); 00095 GenericFrame input = ifs->readFrame(); if (input.initialized() == false) break; 00096 frames.push_back(input); 00097 if ((ifs->frame() % 5000) == 0) LINFO(" frame %06u", ifs->frame()); 00098 } 00099 LINFO(" %"ZU" frames.", frames.size()); 00100 00101 // we are done with our ModelComponents: 00102 manager.stop(); 00103 00104 // create a QApplication: 00105 LINFO("Starting GUI..."); 00106 int qtargc = 1; const char* qtargv[1] = { "BorderWatchGUI" }; 00107 QApplication a(qtargc, argv2qt(qtargc, qtargv)); 00108 00109 // and a widget: 00110 BorderWatchQt b(frames, logdata); 00111 b.setWindowTitle("iLab USC -- BorderWatch Review GUI"); 00112 b.show(); 00113 00114 // main loop for QApplication: 00115 const int ret = a.exec(); 00116 00117 // cleanup and exit: 00118 return ret; 00119 }