A class for grabing "range images", intensity images (either RGB or IR) and other information from an Xbox Kinect sensor.
To use Kinect for Windows or ASUS/Primesense RGBD cameras, use the class COpenNI2.
Configuration and usage:
Data is returned as observations of type mrpt::obs::CObservation3DRangeScan (and mrpt::obs::CObservationIMU for accelerometers data). See those classes for documentation on their fields.
As with any other CGenericSensor class, the normal sequence of methods to be called is:
Calibration parameters
For an accurate transformation of depth images to 3D points, you'll have to calibrate your Kinect, and supply the following threee pieces of information (default calibration data will be used otherwise, but they'll be not optimal for all sensors!):
See http://www.mrpt.org/Kinect_calibration for a procedure to calibrate Kinect sensors with an interactive GUI program.
Coordinates convention
The origin of coordinates is the focal point of the depth camera, with the axes oriented as in the diagram shown in mrpt::obs::CObservation3DRangeScan. Notice in that picture that the RGB camera is assumed to have axes as usual in computer vision, which differ from those for the depth camera.
The X,Y,Z axes used to report the data from accelerometers coincide with those of the depth camera (e.g. the camera standing on a table would have an ACC_Z=-9.8m/s2).
Notice however that, for consistency with stereo cameras, when loading the calibration parameters from a configuration file, the left-to-right pose increment is expected as if both RGB & IR cameras had their +Z axes pointing forward, +X to the right, +Y downwards (just like it's the standard in stereo cameras and in computer vision literature). In other words: the pose stored in this class uses a different axes convention for the depth camera than in a stereo camera, so when a pose L2R is loaded from a calibration file it's actually converted like:
L2R(this class convention) = CPose3D(0,0,0,-90deg,0deg,-90deg) (+) L2R(in the config file)
Some general comments
- Depth is grabbed in 10bit depth, and a range N it's converted to meters as: range(m) = 0.1236 * tan(N/2842.5 + 1.1863)
- This sensor can be also used from within rawlog-grabber to grab datasets within a robot with more sensors.
- There is no built-in threading support, so if you use this class manually (not with-in rawlog-grabber), the ideal would be to create a thread and continuously request data from that thread (see mrpt::system::createThread ).
- The intensity channel default to the RGB images, but it can be changed with setVideoChannel() to read the IR camera images (useful for calibrating).
- There is a built-in support for an optional preview of the data on a window, so you don't need to even worry on creating a window to show them.
- This class relies on an embedded version of libfreenect (you do NOT need to install it in your system). Thanks guys for the great job!
Converting to 3D point cloud
You can convert the 3D observation into a 3D point cloud with this piece of code:
Then the point cloud mrpt::maps::CColouredPointsMap can be converted into an OpenGL object for rendering with mrpt::maps::CMetricMap::getAs3DObject() or alternatively with:
gl_points->loadFromPointsMap(&pntsMap);
Raw depth to range conversion
At construction, this class builds an internal array for converting raw 10 or 11bit depths into ranges in meters. Users can read that array or modify it (if you have a better calibration, for example) by calling CKinect::getRawDepth2RangeConversion(). If you replace it, remember to set the first and last entries (index 0 and KINECT_RANGES_TABLE_LEN-1) to zero, to indicate that those are invalid ranges.
R(d) = k3 * tan(d/k2 + k1);
k1 = 1.1863, k2 = 2842.5, k3 = 0.1236
| |
Platform-specific comments
For more details, refer to libfreenect documentation:
- Linux: You'll need root privileges to access Kinect. Or, install
MRPT/scripts/51-kinect.rules in /etc/udev/rules.d/ to allow access to all users.
- Windows:
- MacOS: (write me!)
Format of parameters for loading from a .ini file
PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
-------------------------------------------------------
[supplied_section_name]
sensorLabel = KINECT
preview_window = false
device_number = 0
grab_image = true
grab_depth = true
grab_3D_points = true
grab_IMU = true
pose_x=0
pose_y=0
pose_z=0
pose_yaw=0
pose_pitch=0
pose_roll=0
initial_tilt_angle = 0
[supplied_section_name_LEFT]
rawlog-grabber-ignore = true
resolution = [640 488]
cx = 314.649173
cy = 240.160459
fx = 572.882768
fy = 542.739980
dist = [-4.747169e-03 -4.357976e-03 0.000000e+00 0.000000e+00 0.000000e+00]
[supplied_section_name_RIGHT]
rawlog-grabber-ignore = true
resolution = [640 480]
cx = 322.515987
cy = 259.055966
fx = 521.179233
fy = 493.033034
dist = [5.858325e-02 3.856792e-02 0.000000e+00 0.000000e+00 0.000000e+00]
[supplied_section_name_LEFT2RIGHT_POSE]
rawlog-grabber-ignore = true
pose_quaternion = [0.025575 -0.000609 -0.001462 0.999987 0.002038 0.004335 -0.001693]
More references to read:
Definition at line 207 of file CKinect.h.
|
| | CKinect () |
| | Default ctor. More...
|
| |
| | ~CKinect () |
| | Default ctor. More...
|
| |
| virtual void | initialize () |
| | Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different parameters with the set*() methods. More...
|
| |
| virtual void | doProcess () |
| | To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations. More...
|
| |
| 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(). More...
|
| |
| void | getNextObservation (mrpt::obs::CObservation3DRangeScan &out_obs, mrpt::obs::CObservationIMU &out_obs_imu, bool &there_is_obs, bool &hardware_error) |
| | This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
|
| |
| virtual void | setPathForExternalImages (const std::string &directory) |
| | Set the path where to save off-rawlog image files (this class DOES take into account this path). More...
|
| |
| virtual const mrpt::hwdrivers::TSensorClassId * | GetRuntimeClass () const =0 |
| |
| TSensorState | getState () const |
| | The current state of the sensor. More...
|
| |
| double | getProcessRate () const |
| |
| std::string | getSensorLabel () const |
| |
| void | setSensorLabel (const std::string &sensorLabel) |
| |
| void | enableVerbose (bool enabled=true) |
| | Enable or disable extra debug info dumped to std::cout during sensor operation. More...
|
| |
| bool | isVerboseEnabled () const |
| |
| void | loadConfig (const mrpt::utils::CConfigFileBase &configSource, const std::string §ion) |
| | Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensorSpecific" - Exceptions
-
| This | method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value. |
More...
|
| |
| void | getObservations (TListObservations &lstObjects) |
| | Returns a list of enqueued objects, emptying it (thread-safe). More...
|
| |
| void | setExternalImageFormat (const std::string &ext) |
| | Set the extension ("jpg","gif","png",...) that determines the format of images saved externally The default is "jpg". More...
|
| |
| void | setExternalImageJPEGQuality (const unsigned int quality) |
| | The quality of JPEG compression, when external images is enabled and the format is "jpg". More...
|
| |
| unsigned int | getExternalImageJPEGQuality () const |
| |
|
| void | open () |
| | Try to open the camera (set all the parameters before calling this) - users may also call initialize(), which in turn calls this method. More...
|
| |
| bool | isOpen () const |
| | Whether there is a working connection to the sensor. More...
|
| |
| void | close () |
| | Close the conection to the sensor (not need to call it manually unless desired for some reason, since it's called at destructor) More...
|
| |
| void | setVideoChannel (const TVideoChannel vch) |
| | Changes the video channel to open (RGB or IR) - you can call this method before start grabbing or in the middle of streaming and the video source will change on the fly. More...
|
| |
| TVideoChannel | getVideoChannel () const |
| | Return the current video channel (RGB or IR) More...
|
| |
| void | setDeviceIndexToOpen (int index) |
| | Set the sensor index to open (if there're several sensors attached to the computer); default=0 -> the first one. More...
|
| |
| int | getDeviceIndexToOpen () const |
| |
| void | setTiltAngleDegrees (double angle) |
| | Change tilt angle. More...
|
| |
| double | getTiltAngleDegrees () |
| |
| void | enablePreviewRGB (bool enable=true) |
| | Default: disabled. More...
|
| |
| void | disablePreviewRGB () |
| |
| bool | isPreviewRGBEnabled () const |
| |
| void | setPreviewDecimation (size_t decimation_factor) |
| | If preview is enabled, show only one image out of N (default: 1=show all) More...
|
| |
| size_t | getPreviewDecimation () const |
| |
| double | getMaxRange () const |
| | Get the maximum range (meters) that can be read in the observation field "rangeImage". More...
|
| |
| size_t | getRowCount () const |
| | Get the row count in the camera images, loaded automatically upon camera open(). More...
|
| |
| size_t | getColCount () const |
| | Get the col count in the camera images, loaded automatically upon camera open(). More...
|
| |
| const mrpt::utils::TCamera & | getCameraParamsIntensity () const |
| | Get a const reference to the depth camera calibration parameters. More...
|
| |
| void | setCameraParamsIntensity (const mrpt::utils::TCamera &p) |
| |
| const mrpt::utils::TCamera & | getCameraParamsDepth () const |
| | Get a const reference to the depth camera calibration parameters. More...
|
| |
| void | setCameraParamsDepth (const mrpt::utils::TCamera &p) |
| |
| void | setRelativePoseIntensityWrtDepth (const mrpt::poses::CPose3D &p) |
| | Set the pose of the intensity camera wrt the depth camera. More...
|
| |
| const mrpt::poses::CPose3D & | getRelativePoseIntensityWrtDepth () const |
| |
| TDepth2RangeArray & | getRawDepth2RangeConversion () |
| | Get a reference to the array that convert raw depth values (10 or 11 bit) into ranges in meters, so it can be read or replaced by the user. More...
|
| |
| const TDepth2RangeArray & | getRawDepth2RangeConversion () const |
| |
| void | enableGrabRGB (bool enable=true) |
| | Enable/disable the grabbing of the RGB channel. More...
|
| |
| bool | isGrabRGBEnabled () const |
| |
| void | enableGrabDepth (bool enable=true) |
| | Enable/disable the grabbing of the depth channel. More...
|
| |
| bool | isGrabDepthEnabled () const |
| |
| void | enableGrabAccelerometers (bool enable=true) |
| | Enable/disable the grabbing of the inertial data. More...
|
| |
| bool | isGrabAccelerometersEnabled () const |
| |
| void | enableGrab3DPoints (bool enable=true) |
| | Enable/disable the grabbing of the 3D point clouds. More...
|
| |
| bool | isGrab3DPointsEnabled () const |
| |