Main MRPT website > C++ reference
MRPT logo

mrpt::hwdrivers::CCameraSensor Class Reference

The central class for camera grabbers in MRPT, implementing the "generic sensor" interface. More...

#include <mrpt/hwdrivers/CCameraSensor.h>

Inheritance diagram for mrpt::hwdrivers::CCameraSensor:
Inheritance graph
[legend]
Collaboration diagram for mrpt::hwdrivers::CCameraSensor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CCameraSensor ()
 Constructor The camera is not open until "initialize" is called.
virtual ~CCameraSensor ()
 Destructor.
void doProcess ()
 This method should be called periodically (at least at 1Hz to capture ALL the real-time data) It is thread safe, i.e.
mrpt::slam::CObservationPtr getNextFrame ()
 Retrieves the next frame from the video source, raising an exception on any error.
virtual void initialize ()
 Tries to open the camera, after setting all the parameters with a call to loadConfig.
void close ()
 Close the camera (if open).
void setPathForExternalImages (const std::string &directory)
 Set the path where to save off-rawlog images: empty (default) means save images embedded in the rawlog.
void setExternalImageFormat (const std::string &ext)
 Set the extension ("jpg","gif","png",.
void setExternalImageJPEGQuality (const unsigned int quality)
 The quality of JPEG compression, when external images is enabled and the format is "jpg".
unsigned int getExternalImageJPEGQuality () const
void enableLaunchOwnThreadForSavingImages (bool enable=true)
 This must be called before initialize().

Protected Member Functions

void loadConfig_sensorSpecific (const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
 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) See hwdrivers::CCameraSensor for the possible parameters.

Protected Attributes

poses::CPose3D m_sensorPose
std::string m_sensorLabel
std::string m_grabber_type
 Can be "opencv",...
bool m_capture_grayscale
int m_cv_camera_index
std::string m_cv_camera_type
mrpt::hwdrivers::TCaptureCVOptions m_cv_options
uint64_t m_dc1394_camera_guid
int m_dc1394_camera_unit
mrpt::hwdrivers::TCaptureOptions_dc1394 m_dc1394_options
int m_preview_decimation
int m_preview_reduction
int m_bumblebee_camera_index
mrpt::hwdrivers::TCaptureOptions_bumblebee m_bumblebee_options
int m_bumblebee_monocam
std::string m_ffmpeg_url
std::string m_rawlog_file
std::string m_rawlog_camera_sensor_label
std::string m_rawlog_detected_images_dir
std::string m_path_for_external_images
 The path where to save off-rawlog images: empty means save images embedded in the rawlog.
std::string m_external_images_format
 The extension ("jpg","gif","png",...) that determines the format of images saved externally.
unsigned int m_external_images_jpeg_quality
 For JPEG images, the quality (default=95%).
bool m_external_images_own_thread
 Whether to launch independent thread.
unsigned int m_external_image_saver_count
 Number of working threads. Default:1, set to 2 in quad cores.
std::vector
< mrpt::system::TThreadHandle
m_threadImagesSaver
bool m_threadImagesSaverShouldEnd

Private Member Functions

void thread_save_images (unsigned int my_working_thread_index)
 Thread to save images to files.

Private Attributes

mrpt::hwdrivers::CImageGrabber_OpenCVm_cap_cv
 The OpenCV capture object.
mrpt::hwdrivers::CImageGrabber_dc1394m_cap_dc1394
 The dc1394 capture object.
mrpt::hwdrivers::CStereoGrabber_Bumblebeem_cap_bumblebee
 The bumblebee capture object.
CFFMPEG_InputStreamm_cap_ffmpeg
 The FFMPEG capture object.
mrpt::utils::CFileGZInputStreamm_cap_rawlog
 The input file for rawlogs.
int m_camera_grab_decimator
int m_camera_grab_decimator_counter
int m_preview_counter
mrpt::gui::CDisplayWindowPtr m_preview_win1
mrpt::gui::CDisplayWindowPtr m_preview_win2
 Normally we'll use only one window, but for stereo images we'll use two of them.
mrpt::synch::CCriticalSection m_csToSaveList
 The critical section for m_toSaveList.
std::vector< TListObservationsm_toSaveList
 The queues of objects to be returned by getObservations, one for each working thread.

Detailed Description

The central class for camera grabbers in MRPT, implementing the "generic sensor" interface.

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,...)

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:

   CCameraSensor myCam;
   string str = "[CONFIG]\n grabber_type=opencv \n";
   CConfigFileMemory    cfg(str);
   myCam.loadConfig(cfg,"CONFIG");
   myCam.initialize();
   CObservationPtr obs = myCam.getNextFrame();

Images can be retrieves through the normal "doProcess()" interface, or the specific method "getNextFrame()".

