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.
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:
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.
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)
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:
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 |
For more details, refer to libfreenect documentation:
MRPT/scripts/51-kinect.rules
in /etc/udev/rules.d/
to allow access to all users.More references to read:
#include <mrpt/hwdrivers/CKinect.h>
Public Types | |
enum | TVideoChannel { VIDEO_CHANNEL_RGB =0 , VIDEO_CHANNEL_IR } |
RGB or IR video channel identifiers. More... | |
typedef float | TDepth2RangeArray[KINECT_RANGES_TABLE_LEN] |
A typedef for an array that converts raw depth to ranges in meters. | |
enum | TSensorState { ssInitializing = 0 , ssWorking , ssError } |
The current state of the sensor. More... | |
typedef std::multimap< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > | TListObservations |
typedef std::pair< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > | TListObsPair |
Public Member Functions | |
CKinect () | |
Default ctor. | |
~CKinect () | |
Default ctor. | |
virtual void | initialize () |
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different parameters with the set*() methods. | |
virtual void | doProcess () |
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations. | |
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(). | |
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. | |
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). | |
virtual const mrpt::hwdrivers::TSensorClassId * | GetRuntimeClass () const =0 |
TSensorState | getState () const |
The current state of the sensor | |
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. | |
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". | |
void | getObservations (TListObservations &lstObjects) |
Returns a list of enqueued objects, emptying it (thread-safe). | |
void | setExternalImageFormat (const std::string &ext) |
Set the extension ("jpg","gif","png",...) that determines the format of images saved externally The default is "jpg". | |
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 |
Sensor parameters (alternative to \a loadConfig ) and manual control | |
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. | |
bool | isOpen () const |
Whether there is a working connection to the sensor. | |
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) | |
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. | |
TVideoChannel | getVideoChannel () const |
Return the current video channel (RGB or IR) | |
void | setDeviceIndexToOpen (int index) |
Set the sensor index to open (if there're several sensors attached to the computer); default=0 -> the first one. | |
int | getDeviceIndexToOpen () const |
void | setTiltAngleDegrees (double angle) |
Change tilt angle. | |
double | getTiltAngleDegrees () |
void | enablePreviewRGB (bool enable=true) |
Default: disabled. | |
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) | |
size_t | getPreviewDecimation () const |
double | getMaxRange () const |
Get the maximum range (meters) that can be read in the observation field "rangeImage". | |
size_t | getRowCount () const |
Get the row count in the camera images, loaded automatically upon camera open(). | |
size_t | getColCount () const |
Get the col count in the camera images, loaded automatically upon camera open(). | |
const mrpt::utils::TCamera & | getCameraParamsIntensity () const |
Get a const reference to the depth camera calibration parameters. | |
void | setCameraParamsIntensity (const mrpt::utils::TCamera &p) |
const mrpt::utils::TCamera & | getCameraParamsDepth () const |
Get a const reference to the depth camera calibration parameters. | |
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. | |
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. | |
const TDepth2RangeArray & | getRawDepth2RangeConversion () const |
void | enableGrabRGB (bool enable=true) |
Enable/disable the grabbing of the RGB channel. | |
bool | isGrabRGBEnabled () const |
void | enableGrabDepth (bool enable=true) |
Enable/disable the grabbing of the depth channel. | |
bool | isGrabDepthEnabled () const |
void | enableGrabAccelerometers (bool enable=true) |
Enable/disable the grabbing of the inertial data. | |
bool | isGrabAccelerometersEnabled () const |
void | enableGrab3DPoints (bool enable=true) |
Enable/disable the grabbing of the 3D point clouds. | |
bool | isGrab3DPointsEnabled () const |
Static Public Member Functions | |
static void | registerClass (const TSensorClassId *pNewClass) |
Register a class into the internal list of "CGenericSensor" descendents. | |
static CGenericSensor * | createSensor (const std::string &className) |
Creates a sensor by a name of the class. | |
static CGenericSensorPtr | createSensorPtr (const std::string &className) |
Just like createSensor, but returning a smart pointer to the newly created sensor object. | |
Protected Member Functions | |
virtual void | loadConfig_sensorSpecific (const mrpt::utils::CConfigFileBase &configSource, const std::string §ion) |
See the class documentation at the top for expected parameters. | |
void | appendObservations (const std::vector< mrpt::utils::CSerializablePtr > &obj) |
This method must be called by derived classes to enqueue a new observation in the list to be returned by getObservations. | |
void | appendObservation (const mrpt::utils::CSerializablePtr &obj) |
Like appendObservations() but for just one observation. | |
Protected Attributes | |
mrpt::poses::CPose3D | m_sensorPoseOnRobot |
bool | m_preview_window |
Show preview window while grabbing. | |
size_t | m_preview_window_decimation |
If preview is enabled, only show 1 out of N images. | |
size_t | m_preview_decim_counter_range |
size_t | m_preview_decim_counter_rgb |
mrpt::gui::CDisplayWindowPtr | m_win_range |
mrpt::gui::CDisplayWindowPtr | m_win_int |
mrpt::utils::TCamera | m_cameraParamsRGB |
Params for the RGB camera. | |
mrpt::utils::TCamera | m_cameraParamsDepth |
Params for the Depth camera. | |
mrpt::poses::CPose3D | m_relativePoseIntensityWRTDepth |
See mrpt::obs::CObservation3DRangeScan for a diagram of this pose. | |
int | m_initial_tilt_angle |
Set Kinect tilt to an initial deegre (it should be take in account in the sensor pose by the user) | |
double | m_maxRange |
Sensor max range (meters) | |
int | m_user_device_number |
Number of device to open (0:first,...) | |
bool | m_grab_image |
bool | m_grab_depth |
bool | m_grab_3D_points |
bool | m_grab_IMU |
Default: all true. | |
TVideoChannel | m_video_channel |
The video channel to open: RGB or IR. | |
size_t | m_grab_decimation_counter |
Used when "m_grab_decimation" is enabled. | |
TSensorState | m_state |
bool | m_verbose |
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%). | |
Common settings to any sensor, loaded in "loadConfig" | |
double | m_process_rate |
See CGenericSensor. | |
size_t | m_max_queue_len |
See CGenericSensor. | |
size_t | m_grab_decimation |
If set to N>=2, only 1 out of N observations will be saved to m_objList. | |
std::string | m_sensorLabel |
See CGenericSensor. | |
Private Member Functions | |
void | calculate_range2meters () |
Compute m_range2meters at construction. | |
Private Attributes | |
std::vector< uint8_t > | m_buf_depth |
std::vector< uint8_t > | m_buf_rgb |
Temporary buffers for image grabbing. | |
TDepth2RangeArray | m_range2meters |
The table raw depth -> range in meters. | |
synch::CCriticalSection | m_csObjList |
The critical section for m_objList. | |
TListObservations | m_objList |
The queue of objects to be returned by getObservations. | |
Static Private Attributes | |
static std::map< std::string, const TSensorClassId * > | m_knownClasses |
Used in registerClass. | |
typedef float mrpt::hwdrivers::CKinect::TDepth2RangeArray[KINECT_RANGES_TABLE_LEN] |
|
inherited |
Definition at line 68 of file CGenericSensor.h.
|
inherited |
Definition at line 69 of file CGenericSensor.h.
|
inherited |
The current state of the sensor.
Enumerator | |
---|---|
ssInitializing | |
ssWorking | |
ssError |
Definition at line 74 of file CGenericSensor.h.
RGB or IR video channel identifiers.
Enumerator | |
---|---|
VIDEO_CHANNEL_RGB | |
VIDEO_CHANNEL_IR |
mrpt::hwdrivers::CKinect::CKinect | ( | ) |
Default ctor.
mrpt::hwdrivers::CKinect::~CKinect | ( | ) |
Default ctor.
|
inlineprotectedinherited |
Like appendObservations() but for just one observation.
Definition at line 146 of file CGenericSensor.h.
|
protectedinherited |
This method must be called by derived classes to enqueue a new observation in the list to be returned by getObservations.
Passed objects must be created in dynamic memory and a smart pointer passed. Example of creation:
If several observations are passed at once in the vector, they'll be considered as a block regarding the grabbing decimation factor.
|
private |
Compute m_range2meters at construction.
void mrpt::hwdrivers::CKinect::close | ( | ) |
Close the conection to the sensor (not need to call it manually unless desired for some reason, since it's called at destructor)
|
staticinherited |
Creates a sensor by a name of the class.
Typically the user may want to create a smart pointer around the returned pointer, whis is made with:
|
inlinestaticinherited |
Just like createSensor, but returning a smart pointer to the newly created sensor object.
Definition at line 179 of file CGenericSensor.h.
|
inline |
|
virtual |
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observations.
This method is mainly intended for usage within rawlog-grabber or similar programs. For an alternative, see getNextObservation()
This | method must throw an exception with a descriptive message if some critical error is found. |
Implements mrpt::hwdrivers::CGenericSensor.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineinherited |
Enable or disable extra debug info dumped to std::cout during sensor operation.
Default: disabled unless the environment variable "MRPT_HWDRIVERS_VERBOSE" is set to "1" during object creation.
Definition at line 92 of file CGenericSensor.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineinherited |
Definition at line 233 of file CGenericSensor.h.
|
inline |
void mrpt::hwdrivers::CKinect::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().
out_obs | The output retrieved observation (only if there_is_obs=true). |
there_is_obs | If set to false, there was no new observation. |
hardware_error | True on hardware/comms error. |
void mrpt::hwdrivers::CKinect::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.
|
inherited |
Returns a list of enqueued objects, emptying it (thread-safe).
The objects must be freed by the invoker.
|
inline |
|
inlineinherited |
Definition at line 84 of file CGenericSensor.h.
|
inline |
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.
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.
|
inline |
|
inline |
|
inline |
|
pure virtualinherited |
|
inlineinherited |
Definition at line 86 of file CGenericSensor.h.
|
inlineinherited |
The current state of the sensor
Definition at line 82 of file CGenericSensor.h.
double mrpt::hwdrivers::CKinect::getTiltAngleDegrees | ( | ) |
|
inline |
Return the current video channel (RGB or IR)
|
virtual |
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different parameters with the set*() methods.
This | method must throw an exception with a descriptive message if some critical error is found. |
Reimplemented from mrpt::hwdrivers::CGenericSensor.
|
inline |
|
inline |
|
inline |
|
inline |
bool mrpt::hwdrivers::CKinect::isOpen | ( | ) | const |
Whether there is a working connection to the sensor.
|
inline |
|
inlineinherited |
Definition at line 93 of file CGenericSensor.h.
|
inherited |
Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensorSpecific".
This | method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value. |
|
protectedvirtual |
See the class documentation at the top for expected parameters.
Implements mrpt::hwdrivers::CGenericSensor.
void mrpt::hwdrivers::CKinect::open | ( | ) |
Try to open the camera (set all the parameters before calling this) - users may also call initialize(), which in turn calls this method.
Raises an exception upon error.
std::exception | A textual description of the error. |
|
staticinherited |
Register a class into the internal list of "CGenericSensor" descendents.
Used internally in the macros DEFINE_GENERIC_SENSOR, etc...
Can be used as "CGenericSensor::registerClass( SENSOR_CLASS_ID(CMySensor) );" if building custom sensors outside mrpt libraries in user code.
|
inline |
|
inline |
|
inline |
|
inlineinherited |
Set the extension ("jpg","gif","png",...) that determines the format of images saved externally The default is "jpg".
Definition at line 225 of file CGenericSensor.h.
|
inlineinherited |
The quality of JPEG compression, when external images is enabled and the format is "jpg".
Definition at line 230 of file CGenericSensor.h.
|
virtual |
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.
std::exception | If the directory doesn't exists and cannot be created. |
Reimplemented from mrpt::hwdrivers::CGenericSensor.
|
inline |
|
inline |
Set the pose of the intensity camera wrt the depth camera.
|
inlineinherited |
Definition at line 87 of file CGenericSensor.h.
void mrpt::hwdrivers::CKinect::setTiltAngleDegrees | ( | double | angle | ) |
Change tilt angle.
void mrpt::hwdrivers::CKinect::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.
Default is RGB channel.
|
private |
|
private |
|
protected |
|
protected |
|
privateinherited |
The critical section for m_objList.
Definition at line 104 of file CGenericSensor.h.
|
protectedinherited |
The extension ("jpg","gif","png",...) that determines the format of images saved externally.
Definition at line 130 of file CGenericSensor.h.
|
protectedinherited |
For JPEG images, the quality (default=95%).
Definition at line 131 of file CGenericSensor.h.
|
protectedinherited |
If set to N>=2, only 1 out of N observations will be saved to m_objList.
Definition at line 117 of file CGenericSensor.h.
|
protectedinherited |
Used when "m_grab_decimation" is enabled.
Definition at line 122 of file CGenericSensor.h.
|
protected |
|
protected |
|
staticprivateinherited |
Used in registerClass.
Definition at line 108 of file CGenericSensor.h.
|
protectedinherited |
See CGenericSensor.
Definition at line 116 of file CGenericSensor.h.
|
protected |
|
privateinherited |
The queue of objects to be returned by getObservations.
Definition at line 105 of file CGenericSensor.h.
|
protectedinherited |
The path where to save off-rawlog images: empty means save images embedded in the rawlog.
Definition at line 129 of file CGenericSensor.h.
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
See CGenericSensor.
Definition at line 115 of file CGenericSensor.h.
|
private |
|
protected |
See mrpt::obs::CObservation3DRangeScan for a diagram of this pose.
|
protectedinherited |
See CGenericSensor.
Definition at line 118 of file CGenericSensor.h.
|
protected |
|
protectedinherited |
Definition at line 124 of file CGenericSensor.h.
|
protected |
|
protectedinherited |
Definition at line 125 of file CGenericSensor.h.
|
protected |
|
protected |
|
protected |
Page generated by Doxygen 1.9.7 for MRPT 1.4.0 SVN: at Tue Jun 13 14:27:49 UTC 2023 |