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://mrpt.sourceforge.net/                            |
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                   */
00068                 struct TCaptureOptions_dc1394
00069                 {
00070                         TCaptureOptions_dc1394() :
00071                                 frame_width             (640),
00072                                 frame_height    (480),
00073                                 framerate               (FRAMERATE_15),
00074                                 color_coding    (COLOR_CODING_YUV422),
00075                                 mode7                   (-1),
00076                                 shutter                 (-1),
00077                                 gain                    (-1),
00078                                 gamma                   (-1),
00079                                 brightness              (-1),
00080                                 exposure                (-1),
00081                                 sharpness               (-1),
00082                                 white_balance   (-1),
00083                                 deinterlace_stereo(false)
00084                         {}
00085 
00086                         int             frame_width,frame_height;       //!< Capture resolution (Default: 640x480)
00087                         grabber_dc1394_framerate_t              framerate;
00088                         grabber_dc1394_color_coding_t   color_coding;
00089 
00090                         int             mode7;                  //!< -1: Normal mode, i>=0: use MODE7_i, then frame_width/height and color_coding are ignored.
00091 
00092                         int             shutter;                //!< Shutter, -1=default:Do not change
00093                         int             gain;                   //!< Gain, -1=default:Do not change
00094                         int             gamma;                  //!< Gamma, -1=default:Do not change
00095                         int             brightness;             //!< Brightness, -1=default:Do not change
00096                         int             exposure;               //!< Exposure, -1=default:Do not change
00097                         int             sharpness;              //!< Sharpness, -1=default:Do not change
00098                         int             white_balance;  //!< White balance, -1=default:Do not change
00099                         bool    deinterlace_stereo;     //!< For stereo cameras (eg PR Bumblebee)
00100                 };
00101 
00102                 /** A class for grabing images from a IEEE1394 (Firewire) camera using the libdc1394-2 library.
00103                   *   See the constructor for the options when opening the camera. Notice that you may have
00104                   *    to carefully set the resolution, framerate and color_mode. See the verbose parameter of
00105                   *    the constructor, which can display a list of supported modes in your camera.
00106                   *
00107                   *  This class is able to manage any Firewire cameras, including Stereo or multi-cameras in general,
00108                   *    so this can be used to open the Bumblebee camera (not tested yet).
00109                   *
00110                   * A static method (CImageGrabber_dc1394::enumerateCameras) is provided to enumerate all existing cameras and their properties. It can be used
00111                   *  to find the GUID of the desired camera, then open it at the constructor.
00112                   *
00113                   * \note This class requires MRPT compiled with "libdc1394-2" (Only works under Linux for now) and "opencv".
00114                   * \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.
00115                   * \sa The most generic camera grabber in MRPT: mrpt::hwdrivers::CCameraSensor
00116                   */
00117                 class HWDRIVERS_IMPEXP CImageGrabber_dc1394
00118                 {
00119                 protected:
00120                         /** Set to false if we could not initialize the camera.
00121                           */
00122                         bool    m_bInitialized;
00123 
00124                         /** Internal use: */
00125                         void /* dc1394_t * */           *m_dc1394_lib_context;
00126                         void /* dc1394camera_t* */      *m_dc1394camera;
00127                         int                                                     m_desired_mode;
00128 
00129 
00130                         TCaptureOptions_dc1394          m_options;
00131 
00132                 public:
00133                         /** Constructor: open an ieee1394 camera.
00134                          * \param cameraGUID Set the camera GUID to open, or 0 to open the first found camera.
00135                          * \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.
00136                          * \param options Capture options, defined in mrpt::hwdrivers::TCaptureOptions_dc1394.
00137                          * \param verbose  Displays a lot of information about the camera to be open and its valid video modes.
00138                          */
00139                         CImageGrabber_dc1394(
00140                                 uint64_t        cameraGUID = 0,
00141                                 uint16_t        cameraUnit = 0,
00142                                 const TCaptureOptions_dc1394 &options = TCaptureOptions_dc1394(),
00143                                 bool  verbose = false
00144                                 );
00145 
00146                         /** Destructor
00147                         */
00148                         virtual ~CImageGrabber_dc1394( );
00149 
00150                         /** Check whether the camera has been open successfully. */
00151                         bool isOpen() const
00152                         {
00153                                 return m_bInitialized;
00154                         }
00155 
00156                         /** Changes the capture properties (brightness, gain, shutter, etc)
00157                           * The frame size, framerate, and color_coding fields in options are ignored since they can be only set at construction time.
00158                           * \return false on error
00159                           */
00160                         bool changeCaptureOptions( const TCaptureOptions_dc1394 &options  );
00161 
00162 
00163                         /** Grab an image from the opened camera (for monocular cameras).
00164                          * \param out_observation The object to be filled with sensed data.
00165                          *
00166                          * \return false on any error, true if all go fine.
00167                         */
00168                         bool  getObservation( mrpt::slam::CObservationImage &out_observation);
00169 
00170                         /** Grab an image from the opened camera (for stereo cameras).
00171                          * \param out_observation The object to be filled with sensed data.
00172                          *
00173                          * \return false on any error, true if all go fine.
00174                         */
00175                         bool  getObservation( mrpt::slam::CObservationStereoImages &out_observation);
00176 
00177                         /** Used in enumerateCameras */
00178                         struct TCameraInfo
00179                         {
00180                                 uint64_t             guid;
00181                                 int                  unit;
00182                                 uint32_t             unit_spec_ID;
00183                                 uint32_t             unit_sw_version;
00184                                 uint32_t             unit_sub_sw_version;
00185                                 uint32_t             command_registers_base;
00186                                 uint32_t             unit_directory;
00187                                 uint32_t             unit_dependent_directory;
00188                                 uint64_t             advanced_features_csr;
00189                                 uint64_t             PIO_control_csr;
00190                                 uint64_t             SIO_control_csr;
00191                                 uint64_t             strobe_control_csr;
00192                                 uint64_t             format7_csr[16];
00193                                 int                  iidc_version;
00194                                 std::string          vendor;
00195                                 std::string          model;
00196                                 uint32_t             vendor_id;
00197                                 uint32_t             model_id;
00198                                 bool                 bmode_capable;
00199                                 bool                 one_shot_capable;
00200                                 bool                 multi_shot_capable;
00201                                 bool                 can_switch_on_off;
00202                                 bool                 has_vmode_error_status;
00203                                 bool                 has_feature_error_status;
00204                                 int                  max_mem_channel;
00205                         };
00206 
00207                         typedef std::list<TCameraInfo> TCameraInfoList;
00208 
00209                         /** Generates a list with the information on all the existing (Firewire) cameras in the system.
00210                           * \exception std::runtime_error On any error calling libdc1394.
00211                           */
00212                         static void enumerateCameras( TCameraInfoList &out_list );
00213 
00214 
00215                 };      // End of class
00216 
00217         } // End of NS
00218 } // End of NS
00219 
00220 
00221 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011