These is the list of all the accepted parameters:

  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
 -------------------------------------------------------
   [supplied_section_name]
    // Select one of the grabber implementations:
    grabber_type       = opencv | dc1394 | bumblebee | ffmpeg | rawlog
    preview_decimation = 0     // N<=0 (or not present): No preview; N>0, display 1 out of N captured frames.
    preview_reduction  = 0     // 0 or 1 (or not present): The preview shows the actual image. For 2,3,..., reduces the size of the image by that factor, only for the preview window.
    capture_grayscale  = 0     // 1:capture in grayscale, whenever the driver allows it. Default=0

    // Options for grabber_type= opencv
    cv_camera_index  = 0       // [opencv] Number of camera to open
    cv_camera_type   = CAMERA_CV_AUTODETECT
    cv_frame_width   = 640     // [opencv] Capture width (not present or set to 0 for default)
    cv_frame_height  = 480     // [opencv] Capture height (not present or set to 0 for default)
    cv_fps           = 15      // [opencv] IEEE1394 cams only: Capture FPS (not present or 0 for default)
    cv_gain          = 0       // [opencv] Camera gain, if available (nor present or set to 0 for default).

    // Options for grabber_type= dc1394
    dc1394_camera_guid   = 0 | 0x11223344    // 0 (or not present): the first camera; A hexadecimal number: The GUID of the camera to open
    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)
    dc1394_frame_width  = 640
    dc1394_frame_height = 480
    dc1394_framerate            = 15                                    // eg: 7.5, 15, 30, 60, etc... For posibilities see mrpt::hwdrivers::TCaptureOptions_dc1394
    dc1394_mode7         = -1                    // -1: Ignore, i>=0, set to MODE7_i
    dc1394_color_coding = COLOR_CODING_YUV422   // For posibilities see mrpt::hwdrivers::TCaptureOptions_dc1394
    dc1394_shutter              = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_gain                 = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_gamma                        = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_brightness   = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_exposure             = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_sharpness            = -1    // A value, or -1 (or not present) for not to change this parameter in the camera
    dc1394_white_balance        = -1    // A value, or -1 (or not present) for not to change this parameter in the camera

    // Options for grabber_type= bumblebee
    bumblebee_camera_index  = 0       // [bumblebee] Number of camera within the firewire bus to open (typically = 0)
    bumblebee_frame_width   = 640     // [bumblebee] Capture width (not present or set to 0 for default)
    bumblebee_frame_height  = 480     // [bumblebee] Capture height (not present or set to 0 for default)
    bumblebee_fps           = 15      // [bumblebee] Capture FPS (not present or 0 for default)
    bumblebee_mono          = 0|1     // [bumblebee] OPTIONAL: If this parameter is present, monocular (0:left, 1:right) images will be grabbed instead of stereo pairs.
    bumblebee_get_rectified = 0|1     // [bumblebee] Determines if the camera should grab rectified or raw images (1 is the default)

    // Options for grabber_type= ffmpeg
    ffmpeg_url             = rtsp://127.0.0.1      // [ffmpeg] The video file or IP camera to open

    // Options for grabber_type= rawlog
    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.
    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.

    // For externaly stored images, the format of image files (default=jpg)
    //external_images_format  = jpg

    // For externaly stored images: whether to spawn independent threads to save the image files.
    //external_images_own_thread  = 1   // 0 or 1

    // If external_images_own_thread=1, this changes the number of threads to launch
    //  to save image files. The default is determined from mrpt::system::getNumberOfProcessors()
    //  and should be OK unless you want to save processor time for other things.
    //external_images_own_thread_count = 2    // >=1

    // (Only when external_images_format=jpg): Optional parameter to set the JPEG compression quality:
    //external_images_jpeg_quality = 95    // [1-100]. Default: 95

    // Pose of the sensor on the robot:
    pose_x=0            ; (meters)
    pose_y=0
    pose_z=0
    pose_yaw=0  ; (Angles in degrees)
    pose_pitch=0
    pose_roll=0

Images can be saved in the "external storage" mode. See setPathForExternalImages and setExternalImageFormat. These methods are called automatically from rawlog-grabber.

Note:
The execution rate (in rawlog-grabber) should be greater than the required capture FPS.
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.
See also:
mrpt::hwdrivers::CImageGrabber_OpenCV, mrpt::hwdrivers::CImageGrabber_dc1394, CGenericSensor, prepareVideoSourceFromUserSelection

Definition at line 151 of file CCameraSensor.h.


Constructor & Destructor Documentation

mrpt::hwdrivers::CCameraSensor::CCameraSensor (  ) 

Constructor The camera is not open until "initialize" is called.

virtual mrpt::hwdrivers::CCameraSensor::~CCameraSensor (  )  [virtual]

Destructor.


Member Function Documentation

void mrpt::hwdrivers::CCameraSensor::close (  ) 

Close the camera (if open).

This method is called automatically on destruction.

void mrpt::hwdrivers::CCameraSensor::doProcess (  )  [virtual]

This method should be called periodically (at least at 1Hz to capture ALL the real-time data) It is thread safe, i.e.

you can call this from one thread, then to other methods from other threads.

Implements mrpt::hwdrivers::CGenericSensor.

void mrpt::hwdrivers::CCameraSensor::enableLaunchOwnThreadForSavingImages ( bool  enable = true  )  [inline]

