Main MRPT website > C++ reference
MRPT logo
CImageGrabber_OpenCV.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 CImageGrabber_OpenCV_H
00029 #define CImageGrabber_OpenCV_H
00030 
00031 #include <mrpt/config.h>
00032 #include <mrpt/hwdrivers/link_pragmas.h>
00033 
00034 #include <mrpt/slam/CObservationImage.h>
00035 #include <mrpt/utils/safe_pointers.h>
00036 
00037 
00038 namespace mrpt
00039 {
00040         namespace hwdrivers
00041         {
00042                 /** These capture types are like their OpenCV equivalents. */
00043                 enum TCameraType
00044                 {
00045                         CAMERA_CV_AUTODETECT = 0,
00046                         CAMERA_CV_DC1394,
00047                         CAMERA_CV_VFL,
00048                         CAMERA_CV_VFW,
00049                         CAMERA_CV_MIL,
00050                         CAMERA_CV_DSHOW //!< Valid only with OpenCV >= 1.1.0
00051                 };
00052 
00053                 /** Options used when creating an OpenCV capture object
00054                   *  Some options apply to IEEE1394 cameras only.
00055                   * \sa CImageGrabber_OpenCV
00056                   * \ingroup mrpt_hwdrivers_grp
00057                   */
00058                 struct TCaptureCVOptions
00059                 {
00060                         TCaptureCVOptions() :
00061                                 frame_width(0), frame_height(0),
00062                                 gain(0),
00063                                 ieee1394_fps(0),
00064                                 ieee1394_grayscale(false)
00065                         {}
00066 
00067                         int             frame_width,frame_height;       //!< (All cameras) Capture resolution (0: Leave the default)
00068                         double  gain;                   //!< (All cameras) Camera gain (0: Leave the default)
00069                         double  ieee1394_fps;   //!< (IEEE1394 cameras) Frame rate for the capture (0: Leave the default).
00070                         bool    ieee1394_grayscale;     //!< (IEEE1394 cameras) Whether to grab grayscale images (Default=false).
00071                 };
00072 
00073                 /** A class for grabing images from a "OpenCV"-compatible camera, or from an AVI video file.
00074                   *   See the constructor for the options when opening the camera.
00075                   *
00076                   *  Unless input from AVI files is required, it is recommended to use the more generic class
00077                   *   mrpt::hwdrivers::CCameraSensor.
00078                   *
00079                   * \note This class is only available when compiling MRPT with the flag "MRPT_HAS_OPENCV" defined.
00080                   * \note Some code is based on the class CaptureCamera from the Orocos project.
00081                   * \sa mrpt::hwdrivers::CCameraSensor, CImageGrabber_dc1394
00082                   * \sa The most generic camera grabber in MRPT: mrpt::hwdrivers::CCameraSensor
00083                   * \ingroup mrpt_hwdrivers_grp
00084                   */
00085                 class HWDRIVERS_IMPEXP CImageGrabber_OpenCV
00086                 {
00087                 protected:
00088                         /** Set to false if we could not initialize the camera.
00089                           */
00090                         bool    m_bInitialized;
00091 
00092                         /** Internal use:
00093                           */
00094                         mrpt::utils::void_ptr_noncopy /*CvCapture*/ m_capture;
00095 
00096                 public:
00097                         /** Constructor for cameras:
00098                          * \param cameraIndex Set the camera index, or -1 if it does not matter and you select AUTODETECT as cameraType.
00099                          * \param cameraType Can be any value of TCameraType, or CAMERA_CV_AUTODETECT if there is only one camera.
00100                          * \param options Capture options, defined in mrpt::hwdrivers::TCaptureCVOptions. If not provided, all the default options will be used.
00101                          */
00102                         CImageGrabber_OpenCV(
00103                                 int cameraIndex = -1,
00104                                 TCameraType cameraType = CAMERA_CV_AUTODETECT,
00105                                 const TCaptureCVOptions &options = TCaptureCVOptions()
00106                                  );
00107 
00108                         /** Constructor for AVI files:
00109                         */
00110                         CImageGrabber_OpenCV( const std::string &AVI_fileName );
00111 
00112                         /** Destructor
00113                         */
00114                         virtual ~CImageGrabber_OpenCV( );
00115 
00116                         /** Check whether the camera has been open successfully. */
00117                         bool isOpen() const
00118                         {
00119                                 return m_bInitialized;
00120                         }
00121 
00122                         /** Grab an image from the opened camera.
00123                          * \param out_observation The object to be filled with sensed data.
00124                          *
00125                          * \return false on any error, true if all go fine.
00126                         */
00127                         bool  getObservation( mrpt::slam::CObservationImage &out_observation);
00128 
00129 
00130                 };      // End of class
00131 
00132         } // End of NS
00133 } // End of NS
00134 
00135 
00136 #endif



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