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