This must be called before initialize().

Definition at line 207 of file CCameraSensor.h.

unsigned int mrpt::hwdrivers::CCameraSensor::getExternalImageJPEGQuality (  )  const [inline]

Definition at line 202 of file CCameraSensor.h.

mrpt::slam::CObservationPtr mrpt::hwdrivers::CCameraSensor::getNextFrame (  ) 

Retrieves the next frame from the video source, raising an exception on any error.

Note:
The observations can be of the classes CObservationImage or CObservationStereoImages
virtual void mrpt::hwdrivers::CCameraSensor::initialize (  )  [virtual]

Tries to open the camera, after setting all the parameters with a call to loadConfig.

Exceptions:
This method must throw an exception with a descriptive message if some critical error is found.

Reimplemented from mrpt::hwdrivers::CGenericSensor.

void mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific ( const mrpt::utils::CConfigFileBase configSource,
const std::string &  iniSection 
) [protected, virtual]

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) See hwdrivers::CCameraSensor for the possible parameters.

Implements mrpt::hwdrivers::CGenericSensor.

void mrpt::hwdrivers::CCameraSensor::setExternalImageFormat ( const std::string &  ext  )  [inline]

Set the extension ("jpg","gif","png",.

..) that determines the format of images saved externally The default is "jpg".

See also:
setPathForExternalImages, setExternalImageJPEGQuality

Definition at line 194 of file CCameraSensor.h.

void mrpt::hwdrivers::CCameraSensor::setExternalImageJPEGQuality ( const unsigned int  quality  )  [inline]

The quality of JPEG compression, when external images is enabled and the format is "jpg".

See also:
setExternalImageFormat

Definition at line 199 of file CCameraSensor.h.

void mrpt::hwdrivers::CCameraSensor::setPathForExternalImages ( const std::string &  directory  ) 

Set the path where to save off-rawlog images: empty (default) means save images embedded in the rawlog.

Exceptions:
std::exception If the directory cannot be created
void mrpt::hwdrivers::CCameraSensor::thread_save_images ( unsigned int  my_working_thread_index  )  [private]

Thread to save images to files.


Member Data Documentation

Definition at line 225 of file CCameraSensor.h.

Definition at line 227 of file CCameraSensor.h.

Definition at line 226 of file CCameraSensor.h.

Definition at line 268 of file CCameraSensor.h.

Definition at line 269 of file CCameraSensor.h.

The bumblebee capture object.

Definition at line 260 of file CCameraSensor.h.

The OpenCV capture object.

Definition at line 254 of file CCameraSensor.h.

The dc1394 capture object.

Definition at line 257 of file CCameraSensor.h.

The FFMPEG capture object.

Definition at line 263 of file CCameraSensor.h.

The input file for rawlogs.

Definition at line 266 of file CCameraSensor.h.

Definition at line 214 of file CCameraSensor.h.

The critical section for m_toSaveList.

Definition at line 274 of file CCameraSensor.h.

Definition at line 215 of file CCameraSensor.h.

Definition at line 216 of file CCameraSensor.h.

Definition at line 217 of file CCameraSensor.h.

Definition at line 219 of file CCameraSensor.h.

Definition at line 220 of file CCameraSensor.h.

Definition at line 221 of file CCameraSensor.h.

Number of working threads. Default:1, set to 2 in quad cores.

Definition at line 240 of file CCameraSensor.h.

The extension ("jpg","gif","png",...) that determines the format of images saved externally.

See also:
setPathForExternalImages

Definition at line 236 of file CCameraSensor.h.

For JPEG images, the quality (default=95%).

Definition at line 237 of file CCameraSensor.h.

Whether to launch independent thread.

Definition at line 239 of file CCameraSensor.h.

Definition at line 229 of file CCameraSensor.h.

Can be "opencv",...

Definition at line 213 of file CCameraSensor.h.

The path where to save off-rawlog images: empty means save images embedded in the rawlog.

Definition at line 235 of file CCameraSensor.h.

Definition at line 271 of file CCameraSensor.h.

Definition at line 222 of file CCameraSensor.h.

Definition at line 223 of file CCameraSensor.h.

mrpt::gui::CDisplayWindowPtr mrpt::hwdrivers::CCameraSensor::m_preview_win1 [private]

Definition at line 272 of file CCameraSensor.h.

mrpt::gui::CDisplayWindowPtr mrpt::hwdrivers::CCameraSensor::m_preview_win2 [private]

Normally we'll use only one window, but for stereo images we'll use two of them.

Definition at line 272 of file CCameraSensor.h.

Definition at line 232 of file CCameraSensor.h.

Definition at line 233 of file CCameraSensor.h.

Definition at line 231 of file CCameraSensor.h.

Definition at line 211 of file CCameraSensor.h.

Definition at line 207 of file CCameraSensor.h.

Definition at line 241 of file CCameraSensor.h.

Definition at line 243 of file CCameraSensor.h.

The queues of objects to be returned by getObservations, one for each working thread.

Definition at line 275 of file CCameraSensor.h.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010