Main MRPT website > C++ reference
MRPT logo
CImageGrabber_dc1394.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CCImageGrabber_dc1394
00029 #define CCImageGrabber_dc1394
00030 
00031 #include <mrpt/config.h>
00032 
00033 #include <mrpt/slam/CObservationImage.h>
00034 #include <mrpt/slam/CObservationStereoImages.h>
00035 
00036 #include <mrpt/hwdrivers/link_pragmas.h>
00037 
00038 namespace mrpt
00039 {
00040         namespace hwdrivers
00041         {
00042 
00043                 typedef enum {
00044                         FRAMERATE_1_875= 32,
00045                         FRAMERATE_3_75,
00046                         FRAMERATE_7_5,
00047                         FRAMERATE_15,
00048                         FRAMERATE_30,
00049                         FRAMERATE_60,
00050                         FRAMERATE_120,
00051                         FRAMERATE_240
00052                 } grabber_dc1394_framerate_t;
00053 
00054                 typedef enum {
00055                         COLOR_CODING_MONO8= 352,
00056                         COLOR_CODING_YUV411,
00057                         COLOR_CODING_YUV422,
00058                         COLOR_CODING_YUV444,
00059                         COLOR_CODING_RGB8,
00060                         COLOR_CODING_MONO16
00061                 } grabber_dc1394_color_coding_t;
00062 
00063 
00064                 /** Options used when creating an dc1394 capture object
00065                   *   All but the frame size, framerate, and color_coding can be changed dynamically by CImageGrabber_dc1394::changeCaptureOptions
00066                   * \sa CImageGrabber_dc1394
00067                   * \ingroup mrpt_hwdrivers_grp
00068                   */
00069                 struct TCaptureOptions_dc1394
00070                 {
00071                         TCaptureOptions_dc1394() :
00072                                 frame_width             (640),
00073                                 frame_height    (480),
00074                                 framerate               (FRAMERATE_15),
00075                                 color_coding    (COLOR_CODING_YUV422),
00076                                 mode7                   (-1),
00077                                 shutter                 (-1),
00078                                 gain                    (-1),
00079                                 gamma                   (-1),
00080                                 brightness              (-1),
00081                                 exposure                (-1),
00082                                 sharpness               (-1),
00083                                 white_balance   (-1),
00084                                 deinterlace_stereo(false)
00085                         {}
00086 
00087                         int             frame_width,frame_height;       //!< Capture resolution (Default: 640x480)
00088                         grabber_dc1394_framerate_t              framerate;
00089                         grabber_dc1394_color_coding_t   color_coding;
00090 
00091                         int             mode7;                  //!< -1: Normal mode, i>=0: use MODE7_i, then frame_width/height and color_coding are ignored.
00092 
00093                         int             shutter;                //!< Shutter, -1=default:Do not change
00094                         int             gain;                   //!< Gain, -1=default:Do not change
00095                         int             gamma;                  //!< Gamma, -1=default:Do not change
00096                         int             brightness;             //!< Brightness, -1=default:Do not change
00097                         int             exposure;               //!< Exposure, -1=default:Do not change
00098                         int             sharpness;              //!< Sharpness, -1=default:Do not change
00099                         int             white_balance;  //!< White balance, -1=default:Do not change
00100                         bool    deinterlace_stereo;     //!< For stereo cameras (eg PR Bumblebee)
00101                 };
00102 
00103                 /** A class for grabing images from a IEEE1394 (Firewire) camera using the libdc1394-2 library.
00104                   *   See the constructor for the options when opening the camera. Notice that you may have
00105                   *    to carefully set the resolution, framerate and color_mode. See the verbose parameter of
00106                   *    the constructor, which can display a list of supported modes in your camera.
00107                   *
00108                   *  This class is able to manage any Firewire cameras, including Stereo or multi-cameras in general,
00109                   *    so this can be used to open the Bumblebee camera (not tested yet).
00110                   *
00111                   * A static method (CImageGrabber_dc1394::enumerateCameras) is provided to enumerate all existing cameras and their properties. It can be used
00112                   *  to find the GUID of the desired camera, then open it at the constructor.
00113                   *
00114                   * \note This class requires MRPT compiled with "libdc1394-2" (Only works under Linux for now) and "opencv".
00115                   * \note In Linux you may need to execute "chmod 666 /dev/video1394/ * " and "chmod 666 /dev/raw1394" for allowing any user R/W access to firewire cameras.
00116                   * \sa The most generic camera grabber in MRPT: mrpt::hwdrivers::CCameraSensor
00117                   * \ingroup mrpt_hwdrivers_grp
00118                   */
00119                 class HWDRIVERS_IMPEXP CImageGrabber_dc1394
00120                 {
00121                 protected:
00122                         /** Set to false if we could not initialize the camera.
00123                           */
00124                         bool    m_bInitialized;
00125 
00126                         /** Internal use: */
00127                         void /* dc1394_t * */           *m_dc1394_lib_context;
00128                         void /* dc1394camera_t* */      *m_dc1394camera;
00129                         int                                                     m_desired_mode;
00130 
00131 
00132                         TCaptureOptions_dc1394          m_options;
00133 
00134                 public:
00135                         /** Constructor: open an ieee1394 camera.
00136                          * \param cameraGUID Set the camera GUID to open, or 0 to open the first found camera.
00137                          * \param cameraUnit (Ignored if cameraGUID=0). The number of camera to open within the device with the given GUID: In a stereo camera this may be 0 or 1. Normally this is 0.
00138                          * \param options Capture options, defined in mrpt::hwdrivers::TCaptureOptions_dc1394.
00139                          * \param verbose  Displays a lot of information about the camera to be open and its valid video modes.
00140                          */
00141                         CImageGrabber_dc1394(
00142                                 uint64_t        cameraGUID = 0,
00143                                 uint16_t        cameraUnit = 0,
00144                                 const TCaptureOptions_dc1394 &options = TCaptureOptions_dc1394(),
00145                                 bool  verbose = false
00146                                 );
00147 
00148                         /** Destructor
00149                         */
00150                         virtual ~CImageGrabber_dc1394( );
00151 
00152                         /** Check whether the camera has been open successfully. */
00153                         bool isOpen() const
00154                         {
00155                                 return m_bInitialized;
00156                         }
00157 
00158                         /** Changes the capture properties (brightness, gain, shutter, etc)
00159                           * The frame size, framerate, and color_coding fields in options are ignored since they can be only set at construction time.
00160                           * \return false on error
00161                           */
00162                         bool changeCaptureOptions( const TCaptureOptions_dc1394 &options  );
00163 
00164 
00165                         /** Grab an image from the opened camera (for monocular cameras).
00166                          * \param out_observation The object to be filled with sensed data.
00167                          *
00168                          * \return false on any error, true if all go fine.
00169                         */
00170                         bool  getObservation( mrpt::slam::CObservationImage &out_observation);
00171 
00172                         /** Grab an image from the opened camera (for stereo cameras).
00173                          * \param out_observation The object to be filled with sensed data.
00174                          *
00175                          * \return false on any error, true if all go fine.
00176                         */
00177                         bool  getObservation( mrpt::slam::CObservationStereoImages &out_observation);
00178 
00179                         /** Used in enumerateCameras */
00180                         struct TCameraInfo
00181                         {
00182                                 uint64_t             guid;
00183                                 int                  unit;
00184                                 uint32_t             unit_spec_ID;
00185                                 uint32_t             unit_sw_version;
00186                                 uint32_t             unit_sub_sw_version;
00187                                 uint32_t             command_registers_base;
00188                                 uint32_t             unit_directory;
00189                                 uint32_t             unit_dependent_directory;
00190                                 uint64_t             advanced_features_csr;
00191                                 uint64_t             PIO_control_csr;
00192                                 uint64_t             SIO_control_csr;
00193                                 uint64_t             strobe_control_csr;
00194                                 uint64_t             format7_csr[16];
00195                                 int                  iidc_version;
00196                                 std::string          vendor;
00197                                 std::string          model;
00198                                 uint32_t             vendor_id;
00199                                 uint32_t             model_id;
00200                                 bool                 bmode_capable;
00201                                 bool                 one_shot_capable;
00202                                 bool                 multi_shot_capable;
00203                                 bool                 can_switch_on_off;
00204                                 bool                 has_vmode_error_status;
00205                                 bool                 has_feature_error_status;
00206                                 int                  max_mem_channel;
00207                         };
00208 
00209                         typedef std::list<TCameraInfo> TCameraInfoList;
00210 
00211                         /** Generates a list with the information on all the existing (Firewire) cameras in the system.
00212                           * \exception std::runtime_error On any error calling libdc1394.
00213                           */
00214                         static void enumerateCameras( TCameraInfoList &out_list );
00215 
00216 
00217                 };      // End of class
00218 
00219         } // End of NS
00220 } // End of NS
00221 
00222 
00223 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011