00001 /*!@file Beosub/BeeBrain/test-stereoVision.C for stereo vision */ 00002 // //////////////////////////////////////////////////////////////////// // 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // 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 // 00032 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu> 00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeeBrain/test-stereoVision.C $ 00034 // $Id: test-stereoVision.C 8623 2007-07-25 17:57:51Z rjpeters $ 00035 00036 #define NAVG 20 00037 00038 #include "Component/ModelManager.H" 00039 #include "Devices/DeviceOpts.H" 00040 #include "Video/VideoFormat.H" 00041 #include "Devices/FrameGrabberConfigurator.H" 00042 #include "Devices/FrameGrabberFactory.H" 00043 #include "GUI/XWinManaged.H" 00044 00045 #include "Raster/Raster.H" 00046 #include "Image/Image.H" 00047 #include "Image/Pixels.H" 00048 00049 #include "Util/Timer.H" 00050 00051 int main( int argc, const char* argv[] ) 00052 { 00053 MYLOGVERB = LOG_INFO; 00054 00055 // instantiate a model manager: 00056 ModelManager manager("test stereo vision"); 00057 00058 nub::soft_ref<FrameIstream> gbF(makeV4L2grabber(manager)); 00059 nub::soft_ref<FrameIstream> gbB(makeV4L2grabber(manager)); 00060 00061 manager.exportOptions(MC_RECURSE); 00062 00063 // Parse command-line: 00064 if (manager.parseCommandLine(argc, argv," ",0, 0) == false) return(1); 00065 00066 gbF->setModelParamVal("FrameGrabberDevice",std::string("/dev/video0")); 00067 gbF->setModelParamVal("FrameGrabberChannel",0); 00068 //gbF->setModelParamVal("InputFrameSource", "V4L2"); 00069 gbF->setModelParamVal("FrameGrabberMode", VIDFMT_YUYV); 00070 gbF->setModelParamVal("FrameGrabberByteSwap", false); 00071 //gbF->setModelParamVal("FrameGrabberFPS", 30); 00072 manager.addSubComponent(gbF); 00073 00074 gbB->setModelParamVal("FrameGrabberDevice",std::string("/dev/video1")); 00075 gbB->setModelParamVal("FrameGrabberChannel",0); 00076 //gbB->setModelParamVal("InputFrameSource", "V4L2"); 00077 gbB->setModelParamVal("FrameGrabberMode", VIDFMT_YUYV); 00078 gbB->setModelParamVal("FrameGrabberByteSwap", false); 00079 //gbB->setModelParamVal("FrameGrabberFPS", 30); 00080 manager.addSubComponent(gbB); 00081 00082 manager.start(); 00083 00084 uint wF = gbF->getWidth(); uint hF = gbF->getHeight(); 00085 uint wB = gbB->getWidth(); uint hB = gbB->getHeight(); 00086 00087 rutz::shared_ptr<XWinManaged> fwin(new XWinManaged(Dims(wF,hF), 0, 20, "front")); 00088 rutz::shared_ptr<XWinManaged> bwin(new XWinManaged(Dims(wB,hB), wF,20, "back")); 00089 00090 //start streaming 00091 gbF->startStream(); 00092 gbB->startStream(); 00093 00094 Timer tim(1000000); uint64 t[NAVG]; float frate = 0.0f; tim.reset(); 00095 bool goforever =true; 00096 uint fNum =0; 00097 while(goforever) 00098 { 00099 //grab the images 00100 Image< PixRGB<byte> > fImg = gbF->readRGB(); 00101 Image< PixRGB<byte> > bImg = gbB->readRGB(); 00102 00103 if((fNum % 15) ==0) fwin->drawImage(fImg,0,0); 00104 if((fNum % 15) ==0) bwin->drawImage(bImg,0,0); 00105 00106 // compute and show framerate over the last NAVG frames: 00107 t[fNum % NAVG] = tim.get(); tim.reset(); 00108 if (fNum % NAVG == 0 && fNum > 0) 00109 { 00110 uint64 avg = 0ULL; 00111 for(int i = 0; i < NAVG; i ++) avg += t[i]; 00112 frate = 1000000.0F / float(avg) * float(NAVG); 00113 LINFO("[%6d] Frame rate: %6.3f fps -> %8.3f ms/frame", 00114 fNum,frate, 1000.0/frate); 00115 } 00116 00117 //std::string saveFNameF = sformat("data/cross_F_%07d.ppm", fNum); 00118 //std::string saveFNameB = sformat("data/cross_B_%07d.ppm", fNum); 00119 //LINFO("saving: %s & %s",saveFNameF.c_str(),saveFNameB.c_str()); 00120 //Raster::WriteRGB(fImg,saveFNameF); 00121 //Raster::WriteRGB(bImg,saveFNameB); 00122 fNum++; 00123 } 00124 00125 return 0; 00126 } 00127 00128 // ###################################################################### 00129 /* So things look consistent in everyone's emacs... */ 00130 /* Local Variables: */ 00131 /* indent-tabs-mode: nil */ 00132 /* End: */ 00133 00134