20 #include <mrpt/otherlibs/do_opencv_includes.h> 40 : m_sensorPoseOnRobot(),
42 m_relativePoseIntensityWRTDepth(
47 m_sensorLabel =
"OPENNI2";
51 m_cameraParamsRGB.ncols = 0;
52 m_cameraParamsRGB.nrows = 0;
54 m_cameraParamsRGB.cx(-1);
55 m_cameraParamsRGB.cy(-1);
56 m_cameraParamsRGB.fx(-1);
57 m_cameraParamsRGB.fy(-1);
59 m_cameraParamsRGB.dist.fill(0);
62 m_cameraParamsDepth.ncols = 0;
63 m_cameraParamsDepth.nrows = 0;
65 m_cameraParamsDepth.cx(-1);
66 m_cameraParamsDepth.cy(-1);
67 m_cameraParamsDepth.fx(-1);
68 m_cameraParamsDepth.fy(-1);
70 m_cameraParamsDepth.dist.fill(0);
79 close(m_user_device_number);
80 #endif // MRPT_HAS_OPENNI2 93 if (getConnectedDevices() <= 0)
99 if (m_serial_number != 0)
101 openDeviceBySerial(m_serial_number);
102 if (getDeviceIDFromSerialNum(
103 m_serial_number, m_user_device_number) ==
false)
106 "Failed to find sensor_id from serial number(%d).",
111 open(m_user_device_number);
113 if (isOpen(m_user_device_number) ==
false)
116 "Failed to open OpenNI2 device(%d).", m_user_device_number));
122 if (getDepthSensorParam(
123 m_cameraParamsDepth, m_user_device_number) ==
false)
130 if (getColorSensorParam(m_cameraParamsRGB, m_user_device_number) ==
137 catch (std::logic_error& e)
143 #endif // MRPT_HAS_OPENNI2 155 bool thereIs, hwError;
158 std::make_shared<CObservation3DRangeScan>();
160 assert(getNumDevices() > 0);
161 getNextObservation(*newObs, thereIs, hwError);
173 std::vector<mrpt::serialization::CSerializable::Ptr> objs;
174 if (m_grab_image || m_grab_depth || m_grab_3D_points)
175 objs.push_back(newObs);
177 appendObservations(objs);
181 #endif // MRPT_HAS_OPENNI2 194 cout <<
"COpenNI2Sensor::loadConfig_sensorSpecific...\n";
196 m_sensorPoseOnRobot.setFromValues(
197 configSource.
read_float(iniSection,
"pose_x", 0),
198 configSource.
read_float(iniSection,
"pose_y", 0),
199 configSource.
read_float(iniSection,
"pose_z", 0),
205 configSource.
read_bool(iniSection,
"preview_window", m_preview_window);
207 m_width = configSource.
read_int(iniSection,
"width", 0);
208 m_height = configSource.
read_int(iniSection,
"height", 0);
209 m_fps = configSource.
read_float(iniSection,
"fps", 0);
210 std::cout <<
"width " << m_width <<
" height " << m_height <<
" fps " 213 bool hasRightCameraSection =
215 bool hasLeftCameraSection =
217 bool hasLeft2RightPose =
218 configSource.
sectionExists(iniSection +
string(
"_LEFT2RIGHT_POSE"));
226 catch (
const std::exception& e)
228 std::cout <<
"[COpenNI2Sensor::loadConfig_sensorSpecific] Warning: " 229 "Ignoring error loading calibration parameters:\n" 232 if (hasRightCameraSection)
236 if (hasLeftCameraSection)
240 if (hasLeft2RightPose)
244 m_relativePoseIntensityWRTDepth =
250 m_user_device_number = configSource.
read_int(
251 iniSection,
"device_number", m_user_device_number);
254 configSource.
read_int(iniSection,
"serial_number", m_serial_number);
257 configSource.
read_bool(iniSection,
"grab_image", m_grab_image);
259 configSource.
read_bool(iniSection,
"grab_depth", m_grab_depth);
261 configSource.
read_bool(iniSection,
"grab_3D_points", m_grab_3D_points);
265 iniSection,
"relativePoseIntensityWRTDepth",
"");
266 if (!
s.empty()) m_relativePoseIntensityWRTDepth.fromString(
s);
280 bool& hardware_error)
287 out_obs, there_is_obs, hardware_error, m_user_device_number);
311 if (m_preview_window)
315 if (++m_preview_decim_counter_range > m_preview_window_decimation)
317 m_preview_decim_counter_range = 0;
322 m_win_range->setPos(5, 5);
329 r *= float(1.0 / this->m_maxRange);
330 m_win_range->showImage(
img);
335 if (++m_preview_decim_counter_rgb > m_preview_window_decimation)
337 m_preview_decim_counter_rgb = 0;
342 m_win_int->setPos(300, 5);
350 if (m_win_range) m_win_range.reset();
351 if (m_win_int) m_win_int.reset();
360 #endif // MRPT_HAS_OPENNI2 mrpt::img::TCamera cameraParams
Projection parameters of the depth camera.
void resize(size_t row, size_t col)
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION(msg)
bool isValidParameter(const mrpt::img::TCamera ¶m)
double DEG2RAD(const double x)
Degrees to radians.
void project3DPointsFromDepthImage(const bool PROJ3D_USE_LUT=true)
This method is equivalent to project3DPointsFromDepthImageInto() storing the projected 3D points (wit...
mrpt::math::CMatrixF rangeImage
If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters) ...
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.
Contains classes for various device interfaces.
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...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from a configuration text...
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 ...
mrpt::img::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
This namespace contains representation of robot actions and observations.
bool hasRangeImage
true means the field rangeImage contains valid data
Structure to hold the parameters of a pinhole camera model.
bool sectionExists(const std::string §ion_name) const
Checks if a given section exists (name is case insensitive)
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().
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
void setPathForExternalImages(const std::string &directory) override
Set the path where to save off-rawlog image files (this class DOES take into account this path)...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
GLdouble GLdouble GLdouble r
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
void doProcess() override
To be called at a high rate (>XX Hz), this method populates the internal buffer of received observati...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool hasIntensityImage
true means the field intensityImage contains valid data
TCamera leftCamera
Intrinsic and distortion parameters of the left and right cameras.
mrpt::math::TPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
~COpenNI2Sensor() override
Default ctor.
void initialize() override
Initializes the 3D camera - should be invoked after calling loadConfig() or setting the different par...
uint32_t twist(const uint32_t m, const uint32_t s0, const uint32_t s1)
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string §ion) override
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see config::CConfigFileBase and derived classes)
static CDisplayWindow::Ptr Create(const std::string &windowCaption, unsigned int initWidth=400, unsigned int initHeight=400)
Class factory returning a smart pointer.
mrpt::img::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
Structure to hold the parameters of a pinhole stereo camera model.
A class for storing images as grayscale or RGB bitmaps.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.