19 #include <mrpt/otherlibs/do_opencv_includes.h>
40 m_sensorPoseOnRobot(),
41 m_preview_window(false),
42 m_preview_window_decimation(1),
43 m_preview_decim_counter_range(0),
44 m_preview_decim_counter_rgb(0),
47 m_user_device_number(0),
52 m_sensorLabel =
"OPENNI2";
56 m_cameraParamsRGB.ncols = 0;
57 m_cameraParamsRGB.nrows = 0;
59 m_cameraParamsRGB.cx(-1);
60 m_cameraParamsRGB.cy(-1);
61 m_cameraParamsRGB.fx(-1);
62 m_cameraParamsRGB.fy(-1);
64 m_cameraParamsRGB.dist.zeros();
67 m_cameraParamsDepth.ncols = 0;
68 m_cameraParamsDepth.nrows = 0;
70 m_cameraParamsDepth.cx(-1);
71 m_cameraParamsDepth.cy(-1);
72 m_cameraParamsDepth.fx(-1);
73 m_cameraParamsDepth.fy(-1);
75 m_cameraParamsDepth.dist.zeros();
84 close(m_user_device_number);
95 if(getConnectedDevices() <= 0){
99 if(m_serial_number != 0)
101 openDeviceBySerial(m_serial_number);
102 if(getDeviceIDFromSerialNum(m_serial_number, m_user_device_number) ==
false){
107 open(m_user_device_number);
109 if(isOpen(m_user_device_number) ==
false){
114 if(getDepthSensorParam(m_cameraParamsDepth, m_user_device_number) ==
false){
119 if(getColorSensorParam(m_cameraParamsRGB, m_user_device_number) ==
false){
123 }
catch(std::logic_error& e){
139 bool thereIs, hwError;
141 CObservation3DRangeScanPtr newObs = CObservation3DRangeScan::Create();
143 assert(getNumDevices() > 0);
144 getNextObservation( *newObs, thereIs, hwError );
156 std::vector<mrpt::utils::CSerializablePtr> objs;
157 if (m_grab_image || m_grab_depth || m_grab_3D_points) objs.push_back(newObs);
159 appendObservations( objs );
173 cout <<
"COpenNI2Sensor::loadConfig_sensorSpecific...\n";
175 m_sensorPoseOnRobot.setFromValues(
176 configSource.
read_float(iniSection,
"pose_x",0),
177 configSource.
read_float(iniSection,
"pose_y",0),
178 configSource.
read_float(iniSection,
"pose_z",0),
184 m_preview_window = configSource.
read_bool(iniSection,
"preview_window",m_preview_window);
186 m_width = configSource.
read_int(iniSection,
"width",0);
187 m_height = configSource.
read_int(iniSection,
"height",0);
188 m_fps = configSource.
read_float(iniSection,
"fps",0);
189 std::cout <<
"width " << m_width <<
" height " << m_height <<
" fps " << m_fps << endl;
191 bool hasRightCameraSection = configSource.
sectionExists(iniSection +
string(
"_RIGHT"));
192 bool hasLeftCameraSection = configSource.
sectionExists(iniSection +
string(
"_LEFT"));
193 bool hasLeft2RightPose = configSource.
sectionExists(iniSection +
string(
"_LEFT2RIGHT_POSE"));
199 }
catch (std::exception &e) {
200 std::cout <<
"[COpenNI2Sensor::loadConfig_sensorSpecific] Warning: Ignoring error loading calibration parameters:\n" << e.what();
202 if(hasRightCameraSection){
205 if(hasLeftCameraSection){
208 if(hasLeft2RightPose){
214 m_user_device_number = configSource.
read_int(iniSection,
"device_number", m_user_device_number);
216 m_serial_number = configSource.
read_int(iniSection,
"serial_number", m_serial_number);
218 m_grab_image = configSource.
read_bool(iniSection,
"grab_image",m_grab_image);
219 m_grab_depth = configSource.
read_bool(iniSection,
"grab_depth",m_grab_depth);
220 m_grab_3D_points = configSource.
read_bool(iniSection,
"grab_3D_points",m_grab_3D_points);
225 m_relativePoseIntensityWRTDepth.fromString(
s);
241 bool &hardware_error)
247 getNextFrameRGBD(out_obs, there_is_obs, hardware_error, m_user_device_number );
273 if (m_preview_window)
277 if (++m_preview_decim_counter_range>m_preview_window_decimation)
279 m_preview_decim_counter_range=0;
286 m_win_range->showImage(
img);
291 if (++m_preview_decim_counter_rgb>m_preview_window_decimation)
293 m_preview_decim_counter_rgb=0;
301 if (m_win_range) m_win_range.clear();
302 if (m_win_int) m_win_int.clear();
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
bool isValidParameter(const mrpt::utils::TCamera ¶m)
uint32_t twist(const uint32_t m, const uint32_t s0, const uint32_t s1)
static CDisplayWindowPtr Create()
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
virtual void initialize()
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different par...
virtual void doProcess()
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observati...
~COpenNI2Sensor()
Default ctor.
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 void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string §ion)
Loads specific configuration for the device from a given source of configuration parameters,...
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().
A matrix of dynamic size.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
mrpt::utils::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
mrpt::utils::TCamera cameraParams
Projection parameters of the depth camera.
bool hasIntensityImage
true means the field intensityImage contains valid data
mrpt::poses::CPose3D relativePoseIntensityWRTDepth
Relative pose of the intensity camera wrt the depth camera (which is the coordinates origin for this ...
void project3DPointsFromDepthImage(const bool PROJ3D_USE_LUT=true)
This method is equivalent to project3DPointsFromDepthImageInto() storing the projected 3D points (wit...
bool hasRangeImage
true means the field rangeImage contains valid data
mrpt::math::CMatrix rangeImage
If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters)
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage".
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This class allows loading and storing values and vectors of different types from a configuration text...
bool sectionExists(const std::string §ion_name) const
Checks if a given section exists (name is case insensitive)
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
A class for storing images as grayscale or RGB bitmaps.
Structure to hold the parameters of a pinhole camera model.
Structure to hold the parameters of a pinhole stereo camera model.
mrpt::poses::CPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
TCamera rightCamera
Intrinsic and distortion parameters of the left and right cameras.
void loadFromConfigFile(const std::string §ion, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the same format that used in saveToConfigFile().
GLdouble GLdouble GLdouble r
GLsizei const GLchar ** string
#define THROW_EXCEPTION(msg)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Contains classes for various device interfaces.
This base provides a set of functions for maths stuff.
This namespace contains representation of robot actions and observations.
This namespace provides multitask, synchronization utilities.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
double DEG2RAD(const double x)
Degrees to radians.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.