Follow this link to skip to the main content

camera_group.h

Go to the documentation of this file.
00001 // -*-c++-*-
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /**
00004  * @file  camera_group.h
00005  *
00006  * Defines the base logical camera class.
00007  *
00008  * <br>@b Designer(s):  Daniel Clouse, Clay Kunz, Issa Nesnas
00009  * <br>@b Author(s):    Daniel Clouse
00010  * <br>@b Date:         June 9, 2006
00011  *
00012  * <b>Software License:</b><br>
00013  * <code>  http://claraty.jpl.nasa.gov/license/open_src/  or
00014  *         file: license/open_src.txt  </code>
00015  *
00016  * &copy; 2007, Jet Propulsion Laboratory, California Institute of Technology<br>
00017  * &copy; 2007, NASA Ames Research Center
00018  *
00019  * $Revision: 1.9 $
00020  */
00021 //-----------------------------------------------------------------------------
00022 
00023 #ifndef CAMERA_GROUP_H
00024 #define CAMERA_GROUP_H
00025 
00026 #include "claraty/share.h"
00027 #include "claraty/device_group.h"
00028 #include "claraty/camera.h"
00029 
00030 namespace claraty {
00031 
00032 template < typename Pixel > class Image;
00033 template < typename Pixel > class Camera_Image;
00034 
00035 //-----------------------------------------------------------------------------
00036 /**
00037  * Image acquisition/Camera related classes.
00038  *
00039  * The Camera_Group base class defines operations for cameras in a 
00040  * group.  This class provides a default group acquire that uses 
00041  * sequential image acquisition from the cameras. This function
00042  * needs to be specialized for synchronized image acquisition.
00043  * 
00044  * <code>
00045  * A_Camera        cam1, cam2;
00046  * Camera_Group    cam_pair1 ( cam1, cam2 );  // Uses default group acquire
00047  * A_Camera_Group  cam_pair2 ( cam1, cam2 );  // Uses hw-based sync. acquire
00048  *
00049  * vector< Image<uint8_t> > img_vec;
00050  * cam_pair.acquire(img_vec);
00051  * </code>
00052  *
00053  * @ingroup vision_file_io
00054  */
00055 
00056 class Camera_Group : public Device_Group {
00057   
00058 public:
00059   Camera_Group(Camera & cam1, Camera & cam2);
00060   Camera_Group(Camera & cam1, Camera & cam2, Camera & cam3);
00061   Camera_Group(Camera & cam1, Camera & cam2, Camera & cam3, Camera & cam4);
00062   Camera_Group(int size,
00063                const std::string & group_name = "");
00064 
00065   Camera & get_camera(unsigned int cam_index) const throw(std::out_of_range);
00066   
00067   // @name Acquisition
00068   // @{ 
00069   
00070   /*----------------------------------------------------------------------
00071    * @brief Acquire synchronized Images (unsigned char version).
00072    *
00073    * Defines interface and default implementation for synchronized image
00074    * acquisition.  A derived class must implement acquire with the following
00075    * behavior:
00076    * 1. Verify that the the current image format (as set by set_format) is
00077    *    not one of the 8 bit formats (MONO8, YUV411, YUV422, YUV444, RGB8),
00078    *    otherwise throw invalid_argument.
00079    *    Note that this interface requires all cameras in the group to
00080    *    have the same format size (8 or 16 bit).  However, the pixel
00081    *    geometry of the various cameras are not required to be the same.
00082    * 2. Resize each image to match the pixel geometry expected by its
00083    *    corresponding camera.
00084    * 3. For each physical camera, set the parameter settings to match 
00085    *    those of the corresponding logical camera.
00086    * 4. Acquire the synchronized images.
00087    * 5. If *timestamp_ptr not NULL, fill with the times the images were
00088    *    acquired.
00089    * 6. If *feature_map_prt not NULL, fill with the camera parameter
00090    *    settings in effect at the time the image were acquired. 
00091    *
00092    * During this process any other error encountered causes an exception
00093    * derived from Camera_Exception to be thrown.
00094    *    
00095    * @param[out] image_vec
00096    *             Returns newly acquired Images.  Each Image is resized
00097    *             to match the image size returned by the corresponding
00098    *             camera.  The size of the image_vec vector is not
00099    *             changed by this routine.  The number of images
00100    *             actually returned equals min(image_vec.size(), this.size()).
00101    *             Any images beyond this number are left unchanged.
00102    * @param[out] timestamp_vec
00103    *             Returns timestamps for each image.
00104    * @param[out] feature_map_vec
00105    *             Returns camera feature settings for each image.
00106    * @return     The number of valid images returned in image_vec.
00107    *             This value may be less than image_vec.size().  It is
00108    *             equal to min(image_vec.size(), this.size()).
00109    */
00110   virtual int acquire(std::vector< Image<uint8_t> * > & image_vec,
00111                       std::vector< Time             > * timestamp_vec   = NULL,
00112                       std::vector< Feature_Map    * > * feature_map_vec = NULL)
00113     throw (std::exception);
00114 
00115   /*----------------------------------------------------------------------
00116    * @brief Acquire synchronized Images (unsigned short version).
00117    *
00118    * Behavior is the same as that of the unsigned char version except
00119    * that this version works with MONO16 and RGB16 formats only.
00120    */
00121   virtual int acquire(std::vector< Image<uint16_t> * > & image_vec,
00122                       std::vector< Time              > * timestamp_vec   = NULL,
00123                       std::vector< Feature_Map     * > * feature_map_vec = NULL)
00124     throw (std::exception);
00125   
00126   template <class Pixel_Type> 
00127   int acquire(std::vector< Camera_Image<Pixel_Type> * > & cam_img_ptr_vec);
00128 
00129   template <class Pixel_Type> 
00130   int acquire(std::vector< Camera_Image<Pixel_Type>   > & cam_img_ptr_vec);
00131 
00132   // @}
00133 
00134   virtual bool io(FDM_Map map);
00135 
00136 protected:
00137   void _verify_pixel_format    (size_t pixel_size);
00138   template <class Pixel_Type>
00139   void _verify_resize_images(std::vector < Image<Pixel_Type> * > & img_vec);
00140 
00141   template <class Pixel_Type> 
00142   int _acquire(std::vector< Image<Pixel_Type> * > & img_vec,
00143                std::vector< Time                > * time_vec        = NULL,
00144                std::vector< Feature_Map       * > * feature_map_vec = NULL)
00145     throw (std::exception); 
00146   
00147 };
00148 
00149 //-------------------------------------------------------------------------
00150 
00151 } // namespace claraty
00152 
00153 #include "claraty/camera_group.ipp"
00154 
00155 #endif   // CAMERA_GROUP_H