20 #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),
46 m_relativePoseIntensityWRTDepth(
48 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.fill(0);
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.fill(0);
84 close(m_user_device_number);
98 if (getConnectedDevices() <= 0)
104 if (m_serial_number != 0)
106 openDeviceBySerial(m_serial_number);
107 if (getDeviceIDFromSerialNum(
108 m_serial_number, m_user_device_number) ==
false)
112 "Failed to find sensor_id from serial number(%d).",
117 open(m_user_device_number);
119 if (isOpen(m_user_device_number) ==
false)
123 "Failed to open OpenNI2 device(%d).", m_user_device_number))
129 if (getDepthSensorParam(
130 m_cameraParamsDepth, m_user_device_number) ==
false)
137 if (getColorSensorParam(m_cameraParamsRGB, m_user_device_number) ==
144 catch (std::logic_error& e)
162 bool thereIs, hwError;
165 mrpt::make_aligned_shared<CObservation3DRangeScan>();
167 assert(getNumDevices() > 0);
168 getNextObservation(*newObs, thereIs, hwError);
180 std::vector<mrpt::serialization::CSerializable::Ptr> objs;
181 if (m_grab_image || m_grab_depth || m_grab_3D_points)
182 objs.push_back(newObs);
184 appendObservations(objs);
201 cout <<
"COpenNI2Sensor::loadConfig_sensorSpecific...\n";
203 m_sensorPoseOnRobot.setFromValues(
204 configSource.
read_float(iniSection,
"pose_x", 0),
205 configSource.
read_float(iniSection,
"pose_y", 0),
206 configSource.
read_float(iniSection,
"pose_z", 0),
212 configSource.
read_bool(iniSection,
"preview_window", m_preview_window);
214 m_width = configSource.
read_int(iniSection,
"width", 0);
215 m_height = configSource.
read_int(iniSection,
"height", 0);
216 m_fps = configSource.
read_float(iniSection,
"fps", 0);
217 std::cout <<
"width " << m_width <<
" height " << m_height <<
" fps "
220 bool hasRightCameraSection =
222 bool hasLeftCameraSection =
224 bool hasLeft2RightPose =
225 configSource.
sectionExists(iniSection +
string(
"_LEFT2RIGHT_POSE"));
233 catch (std::exception& e)
235 std::cout <<
"[COpenNI2Sensor::loadConfig_sensorSpecific] Warning: "
236 "Ignoring error loading calibration parameters:\n"
239 if (hasRightCameraSection)
243 if (hasLeftCameraSection)
247 if (hasLeft2RightPose)
251 m_relativePoseIntensityWRTDepth =
257 m_user_device_number = configSource.
read_int(
258 iniSection,
"device_number", m_user_device_number);
261 configSource.
read_int(iniSection,
"serial_number", m_serial_number);
264 configSource.
read_bool(iniSection,
"grab_image", m_grab_image);
266 configSource.
read_bool(iniSection,
"grab_depth", m_grab_depth);
268 configSource.
read_bool(iniSection,
"grab_3D_points", m_grab_3D_points);
272 iniSection,
"relativePoseIntensityWRTDepth",
"");
273 if (!
s.empty()) m_relativePoseIntensityWRTDepth.fromString(
s);
287 bool& hardware_error)
294 out_obs, there_is_obs, hardware_error, m_user_device_number);
318 if (m_preview_window)
322 if (++m_preview_decim_counter_range > m_preview_window_decimation)
324 m_preview_decim_counter_range = 0;
328 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
330 m_win_range->setPos(5, 5);
337 out_obs.
rangeImage * float(1.0 / this->m_maxRange);
338 m_win_range->showImage(
img);
343 if (++m_preview_decim_counter_rgb > m_preview_window_decimation)
345 m_preview_decim_counter_rgb = 0;
349 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
350 "Preview INTENSITY");
351 m_win_int->setPos(300, 5);
359 if (m_win_range) m_win_range.reset();
360 if (m_win_int) m_win_int.reset();
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
bool isValidParameter(const mrpt::img::TCamera ¶m)
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 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::config::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 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::math::TPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
void loadFromConfigFile(const std::string §ion, const mrpt::config::CConfigFileBase &cfg)
Load all the params from a config source, in the same format that used in saveToConfigFile().
TCamera leftCamera
Intrinsic and distortion parameters of the left and right cameras.
A matrix of dynamic size.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
mrpt::img::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 ...
mrpt::img::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage".
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)
std::shared_ptr< CObservation3DRangeScan > Ptr
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
mrpt::img::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
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).
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
#define THROW_EXCEPTION(msg)
GLdouble GLdouble GLdouble r
GLsizei const GLchar ** string
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
double DEG2RAD(const double x)
Degrees to radians.