19 #include <mrpt/otherlibs/do_opencv_includes.h> 39 : m_sensorPoseOnRobot(),
40 m_preview_window(false),
41 m_preview_window_decimation(1),
42 m_preview_decim_counter_range(0),
43 m_preview_decim_counter_rgb(0),
45 m_relativePoseIntensityWRTDepth(
47 m_user_device_number(0),
51 m_sensorLabel =
"OPENNI2";
55 m_cameraParamsRGB.ncols = 0;
56 m_cameraParamsRGB.nrows = 0;
58 m_cameraParamsRGB.cx(-1);
59 m_cameraParamsRGB.cy(-1);
60 m_cameraParamsRGB.fx(-1);
61 m_cameraParamsRGB.fy(-1);
63 m_cameraParamsRGB.dist.zeros();
66 m_cameraParamsDepth.ncols = 0;
67 m_cameraParamsDepth.nrows = 0;
69 m_cameraParamsDepth.cx(-1);
70 m_cameraParamsDepth.cy(-1);
71 m_cameraParamsDepth.fx(-1);
72 m_cameraParamsDepth.fy(-1);
74 m_cameraParamsDepth.dist.zeros();
83 close(m_user_device_number);
84 #endif // MRPT_HAS_OPENNI2 97 if (getConnectedDevices() <= 0)
103 if (m_serial_number != 0)
105 openDeviceBySerial(m_serial_number);
106 if (getDeviceIDFromSerialNum(
107 m_serial_number, m_user_device_number) ==
false)
111 "Failed to find sensor_id from serial number(%d).",
116 open(m_user_device_number);
118 if (isOpen(m_user_device_number) ==
false)
122 "Failed to open OpenNI2 device(%d).", m_user_device_number))
128 if (getDepthSensorParam(
129 m_cameraParamsDepth, m_user_device_number) ==
false)
136 if (getColorSensorParam(m_cameraParamsRGB, m_user_device_number) ==
143 catch (std::logic_error& e)
149 #endif // MRPT_HAS_OPENNI2 161 bool thereIs, hwError;
164 mrpt::make_aligned_shared<CObservation3DRangeScan>();
166 assert(getNumDevices() > 0);
167 getNextObservation(*newObs, thereIs, hwError);
179 std::vector<mrpt::utils::CSerializable::Ptr> objs;
180 if (m_grab_image || m_grab_depth || m_grab_3D_points)
181 objs.push_back(newObs);
183 appendObservations(objs);
187 #endif // MRPT_HAS_OPENNI2 200 cout <<
"COpenNI2Sensor::loadConfig_sensorSpecific...\n";
202 m_sensorPoseOnRobot.setFromValues(
203 configSource.
read_float(iniSection,
"pose_x", 0),
204 configSource.
read_float(iniSection,
"pose_y", 0),
205 configSource.
read_float(iniSection,
"pose_z", 0),
211 configSource.
read_bool(iniSection,
"preview_window", m_preview_window);
213 m_width = configSource.
read_int(iniSection,
"width", 0);
214 m_height = configSource.
read_int(iniSection,
"height", 0);
215 m_fps = configSource.
read_float(iniSection,
"fps", 0);
216 std::cout <<
"width " << m_width <<
" height " << m_height <<
" fps " 219 bool hasRightCameraSection =
221 bool hasLeftCameraSection =
223 bool hasLeft2RightPose =
224 configSource.
sectionExists(iniSection +
string(
"_LEFT2RIGHT_POSE"));
232 catch (std::exception& e)
234 std::cout <<
"[COpenNI2Sensor::loadConfig_sensorSpecific] Warning: " 235 "Ignoring error loading calibration parameters:\n" 238 if (hasRightCameraSection)
242 if (hasLeftCameraSection)
246 if (hasLeft2RightPose)
250 m_relativePoseIntensityWRTDepth =
255 m_user_device_number = configSource.
read_int(
256 iniSection,
"device_number", m_user_device_number);
259 configSource.
read_int(iniSection,
"serial_number", m_serial_number);
262 configSource.
read_bool(iniSection,
"grab_image", m_grab_image);
264 configSource.
read_bool(iniSection,
"grab_depth", m_grab_depth);
266 configSource.
read_bool(iniSection,
"grab_3D_points", m_grab_3D_points);
270 iniSection,
"relativePoseIntensityWRTDepth",
"");
271 if (!
s.empty()) m_relativePoseIntensityWRTDepth.fromString(
s);
285 bool& hardware_error)
292 out_obs, there_is_obs, hardware_error, m_user_device_number);
316 if (m_preview_window)
320 if (++m_preview_decim_counter_range > m_preview_window_decimation)
322 m_preview_decim_counter_range = 0;
326 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
328 m_win_range->setPos(5, 5);
335 out_obs.
rangeImage * float(1.0 / this->m_maxRange);
336 m_win_range->showImage(
img);
341 if (++m_preview_decim_counter_rgb > m_preview_window_decimation)
343 m_preview_decim_counter_rgb = 0;
347 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
348 "Preview INTENSITY");
349 m_win_int->setPos(300, 5);
357 if (m_win_range) m_win_range.reset();
358 if (m_win_int) m_win_int.reset();
367 #endif // MRPT_HAS_OPENNI2 virtual void doProcess()
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observati...
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
bool sectionExists(const std::string §ion_name) const
Checks if a given section exists (name is case insensitive)
bool isValidParameter(const mrpt::utils::TCamera ¶m)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double DEG2RAD(const double x)
Degrees to radians.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
mrpt::utils::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
A class for storing images as grayscale or RGB bitmaps.
~COpenNI2Sensor()
Default ctor.
#define THROW_EXCEPTION(msg)
void project3DPointsFromDepthImage(const bool PROJ3D_USE_LUT=true)
This method is equivalent to project3DPointsFromDepthImageInto() storing the projected 3D points (wit...
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, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
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().
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
std::shared_ptr< CObservation3DRangeScan > Ptr
Contains classes for various device interfaces.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
virtual void initialize()
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different par...
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
Structure to hold the parameters of a pinhole stereo camera model.
This class allows loading and storing values and vectors of different types from a configuration text...
mrpt::math::CMatrix rangeImage
If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters) ...
mrpt::utils::TCamera cameraParams
Projection parameters of the depth camera.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This base provides a set of functions for maths stuff.
mrpt::poses::CPose3D relativePoseIntensityWRTDepth
Relative pose of the intensity camera wrt the depth camera (which is the coordinates origin for this ...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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)...
This namespace contains representation of robot actions and observations.
bool hasRangeImage
true means the field rangeImage contains valid data
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
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
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
TCamera leftCamera
Intrinsic and distortion parameters of the left and right cameras.
bool hasIntensityImage
true means the field intensityImage contains valid data
A matrix of dynamic size.
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
mrpt::poses::CPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
Structure to hold the parameters of a pinhole camera model.