BeobotCamera.H

Go to the documentation of this file.
00001 /*!@file Beobot/BeobotCamera.H A Beobot camera driver */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
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 <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/BeobotCamera.H $
00035 // $Id: BeobotCamera.H 7953 2007-02-19 22:51:57Z rjpeters $
00036 //
00037 
00038 #ifndef BEOBOTCAMERA_H_DEFINED
00039 #define BEOBOTCAMERA_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Component/ModelComponent.H"
00043 #include "Image/Pixels.H"
00044 #include "Util/Types.H"
00045 
00046 class IEEE1394grabber;
00047 
00048 //! BeobotCamera event listener
00049 /*! The BeoCamListener is called each time a frame is grabbed from the
00050   BeobotCamera. This is a virtual base class and users should define
00051   their own derived classes that will do something when a frame is
00052   received. */
00053 class BeobotCameraListener {
00054 public:
00055   //! Destructor
00056   virtual ~BeobotCameraListener();
00057 
00058   //! A frame was received
00059   /*! This is called by our grabbing thread and hence will execute in
00060     that thread. When overloading this function, you should be careful
00061     to enforce that processing done here will be very quick, or you
00062     will slow down and possibly choke the grabbing thread. */
00063   virtual void newFrame(const Image< PixRGB<byte> >& image,
00064                         const int frame) = 0;
00065 };
00066 
00067 //! This class abstracts an asynchronous Beobot camera
00068 /*! This class continually grabs frames (in a thread) and makes them
00069   available to other classes, under the control of a mutex. By
00070   default, there is no listener, and users can just asynchronously
00071   query the BeobotCamera to get the most recent frame. Alternatively,
00072   users may register a BeobotCameraListener which will be called each
00073   time a new frame is grabbed. */
00074 class BeobotCamera : public ModelComponent
00075 {
00076 public:
00077   //! Constructor
00078   BeobotCamera(OptionManager& mgr,
00079                const std::string& descrName = "Beobot Camera",
00080                const std::string& tagName = "BeobotCamera");
00081 
00082   //! Install a callback (listener)
00083   /*! This callback will be called eahc time a frame is grabbed. */
00084   void setListener(rutz::shared_ptr<BeobotCameraListener>& listener);
00085 
00086   //! Destructor
00087   ~BeobotCamera();
00088 
00089   //! Get a current view of the world
00090   /*! This function returns the last grabbed frame and also a frame number */
00091   void grab(Image< PixRGB<byte> >& image, int& frame);
00092 
00093   //! Running thread
00094   /*! Do not call directly, this is called by our grabbing thread */
00095   void run();
00096 
00097 protected:
00098   //! get started
00099   void start2();
00100 
00101   //! get stopped
00102   void stop1();
00103 
00104 private:
00105   nub::soft_ref<IEEE1394grabber> itsFG; // Our frame grabber
00106   Image< PixRGB<byte> > itsImage;   // Our internal image buffer
00107   int itsN;                         // frame number
00108   bool itsKeepgoing;                // true as long as we run
00109   rutz::shared_ptr<BeobotCameraListener> itsListener;
00110   pthread_t itsRunner;
00111   pthread_mutex_t itsLock;
00112 };
00113 
00114 // ######################################################################
00115 /* So things look consistent in everyone's emacs... */
00116 /* Local Variables: */
00117 /* indent-tabs-mode: nil */
00118 /* End: */
00119 
00120 #endif
Generated on Sun May 8 08:04:29 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3