00001 00002 /*!@file Devices/XCgrabber.H Definition and access functions for 00003 Silicon Imaging HD Camera grabber */ 00004 00005 // //////////////////////////////////////////////////////////////////// // 00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00007 // University of Southern California (USC) and the iLab at USC. // 00008 // See http://iLab.usc.edu for information about this project. // 00009 // //////////////////////////////////////////////////////////////////// // 00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00012 // in Visual Environments, and Applications'' by Christof Koch and // 00013 // Laurent Itti, California Institute of Technology, 2001 (patent // 00014 // pending; application number 09/912,225 filed July 23, 2001; see // 00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00016 // //////////////////////////////////////////////////////////////////// // 00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00018 // // 00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00020 // redistribute it and/or modify it under the terms of the GNU General // 00021 // Public License as published by the Free Software Foundation; either // 00022 // version 2 of the License, or (at your option) any later version. // 00023 // // 00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00027 // PURPOSE. See the GNU General Public License for more details. // 00028 // // 00029 // You should have received a copy of the GNU General Public License // 00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00032 // Boston, MA 02111-1307 USA. // 00033 // //////////////////////////////////////////////////////////////////// // 00034 // 00035 // Primary maintainer for this file: Zhicheng Li <zhicheng@usc.edu> 00036 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/XCgrabber.H $ 00037 // $Id: XCgrabber.H 12965 2010-03-06 03:23:30Z irock $ 00038 // 00039 00040 #ifndef XCGRABBER_H_DEFINED 00041 #define XCGRABBER_H_DEFINED 00042 00043 #ifdef HAVE_XCLIB 00044 // xclib defines a bunch of types which conflicts with other packages; 00045 // namely: uint64 which we define in Util/Types.H, and, more 00046 // importantly, float4 which is defined by CUDA includes. So we just 00047 // resort to using it in a new xclib namespace. That means that all 00048 // the function calls and uses of xclib datatypes now must use the 00049 // xclib:: prefix: 00050 namespace xclib { 00051 #include <xclib/xcliball.h> 00052 } 00053 #endif 00054 00055 #include "Component/ModelParam.H" 00056 #include "Image/Dims.H" 00057 #include "Transport/FrameIstream.H" 00058 #include "Util/Types.H" 00059 #include "Video/VideoFormat.H" 00060 00061 #include <pthread.h> 00062 00063 class VideoFrame; 00064 template <class T> class PixRGB; 00065 template <class T> class Image; 00066 00067 class XCgrabber : public FrameIstream 00068 { 00069 public: 00070 //! Constructor 00071 XCgrabber(OptionManager& mgr, 00072 const std::string& descrName="XC Frame Grabber Driver", 00073 const std::string& tagName = "XCFrameGrabber", 00074 const ParamFlag flags = USE_MY_VAL); 00075 00076 //! Destructor 00077 virtual ~XCgrabber(); 00078 00079 //! Return the specifications of the next frame to be returned 00080 virtual GenericFrameSpec peekFrameSpec(); 00081 00082 //! Get the inter-frame time that matches our video mode 00083 virtual SimTime getNaturalFrameTime() const; 00084 00085 //! White balance 00086 void WhiteBalance(); 00087 00088 //! Get the next frame from the frame-grabber 00089 /*! Returns grabbed frame. This call will block until a frame is 00090 ready and has been grabbed. 00091 00092 Beware that the integrity of the GenericFrame object may not 00093 last "very long"; basically, try to be finished using the 00094 GenericFrame object before you attempt to grab the next frame in 00095 the stream. If you need it for longer than that, then you should 00096 use GenericFrame::deepCopyOf() to make a copy of the frame that 00097 can be safely held indefinitely. */ 00098 virtual GenericFrame readFrame(); 00099 00100 #ifdef HAVE_XCLIB 00101 xclib::pxbuffer_t getCurrBufID(); 00102 #endif 00103 00104 protected: 00105 //! Grab raw data (the raw bayer format data) 00106 /*! Don't call this directly; use readFrame() instead. */ 00107 VideoFrame grabRaw(); 00108 00109 //! get started 00110 virtual void start1(); 00111 00112 //! get stopped 00113 virtual void stop2(); 00114 00115 OModelParam<int> itsChannel; //!< framegrabber channel 00116 OModelParam<Dims> itsDims; //!< captured image dims, may be smaller than native 00117 OModelParam<Dims> itsOffset; //!< captured image offset if dims smaller than native 00118 OModelParam<int> itsNbuf; //!< Number of grab buffers to use 00119 00120 //! grab mode that the hardware should use 00121 /*! Grabbed frames will internally be converted to Image< 00122 PixRGB<byte> > whatever that mode is, but playing with it may 00123 influence image quality, maximum achievable framerate, and amounts 00124 of CPU doing those conversions to RGB. */ 00125 OModelParam<VideoFormat> itsGrabMode; 00126 00127 //! determines whether byte swapping is done during conversion to RGB 00128 OModelParam<bool> itsByteSwap; 00129 00130 OModelParam<int> itsWhiteBalTarR; //!< for white balance 00131 OModelParam<int> itsWhiteBalTarG; //!< for white balance 00132 OModelParam<int> itsWhiteBalTarB; //!< for white balance 00133 OModelParam<int> itsWhiteBalRefR; //!< for white balance 00134 OModelParam<int> itsWhiteBalRefG; //!< for white balance 00135 OModelParam<int> itsWhiteBalRefB; //!< for white balance 00136 OModelParam<float> itsGamma; //!< gamma correction, dependent on your driver 00137 OModelParam<float> itsFPS; //!< frames per second 00138 00139 int itsBitDepth; //!< Bit depth (per component) 00140 int itsNumComp; //!< Number of components 00141 pthread_mutex_t qmutex_buf; 00142 00143 // check whether the configure script found XClib and XC camera; if not, then 00144 // just stub out the core of the XCgrabber class and issue 00145 // LFATAL()s if somebody actually tries to use it 00146 #ifdef HAVE_XCLIB 00147 OModelParam<std::string> itsFormatFile; 00148 bool itsCameraOk; // the camera is initialized and transmitting 00149 xclib::pxbuffer_t itsLastBuf; 00150 byte* itsImgBuf; 00151 struct xclib::xclibs itsXclib; 00152 int itsStateid; 00153 int itsUnitMap; 00154 struct xclib::pximage **itsPximg; 00155 #endif // HAVE_XCLIB 00156 00157 private: 00158 virtual void paramChanged(ModelParamBase* const param, const bool valueChanged, 00159 ParamClient::ChangeStatus* status); 00160 00161 const char *err(const int errcode); //!< get an error string from an error code 00162 }; 00163 00164 #endif 00165 00166 // ###################################################################### 00167 /* So things look consistent in everyone's emacs... */ 00168 /* Local Variables: */ 00169 /* indent-tabs-mode: nil */ 00170 /* End: */