class mrpt::hwdrivers::CSwissRanger3DCamera

A class for grabing “range images” from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).


  • This class requires a vendor specific driver installed in the system in order to build MRPT with support for this sensor. Download and install the driver from:

  • The intensity channel (grayscale image) is converted from 16bit to standard 8bit-per-pixel using a logarithmic, modified A-law compression. This allows exploiting the full dynamic range of the sensor and provides quite good results.

As with any other CGenericSensor class, the normal sequence of methods to be called is:

This sensor can be also used from within rawlog-grabber.

     sensorLabel  = CAM3D         // A text description
     preview_window  = true       // Show a window with a preview of the
*grabbed data in real-time

     open_USB     = true          // false means ethernet (default: true)
     USB_serial   = 0x4000002f    // only for open_USB=true. If not set, the
*first camera will be open. Serial is the last part of S/N (e.g.  for the
*camera SN: 00-00-40-00-00-2F).
     IP_address   =  // only for open_USB=false. The IP of the

     // Options for the data to save in each CObservation3DRangeScan
     save_3d            = true          // Save the 3D point cloud (default:
     save_range_img     = true          // Save the 2D range image (default:
     save_intensity_img = true          // Save the 2D intensity image
     save_confidence    = true          // Save the estimated confidence 2D
*(default: false)

     enable_img_hist_equal = false      // Enable intensity image histogram
*equalization (default: false)
     enable_median_filter  = true           // Enable median filter in range
*(default: true)
     enable_mediancross_filter = false  // Enable median cross-filter
     enable_conv_gray      = false      // Enable intensity image scale with
*(default: false)
     enable_denoise_anf    = true           // Enable this noise filter

     // Camera calibration parameters: See mrpt::img::TCamera
     //  If not provided, a set of default parameters for a SR4000 camera will
*be loaded.
     resolution = [176 144]
     cx         = 87.99958
     cy         = 68.99957
     fx         = 262.9201
     fy         = 262.9218
     dist       = [-8.258543e-01 6.561022e-01 2.699818e-06 -3.263559e-05 0]

     // For externaly stored images, the format of image files (default=jpg)
     //external_images_format  = jpg
     // (Only when external_images_format=jpg): Optional parameter to set the
*JPEG compression quality:
     //external_images_jpeg_quality = 95    // [1-100]. Default: 95

     pose_x=0.21    // Camera position in the robot (meters)
     pose_yaw=0 // Angles in degrees
#include <mrpt/hwdrivers/CSwissRanger3DCamera.h>

class CSwissRanger3DCamera: public mrpt::hwdrivers::CGenericSensor

    void setOpenFromUSB(bool USB);
    bool getOpenFromUSBMode() const;
    void setOpenIPAddress(const std::string& IP);
    std::string getOpenIPAddress() const;
    void setSave3D(bool save);
    void setSaveRangeImage(bool save);
    void setSaveIntensityImage(bool save);
    void setSaveConfidenceImage(bool save);
    void enableImageHistEqualization(bool enable);
    bool isEnabledImageHistEqualization() const;
    void enableMedianFilter(bool enable);
    bool isEnabledMedianFilter() const;
    void enableMedianCrossFilter(bool enable);
    bool isEnabledMedianCrossFilter() const;
    void enableConvGray(bool enable);
    bool isEnabledConvGray() const;
    void enableDenoiseANF(bool enable);
    bool isEnabledDenoiseANF() const;
    void enablePreviewWindow(bool enable = true);
    bool isEnabledPreviewWindow() const;
    virtual void initialize();
    virtual void doProcess();
    void getNextObservation(mrpt::obs::CObservation3DRangeScan& out_obs, bool& there_is_obs, bool& hardware_error);
    bool open();
    void close();
    bool isOpen() const;
    size_t rows() const;
    size_t cols() const;
    unsigned int getCameraSerialNumber() const;
    double getMaxRange() const;
    void setPathForExternalImages(const std::string& directory);
    bool getMesaLibVersion(std::string& out_version) const;

Inherited Members


    CGenericSensor& operator = (const CGenericSensor&);
    virtual void doProcess() = 0;


void setOpenFromUSB(bool USB)

true: open from USB, false: open from ethernet.

virtual void initialize()

Initializes the 3D camera - should be invoked after calling loadConfig()

This method can or cannot be implemented in the derived class, depending on the need for it.



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

virtual void doProcess()

To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations.

This method will be invoked at a minimum rate of “process_rate” (Hz)

This method is mainly intended for usage within rawlog-grabber or similar programs. For an alternative, see getNextObservation()



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


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

See also:


void getNextObservation(mrpt::obs::CObservation3DRangeScan& out_obs, bool& there_is_obs, bool& hardware_error)

The main data retrieving function, to be called after calling loadConfig() and initialize().



The output retrieved observation (only if there_is_obs=true).


If set to false, there was no new observation.


True on hardware/comms error.

See also:


bool open()

return false on error - Called automatically from initialize(), no need normally for the user to call this.

bool isOpen() const

whether the camera is open and comms work ok.

To be called after initialize()

size_t rows() const

Get the row count in the camera images, loaded automatically upon camera open().

size_t cols() const

Get the col count in the camera images, loaded automatically upon camera open().

unsigned int getCameraSerialNumber() const

Get the camera serial number, loaded automatically upon camera open().

double getMaxRange() const

Returns the maximum camera range, as deduced from its operating frequency.

void setPathForExternalImages(const std::string& directory)

Set the path where to save off-rawlog image files (this class DOES take into account this path).

An empty string (the default value at construction) means to save images embedded in the rawlog, instead of on separate files.



If the directory doesn’t exists and cannot be created.

bool getMesaLibVersion(std::string& out_version) const

Get the version of the MESA library.


false on error