12 #include <mrpt/config.h> 39 openni::Device& m_device;
40 std::string m_strName;
42 openni::VideoStream m_stream;
43 openni::PixelFormat m_format;
51 const std::string& getName()
const {
return m_strName; }
53 bool isMirrorSupported()
const;
54 bool setMirror(
bool flag);
55 void setCloseRange(
int& value);
56 virtual bool open(
int w,
int h,
int fps);
58 virtual void destroy();
59 virtual bool getFrame(
61 bool& there_is_obs,
bool& hardware_error);
63 int getFrameWidth()
const 65 return m_stream.getVideoMode().getResolutionX();
67 int getFrameHeight()
const 69 return m_stream.getVideoMode().getResolutionY();
71 double getHFov()
const {
return m_stream.getHorizontalFieldOfView(); }
74 return getFrameWidth() / (2.0 * tan(getHFov() / 2.0));
76 double getVFov()
const {
return m_stream.getVerticalFieldOfView(); }
79 return getFrameHeight() / (2.0 * tan(getVFov() / 2.0));
81 double getCx()
const {
return (getFrameWidth() - 1) * 0.5; }
82 double getCy()
const {
return (getFrameHeight() - 1) * 0.5; }
83 void disableAutoExposure()
85 m_stream.getCameraSettings()->setAutoExposureEnabled(
false);
87 void enableAutoExposure()
89 m_stream.getCameraSettings()->setAutoExposureEnabled(
true);
94 param.
ncols = getFrameWidth();
95 param.
nrows = getFrameHeight();
104 openni::PixelFormat
format, std::ostream& log,
bool verbose);
106 openni::DeviceInfo m_info;
107 openni::Device m_device;
110 std::stringstream m_log;
113 bool synchMirrorMode();
130 inline void setPixel(
133 rgb.
setPixel(x, y, (src.r << 16) + (src.g << 8) + src.b);
135 inline void setPixel(
139 depth_mm(y, x) = src;
142 template <
class NI_PIXEL,
class MRPT_DATA>
143 void copyRow(
const char* src, MRPT_DATA& rgb,
int w,
const int y)
145 const auto* s = (
const NI_PIXEL*)src;
146 for (
int xc = 0; xc < w; ++xc, ++s)
153 setPixel(*s, rgb, x, y);
157 template <
class NI_PIXEL,
class MRPT_DATA>
158 void copyFrame(openni::VideoFrameRef& frame, MRPT_DATA& dst)
160 const char*
data = (
const char*)frame.getData();
161 const int stride = frame.getStrideInBytes();
162 const int width = frame.getWidth();
163 const int height = frame.getHeight();
164 resize(dst, width, height);
165 for (
int y = 0; y < height; ++y,
data += stride)
167 copyRow<NI_PIXEL, MRPT_DATA>(
data, dst, width, y);
173 const openni::DeviceInfo& info, openni::PixelFormat rgb,
174 openni::PixelFormat depth,
bool m_verbose);
177 const openni::DeviceInfo& getInfo()
const {
return m_info; }
178 std::string getLog()
const {
return m_log.str(); }
184 bool isMirrorMode()
const {
return m_mirror; }
185 void setMirrorMode(
bool mode) { m_mirror = mode; }
186 bool hasColor()
const 193 bool hasDepth()
const 203 bool open(
int w,
int h,
int fps);
207 bool& there_is_obs,
bool& hardware_error);
210 bool& there_is_obs,
bool& hardware_error);
213 bool& hardware_error);
221 if (!m_streams[streamType] || m_streams[streamType]->isValid() ==
false)
225 m_streams[streamType]->getCameraParam(param);
229 bool getSerialNumber(
unsigned int& sn);
232 const openni::DeviceInfo& info, openni::PixelFormat rgb,
233 openni::PixelFormat depth,
bool verbose);
235 openni::Device& getDevicePtr() {
return m_device; }
238 bool getSerialNumber(std::string& sn);
240 #endif // MRPT_HAS_OPENNI2
void resize(size_t row, size_t col)
double fx() const
Get the value of the focal length x-value (in pixels).
std::string std::string format(std::string_view fmt, ARGS &&... args)
void getNextFrameRGB(mrpt::img::CImage &rgb_img, mrpt::system::TTimeStamp ×tamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
double fy() const
Get the value of the focal length y-value (in pixels).
A range or depth 3D scan measurement, as from a time-of-flight range camera or a structured-light dep...
void getNextFrameRGBD(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
Contains classes for various device interfaces.
mrpt::io::CStream CStream
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
bool start()
Open all sensor streams (normally called automatically at constructor, no need to call it manually)...
double cy() const
Get the value of the principal point y-coordinate (in pixels).
void getNextFrameD(mrpt::math::CMatrix_u16 &depth_img_mm, mrpt::system::TTimeStamp ×tamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
void resize(std::size_t width, std::size_t height, TImageChannels nChannels, PixelDepth depth=PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
bool isOpen(const unsigned sensor_id) const
Whether there is a working connection to the sensor.
mrpt::img::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
void close(unsigned sensor_id=0)
Close the connection to the sensor (no need to call it manually unless desired for some reason...
Parameters for the Brown-Conrady camera lens distortion model.
double cx() const
Get the value of the principal point x-coordinate (in pixels).
void setPixel(int x, int y, size_t color) override
Changes the value of the pixel (x,y).
void rangeImage_setSize(const int HEIGHT, const int WIDTH)
Similar to calling "rangeImage.setSize(H,W)" but this method provides memory pooling to speed-up the ...
void open(unsigned sensor_id=0)
Try to open the camera (all the parameters [resolution,fps,...] must be set before calling this) - us...
uint32_t ncols
Camera resolution.
std::shared_ptr< CDevice > Ptr
A class for storing images as grayscale or RGB bitmaps.
static struct FontData data