00001 /** 00002 \file Robots/LoBot/io/LoVideoStream.C 00003 \brief Video stream encapsulation for the Lobot/Robolocust project. 00004 */ 00005 00006 // //////////////////////////////////////////////////////////////////// // 00007 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00008 // by the University of Southern California (USC) and the iLab at USC. // 00009 // See http://iLab.usc.edu for information about this project. // 00010 // //////////////////////////////////////////////////////////////////// // 00011 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00012 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00013 // in Visual Environments, and Applications'' by Christof Koch and // 00014 // Laurent Itti, California Institute of Technology, 2001 (patent // 00015 // pending; application number 09/912,225 filed July 23, 2001; see // 00016 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00017 // //////////////////////////////////////////////////////////////////// // 00018 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00019 // // 00020 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00021 // redistribute it and/or modify it under the terms of the GNU General // 00022 // Public License as published by the Free Software Foundation; either // 00023 // version 2 of the License, or (at your option) any later version. // 00024 // // 00025 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00026 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00027 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00028 // PURPOSE. See the GNU General Public License for more details. // 00029 // // 00030 // You should have received a copy of the GNU General Public License // 00031 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00032 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00033 // Boston, MA 02111-1307 USA. // 00034 // //////////////////////////////////////////////////////////////////// // 00035 // 00036 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu> 00037 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoVideoStream.C $ 00038 // $Id: LoVideoStream.C 12592 2010-01-18 23:17:34Z mviswana $ 00039 // 00040 00041 //------------------------------ HEADERS -------------------------------- 00042 00043 // lobot headers 00044 #include "Robots/LoBot/io/LoVideoStream.H" 00045 #include "Robots/LoBot/config/LoConfigHelpers.H" 00046 #include "Robots/LoBot/misc/LoExcept.H" 00047 00048 // INVT headers 00049 #include "Raster/GenericFrame.H" 00050 00051 //----------------------------- NAMESPACE ------------------------------- 00052 00053 namespace lobot { 00054 00055 //-------------------------- INITIALIZATION ----------------------------- 00056 00057 // Read images directly from FireWire camera 00058 VideoStream:: 00059 VideoStream(int camera, const Dims& resolution, float frame_rate) 00060 : m_grabber(new Grabber(camera, resolution, frame_rate)), 00061 m_decoder(0) 00062 {} 00063 00064 // Read images from an MPEG 00065 VideoStream::VideoStream(const std::string& mpeg_file_name) 00066 : m_grabber(0), 00067 m_decoder(new FfmpegDecoder(video_conf("playback_codec", 00068 std::string("Auto")).c_str(), 00069 video_conf("buffer_size", 100000), 00070 mpeg_file_name.c_str(), 00071 false)) 00072 {} 00073 00074 //----------------------------- VIDEO I/O ------------------------------- 00075 00076 void VideoStream::update() 00077 { 00078 if (m_grabber) 00079 m_image = m_grabber->grab() ; 00080 else if (m_decoder) 00081 m_image = m_decoder->readRGB() ; 00082 else 00083 throw vstream_error(NO_VIDEOSTREAM_SOURCE) ; 00084 } 00085 00086 //------------------------- VIDEO STREAM INFO --------------------------- 00087 00088 Dims VideoStream::frameSize() const 00089 { 00090 if (m_grabber) 00091 return m_grabber->frameSize() ; 00092 if (m_decoder) 00093 return m_decoder->peekFrameSpec().dims ; 00094 throw vstream_error(NO_VIDEOSTREAM_SOURCE) ; 00095 } 00096 00097 float VideoStream::frameRate() const 00098 { 00099 if (m_grabber) 00100 return m_grabber->frameRate() ; 00101 if (m_decoder) 00102 return m_decoder->peekFrameSpec().frameRate ; 00103 throw vstream_error(NO_VIDEOSTREAM_SOURCE) ; 00104 } 00105 00106 //----------------------------- CLEAN-UP -------------------------------- 00107 00108 VideoStream::~VideoStream() 00109 { 00110 delete m_grabber ; 00111 delete m_decoder ; 00112 } 00113 00114 //----------------------------------------------------------------------- 00115 00116 } // end of namespace encapsulating this file's definitions 00117 00118 /* So things look consistent in everyone's emacs... */ 00119 /* Local Variables: */ 00120 /* indent-tabs-mode: nil */ 00121 /* End: */