00001 /*!@file AppMedia/test-world1.C test simple world 1 */ 00002 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00004 // by the University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 // //////////////////////////////////////////////////////////////////// // 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 00030 // //////////////////////////////////////////////////////////////////// // 00031 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu> 00032 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/ObjRec/test-world1.C $ 00033 // $Id: test-world1.C 10794 2009-02-08 06:21:09Z itti $ 00034 00035 00036 #include "Component/ModelManager.H" 00037 #include "Media/FrameSeries.H" 00038 #include "Transport/FrameInfo.H" 00039 #include "Raster/GenericFrame.H" 00040 #include "Image/Image.H" 00041 #include "Image/ImageSet.H" 00042 #include "Image/DrawOps.H" 00043 #include "Image/ShapeOps.H" 00044 #include "Image/Layout.H" 00045 #include <math.h> 00046 #include <stdlib.h> 00047 #include "ObjRec/ObjRec.H" 00048 #include "GUI/ImageDisplayStream.H" 00049 #include "GUI/XWinManaged.H" 00050 00051 int main(const int argc, const char **argv) 00052 { 00053 MYLOGVERB = LOG_INFO; 00054 ModelManager *mgr = new ModelManager("Test ObjRec"); 00055 00056 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr)); 00057 mgr->addSubComponent(ofs); 00058 00059 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr)); 00060 mgr->addSubComponent(ifs); 00061 00062 nub::ref<ObjRec> objRec(new ObjRec(*mgr)); 00063 mgr->addSubComponent(objRec); 00064 00065 mgr->exportOptions(MC_RECURSE); 00066 00067 if (mgr->parseCommandLine( 00068 (const int)argc, (const char**)argv, "", 0, 0) == false) 00069 return 1; 00070 mgr->start(); 00071 00072 00073 ifs->updateNext(); 00074 //grab the images 00075 GenericFrame input = ifs->readFrame(); 00076 Image<PixRGB<byte> > worldImg = rescale(input.asRgb(), 256, 256); 00077 objRec->setImageDims(worldImg.getDims()); 00078 00079 00080 while(0) 00081 { 00082 00083 double prob = objRec->predictWorld(worldImg); 00084 Image<PixRGB<byte> > worldPredictImg = objRec->getWorldPredictImage(); 00085 00086 worldPredictImg += worldImg; 00087 00088 LINFO("World prob %f", prob); 00089 00090 //Show the world 00091 Layout<PixRGB<byte> > outDisp; 00092 outDisp = vcat(outDisp, hcat(worldImg, worldPredictImg)); 00093 00094 Image<PixRGB<byte> > msgImg(worldImg.getWidth()*2, 20, ZEROS); 00095 char msg[255]; 00096 sprintf(msg, "World p=%0.2e", prob); 00097 writeText(msgImg, Point2D<int>(0,0), msg, PixRGB<byte>(255), PixRGB<byte>(127)); 00098 outDisp = vcat(outDisp, msgImg); 00099 00100 ofs->writeRgbLayout(outDisp, "Result", FrameInfo("Result", SRC_POS)); 00101 } 00102 00103 double angle = 45; 00104 double length = 50; 00105 bool run = false; 00106 while(1) 00107 { 00108 00109 //handle clicks 00110 const nub::soft_ref<ImageDisplayStream> ids = 00111 ofs->findFrameDestType<ImageDisplayStream>(); 00112 00113 const rutz::shared_ptr<XWinManaged> uiwin = 00114 ids.is_valid() 00115 ? ids->getWindow("world") 00116 : rutz::shared_ptr<XWinManaged>(); 00117 00118 00119 if (uiwin.is_valid()) 00120 { 00121 00122 int key = uiwin->getLastKeyPress(); 00123 if (key == 98) angle++; 00124 if (key == 104) angle--; 00125 00126 if (key == 100) length++; 00127 if (key == 102) length--; 00128 00129 if (key == 27) run=!run; 00130 00131 if (key != -1) 00132 LINFO("Length %f angle %f key %i", length, angle, key); 00133 00134 Point2D<int> pos = uiwin->getLastMouseClick(); 00135 if (pos.isValid()) 00136 { 00137 double prob = objRec->evalLikelihood(worldImg, pos, angle, length); 00138 LINFO("Prob %f", prob); 00139 } 00140 } 00141 00142 if (run) 00143 objRec->evalLikelihood(worldImg, Point2D<int>(0,0), angle, length); 00144 00145 Image<PixRGB<byte> > worldPredictImg = objRec->getWorldPredictImage(); 00146 00147 if (worldPredictImg.initialized()) 00148 worldPredictImg += worldImg; 00149 else 00150 worldPredictImg = worldImg; 00151 00152 ofs->writeRGB(worldImg, "world", FrameInfo("world", SRC_POS)); 00153 ofs->writeRGB(worldPredictImg, "predict", FrameInfo("predict", SRC_POS)); 00154 00155 00156 } 00157 00158 00159 00160 mgr->stop(); 00161 00162 exit(0); 00163 00164 } 00165 00166