32 openni::Device& m_device;
33 std::string m_strName;
35 openni::VideoStream m_stream;
36 openni::PixelFormat m_format;
39 CStream(openni::Device& device,
openni::SensorType type, openni::PixelFormat
format, std::ostream& log,
bool verbose);
41 const std::string& getName()
const{
return m_strName; }
43 bool isMirrorSupported()
const;
44 bool setMirror(
bool flag);
45 void setCloseRange(
int&
value);
46 virtual bool open(
int w,
int h,
int fps);
48 virtual void destroy();
49 virtual bool getFrame(openni::VideoFrameRef& frame, uint64_t ×tamp,
bool &there_is_obs,
bool &hardware_error);
51 int getFrameWidth()
const{
return m_stream.getVideoMode().getResolutionX(); }
52 int getFrameHeight()
const{
return m_stream.getVideoMode().getResolutionY(); }
53 double getHFov()
const{
return m_stream.getHorizontalFieldOfView(); }
54 double getFx()
const{
return getFrameWidth() / (2.0 * tan(getHFov() / 2.0)); }
55 double getVFov()
const{
return m_stream.getVerticalFieldOfView(); }
56 double getFy()
const{
return getFrameHeight() / (2.0 * tan(getVFov() / 2.0)); }
57 double getCx()
const{
return (getFrameWidth() - 1) * 0.5; }
58 double getCy()
const{
return (getFrameHeight() - 1) * 0.5; }
60 void disableAutoExposure() {m_stream.getCameraSettings()->setAutoExposureEnabled(
false); }
61 void enableAutoExposure() {m_stream.getCameraSettings()->setAutoExposureEnabled(
true); }
64 param.
ncols = getFrameWidth();
65 param.
nrows = getFrameHeight();
72 static Ptr create(openni::Device& device,
openni::SensorType type, openni::PixelFormat format, std::ostream& log,
bool verbose);
74 openni::DeviceInfo m_info;
75 openni::Device m_device;
78 std::stringstream m_log;
81 bool synchMirrorMode();
91 inline void setPixel(
const openni::RGB888Pixel& src,
mrpt::utils::CImage& rgb ,
int x,
int y){ rgb.
setPixel(x, y, (src.r << 16) + (src.g << 8) + src.b); }
92 inline void setPixel(
const openni::DepthPixel& src ,
mrpt::math::CMatrix& depth,
int x,
int y){
93 static const double rate = 1.0 / 1000;
94 depth(y, x) = src * rate;
97 template <
class NI_PIXEL,
class MRPT_DATA>
98 void copyRow(
const char* src, MRPT_DATA& rgb,
int w,
const int y){
99 const NI_PIXEL* s = (
const NI_PIXEL*)src;
100 for (
int xc = 0; xc < w; ++xc, ++s){
105 setPixel(*s, rgb, x, y);
109 template <
class NI_PIXEL,
class MRPT_DATA>
110 void copyFrame(openni::VideoFrameRef& frame, MRPT_DATA& dst){
111 const char*
data = (
const char*)frame.getData();
112 const int stride = frame.getStrideInBytes();
113 const int width = frame.getWidth();
114 const int height = frame.getHeight();
115 resize(dst, width, height);
116 for (
int y = 0; y < height; ++y, data+=stride){
117 copyRow<NI_PIXEL, MRPT_DATA>(
data, dst, width, y);
122 CDevice(
const openni::DeviceInfo& info, openni::PixelFormat rgb, openni::PixelFormat depth,
bool m_verbose);
125 const openni::DeviceInfo& getInfo()
const{
return m_info; }
126 std::string getLog()
const{
return m_log.str(); }
128 void clearLog(){ m_log.str(
""); m_log.clear(); }
129 bool isMirrorMode()
const{
return m_mirror; }
130 void setMirrorMode(
bool mode){ m_mirror = mode; }
136 bool open(
int w,
int h,
int fps);
146 if(!m_streams[streamType] || m_streams[streamType]->isValid() ==
false){
return false; }
147 m_streams[streamType]->getCameraParam(param);
151 bool getSerialNumber(
unsigned int& sn);
153 static Ptr create(
const openni::DeviceInfo& info, openni::PixelFormat rgb, openni::PixelFormat depth,
bool verbose);
155 openni::Device & getDevicePtr(){
return m_device; }
158 bool getSerialNumber(std::string& sn);
160 #endif // MRPT_HAS_OPENNI2 void open(unsigned sensor_id=0)
Try to open the camera (all the parameters [resolution,fps,...] must be set before calling this) - us...
bool isOpen(const unsigned sensor_id) const
Whether there is a working connection to the sensor.
bool start()
Open all sensor streams (normally called automatically at constructor, no need to call it manually)...
stlplus::smart_ptr< CDevice > Ptr
A class for storing images as grayscale or RGB bitmaps.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void resize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
double cy() const
Get the value of the principal point y-coordinate (in pixels).
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.
T value(details::expression_node< T > *n)
double fx() const
Get the value of the focal length x-value (in pixels).
double fy() const
Get the value of the focal length y-value (in pixels).
void getNextFrameD(mrpt::math::CMatrix &depth_img, uint64_t ×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 cx() const
Get the value of the principal point x-coordinate (in pixels).
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 ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void close(unsigned sensor_id=0)
Close the connection to the sensor (no need to call it manually unless desired for some reason...
class HWDRIVERS_IMPEXP CDevice
The list of available devices.
uint32_t nrows
Camera resolution.
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
This class is a "CSerializable" wrapper for "CMatrixFloat".
void getNextFrameRGB(mrpt::utils::CImage &rgb_img, uint64_t ×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 setPixel(int x, int y, size_t color) MRPT_OVERRIDE
Changes the value of the pixel (x,y).
Structure to hold the parameters of a pinhole camera model.
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().