00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Perception and Robotics | 00009 | research group, 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 00029 #ifndef CCameraSensor_H 00030 #define CCameraSensor_H 00031 00032 #include <mrpt/poses/CPose3D.h> 00033 #include <mrpt/slam/CObservation.h> 00034 #include <mrpt/utils/CDebugOutputCapable.h> 00035 #include <mrpt/hwdrivers/CGenericSensor.h> 00036 #include <mrpt/hwdrivers/CFFMPEG_InputStream.h> 00037 #include <mrpt/vision/CImageGrabber_OpenCV.h> 00038 #include <mrpt/vision/CImageGrabber_dc1394.h> 00039 #include <mrpt/vision/CStereoGrabber_Bumblebee.h> 00040 #include <mrpt/utils/CFileGZInputStream.h> 00041 00042 #include <mrpt/gui/CDisplayWindow.h> 00043 00044 namespace mrpt 00045 { 00046 namespace hwdrivers 00047 { 00048 /** The central class for camera grabbers in MRPT, implementing the "generic sensor" interface. 00049 * This class provides the user with a uniform interface to a variety of other classes which manage only one specific camera "driver" (opencv, ffmpeg, bumblebee,...) 00050 * 00051 * Following the "generic sensor" interface, all the parameters must be passed int the form of a configuration file, which may be also formed on the fly (without being a real config file) as in this example: 00052 * 00053 * \code 00054 * CCameraSensor myCam; 00055 * string str = "[CONFIG]\n grabber_type=opencv \n"; 00056 * CConfigFileMemory cfg(str); 00057 * myCam.loadConfig(cfg,"CONFIG"); 00058 * \endcode 00059 * 00060 * Images can be retrieves through the normal "doProcess()" interface, or the specific method "getNextFrame()". 00061 * 00062 * These is the list of all the accepted parameters: 00063 * 00064 * \code 00065 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00066 * ------------------------------------------------------- 00067 * [supplied_section_name] 00068 * // Select one of the grabber implementations: 00069 * grabber_type = opencv | dc1394 | bumblebee | ffmpeg | rawlog 00070 * preview_decimation = 0 // N<=0 : No preview; N>0, display 1 out of N captured frames. 00071 * capture_grayscale = 0 // 1:capture in grayscale, whenever the driver allows it. 00072 * 00073 * // Options for grabber_type= opencv 00074 * cv_camera_index = 0 // [opencv] Number of camera to open 00075 * cv_camera_type = CAMERA_CV_AUTODETECT 00076 * cv_frame_width = 640 // [opencv] Capture width (not present or set to 0 for default) 00077 * cv_frame_height = 480 // [opencv] Capture height (not present or set to 0 for default) 00078 * cv_fps = 15 // [opencv] IEEE1394 cams only: Capture FPS (not present or 0 for default) 00079 * cv_gain = 0 // [opencv] Camera gain, if available (nor present or set to 0 for default). 00080 * 00081 * // Options for grabber_type= dc1394 00082 * dc1394_camera_guid = 0 | 0x11223344 // 0 (or not present): the first camera; A hexadecimal number: The GUID of the camera to open 00083 * dc1394_camera_unit = 0 // 0 (or not present): the first camera; 0,1,2,...: The unit number (within the given GUID) of the camera to open (Stereo cameras: 0 or 1) 00084 * dc1394_frame_width = 640 00085 * dc1394_frame_height = 480 00086 * dc1394_framerate = 15 // eg: 7.5, 15, 30, 60, etc... For posibilities see mrpt::vision::TCaptureOptions_dc1394 00087 * dc1394_mode7 = -1 // -1: Ignore, i>=0, set to MODE7_i 00088 * dc1394_color_coding = COLOR_CODING_YUV422 // For posibilities see mrpt::vision::TCaptureOptions_dc1394 00089 * dc1394_shutter = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00090 * dc1394_gain = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00091 * dc1394_gamma = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00092 * dc1394_brightness = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00093 * dc1394_exposure = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00094 * dc1394_sharpness = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00095 * dc1394_white_balance = -1 // A value, or -1 (or not present) for not to change this parameter in the camera 00096 * 00097 * // Options for grabber_type= bumblebee 00098 * bumblebee_camera_index = 0 // [bumblebee] Number of camera within the firewire bus to open (typically = 0) 00099 * bumblebee_frame_width = 640 // [bumblebee] Capture width (not present or set to 0 for default) 00100 * bumblebee_frame_height = 480 // [bumblebee] Capture height (not present or set to 0 for default) 00101 * bumblebee_fps = 15 // [bumblebee] Capture FPS (not present or 0 for default) 00102 * bumblebee_mono = 0|1 // [bumblebee] OPTIONAL: If this parameter is present, monocular (0:left, 1:right) images will be grabbed instead of stereo pairs. 00103 * bumblebee_get_rectified = 0|1 // [bumblebee] Determines if the camera should grab rectified or raw images (1 is the default) 00104 * 00105 * // Options for grabber_type= ffmpeg 00106 * ffmpeg_url = rtsp://127.0.0.1 // [ffmpeg] The video file or IP camera to open 00107 * 00108 * // Options for grabber_type= rawlog 00109 * rawlog_file = mylog.rawlog // [rawlog] This can be used to simulate the capture of images already grabbed in the past in the form of a MRPT rawlog. 00110 * rawlog_camera_sensor_label = CAMERA1 // [rawlog] If this field is not present, all images found in the rawlog will be retrieved. Otherwise, only those observations with a matching sensor label. 00111 * 00112 * // Pose of the sensor on the robot: 00113 * pose_x=0 ; (meters) 00114 * pose_y=0 00115 * pose_z=0 00116 * pose_yaw=0 ; (Angles in degrees) 00117 * pose_pitch=0 00118 * pose_roll=0 00119 * 00120 * \endcode 00121 * 00122 * - "grabber_type" is the class to use internally for image capturing. Choices are "opencv" (Windows & Linux) or "dc1394" (Linux only for now, requires libdc1394-2). 00123 * - For the meaning of cv_camera_type and other parameters, refer to mrpt::vision::CImageGrabber_OpenCV 00124 * - For the parameters of dc1394 parameters, refer to generic IEEE1394 documentation, and to mrpt::vision::TCaptureOptions_dc1394. 00125 * 00126 * Images can be saved in the "external storage" mode. See setPathForExternalImages and setExternalImageFormat. These methods 00127 * are called automatically from rawlog-grabber. 00128 * 00129 * \note The execution rate (in rawlog-grabber) should be greater than the required capture FPS. 00130 * \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. 00131 * \sa mrpt::vision::CImageGrabber_OpenCV, mrpt::vision::CImageGrabber_dc1394, CGenericSensor, prepareVideoSourceFromUserSelection 00132 */ 00133 class HWDLLIMPEXP CCameraSensor : public utils::CDebugOutputCapable, public CGenericSensor 00134 { 00135 DEFINE_GENERIC_SENSOR(CCameraSensor) 00136 00137 public: 00138 /** Constructor 00139 * The camera is not open until "initialize" is called. 00140 */ 00141 CCameraSensor(); 00142 00143 /** Destructor 00144 */ 00145 virtual ~CCameraSensor(); 00146 00147 /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data) 00148 * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.rip 00149 */ 00150 void doProcess(); 00151 00152 /** Retrieves the next frame from the video source, raising an exception on any error. 00153 * \note The observations can be of the classes CObservationImage or CObservationStereoImages 00154 */ 00155 mrpt::slam::CObservationPtr getNextFrame(); 00156 00157 /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes) 00158 * See hwdrivers::CCameraSensor for the possible parameters 00159 */ 00160 void loadConfig( 00161 const mrpt::utils::CConfigFileBase &configSource, 00162 const std::string &iniSection ); 00163 00164 /** Tries to open the camera, after setting all the parameters with a call to loadConfig. 00165 * \exception This method must throw an exception with a descriptive message if some critical error is found. 00166 */ 00167 virtual void initialize(); 00168 00169 00170 /** Close the camera (if open). 00171 * This method is called automatically on destruction. 00172 */ 00173 void close(); 00174 00175 00176 /** Set the path where to save off-rawlog images: empty (default) means save images embedded in the rawlog. 00177 * \exception std::exception If the directory cannot be created 00178 */ 00179 void setPathForExternalImages( const std::string &directory ); 00180 00181 /** Set the extension ("jpg","gif","png",...) that determines the format of images saved externally 00182 * The default is "jpg". 00183 * \sa setPathForExternalImages 00184 */ 00185 void setExternalImageFormat( const std::string &ext ) 00186 { 00187 m_external_images_format = ext; 00188 } 00189 00190 protected: 00191 poses::CPose3D m_sensorPose; 00192 std::string m_sensorLabel; 00193 00194 std::string m_grabber_type; //!< Can be "opencv",... 00195 bool m_capture_grayscale; 00196 int m_cv_camera_index; 00197 std::string m_cv_camera_type; 00198 mrpt::vision::TCaptureCVOptions m_cv_options; 00199 00200 uint64_t m_dc1394_camera_guid; 00201 int m_dc1394_camera_unit; 00202 mrpt::vision::TCaptureOptions_dc1394 m_dc1394_options; 00203 int m_preview_decimation; 00204 00205 int m_bumblebee_camera_index; 00206 mrpt::vision::TCaptureOptions_bumblebee m_bumblebee_options; 00207 int m_bumblebee_monocam; // 0:Left, 1: Right, <0,>1 -> Stereo 00208 00209 std::string m_ffmpeg_url; 00210 00211 std::string m_rawlog_file; 00212 std::string m_rawlog_camera_sensor_label; 00213 00214 std::string m_path_for_external_images; //!< The path where to save off-rawlog images: empty means save images embedded in the rawlog. 00215 std::string m_external_images_format; //!< The extension ("jpg","gif","png",...) that determines the format of images saved externally \sa setPathForExternalImages 00216 00217 private: 00218 /** The OpenCV capture object. */ 00219 mrpt::vision::CImageGrabber_OpenCV *m_cap_cv; 00220 00221 /** The dc1394 capture object. */ 00222 mrpt::vision::CImageGrabber_dc1394 *m_cap_dc1394; 00223 00224 /** The bumblebee capture object. */ 00225 mrpt::vision::CStereoGrabber_Bumblebee *m_cap_bumblebee; 00226 00227 /** The FFMPEG capture object */ 00228 CFFMPEG_InputStream *m_cap_ffmpeg; 00229 00230 /** The input file for rawlogs */ 00231 mrpt::utils::CFileGZInputStream *m_cap_rawlog; 00232 00233 int m_preview_counter; 00234 mrpt::gui::CDisplayWindow *m_preview_win; 00235 00236 }; // end class 00237 00238 typedef stlplus::smart_ptr<CCameraSensor> CCameraSensorPtr; //!< A smart pointer to a CCameraSensor 00239 00240 /** Used only from MRPT apps: Use with caution since "panel" MUST be a "mrpt::gui::CPanelCameraSelection *" 00241 */ 00242 CCameraSensorPtr HWDLLIMPEXP prepareVideoSourceFromPanel(void *panel); 00243 00244 /** Show to the user a list of possible camera drivers and creates and open the selected camera. 00245 */ 00246 CCameraSensorPtr HWDLLIMPEXP prepareVideoSourceFromUserSelection(); 00247 00248 00249 00250 } // end namespace 00251 } // end namespace 00252 00253 #endif
Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 22:58:25 EDT 2009 |