35#include <visp3/core/vpConfig.h>
38#if defined(VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES)
42#include <visp3/core/vpDebug.h>
43#include <visp3/core/vpXmlParserCamera.h>
44#include <visp3/sensor/vpKinect.h>
51 : Freenect::FreenectDevice(ctx, index), m_rgb_mutex(), m_depth_mutex(), RGBcam(), IRcam(), rgbMir(), irMrgb(),
52 DMres(
DMAP_LOW_RES), hd(240), wd(320), dmap(), IRGB(), m_new_rgb_frame(false), m_new_depth_map(false),
53 m_new_depth_image(false), height(480), width(640)
55 dmap.resize(height, width);
56 IRGB.resize(height, width);
57 vpPoseVector r(-0.0266, -0.0047, -0.0055, 0.0320578, 0.0169041,
62 irMrgb = rgbMir.inverse();
78 std::cout <<
"vpKinect::start LOW depth map resolution 240x320" << std::endl;
79 IRcam.initPersProjWithDistortion(303.06, 297.89, 160.75, 117.9, -0.27, 0);
84 std::cout <<
"vpKinect::start MEDIUM depth map resolution 480x640" << std::endl;
86 IRcam.initPersProjWithDistortion(606.12, 595.78, 321.5, 235.8, -0.27, 0);
92#if defined(VISP_HAVE_VIPER850_DATA) && defined(VISP_HAVE_PUGIXML)
94 std::string cameraXmlFile = std::string(VISP_VIPER850_DATA_PATH) + std::string(
"/include/const_camera_Viper850.xml");
102 RGBcam.initPersProjWithDistortion(522.5431816996, 522.7191431808, 311.4001982614, 267.4283562142, 0.0477365207,
119void vpKinect::VideoCallback(
void *rgb, uint32_t )
121 std::lock_guard<std::mutex> lock(m_rgb_mutex);
122 uint8_t *rgb_ =
static_cast<uint8_t *
>(rgb);
123 for (
unsigned i = 0; i < height; i++) {
124 for (
unsigned j = 0; j < width; j++) {
125 IRGB[i][j].R = rgb_[3 * (width * i + j) + 0];
126 IRGB[i][j].G = rgb_[3 * (width * i + j) + 1];
127 IRGB[i][j].B = rgb_[3 * (width * i + j) + 2];
131 m_new_rgb_frame =
true;
144void vpKinect::DepthCallback(
void *depth, uint32_t )
146 std::lock_guard<std::mutex> lock(m_depth_mutex);
147 uint16_t *depth_ =
static_cast<uint16_t *
>(
depth);
148 for (
unsigned i = 0;
i < height;
i++) {
149 for (
unsigned j = 0;
j < width;
j++) {
151 0.1236f * tan(depth_[width * i + j] / 2842.5f + 1.1863f);
153 if (depth_[width * i + j] > 1023) {
158 m_new_depth_map =
true;
159 m_new_depth_image =
true;
167 std::lock_guard<std::mutex> lock(m_depth_mutex);
168 if (!m_new_depth_map)
171 m_new_depth_map =
false;
181 m_depth_mutex.lock();
182 if (!m_new_depth_map && !m_new_depth_image) {
183 m_depth_mutex.unlock();
188 m_new_depth_map =
false;
189 m_new_depth_image =
false;
190 m_depth_mutex.unlock();
193 vpERROR_TRACE(1,
"Image size does not match vpKinect DM resolution");
195 for (
unsigned int i = 0; i < hd; i++)
196 for (
unsigned int j = 0; j < wd; j++) {
197 map[i][j] = tempMap[i << 1][j << 1];
199 if (fabs(map[i][j] + 1.f) > std::numeric_limits<float>::epsilon())
200 Imap[i][j] =
static_cast<unsigned char>(255 * map[i][j] / 5);
206 for (
unsigned i = 0; i < height; i++)
207 for (
unsigned j = 0; j < width; j++) {
208 map[i][j] = tempMap[i][j];
210 if (fabs(map[i][j] + 1.f) > std::numeric_limits<float>::epsilon())
211 Imap[i][j] =
static_cast<unsigned char>(255 * map[i][j] / 5);
225 std::lock_guard<std::mutex> lock(m_rgb_mutex);
226 if (!m_new_rgb_frame)
229 m_new_rgb_frame =
false;
240 vpERROR_TRACE(1,
"Idepth image size does not match vpKinect DM resolution");
244 IrgbWarped.
resize(hd, wd);
246 double x1 = 0., y1 = 0., x2 = 0., y2 = 0., Z1, Z2;
248 double u = 0., v = 0.;
251 for (
unsigned int i = 0; i < hd; i++)
252 for (
unsigned int j = 0; j < wd; j++) {
257 if (std::fabs(Z1 + 1) <= std::numeric_limits<double>::epsilon()) {
267 if (std::fabs(Z2) > std::numeric_limits<double>::epsilon()) {
272 std::cout <<
"Z2 = 0 !!" << std::endl;
278 unsigned int u_ =
static_cast<unsigned int>(u);
279 unsigned int v_ =
static_cast<unsigned int>(v);
281 if ((u_ < width) && (v_ < height)) {
282 IrgbWarped[i][j] = Irgb[v_][u_];
285 IrgbWarped[i][j] = 0;
291#elif !defined(VISP_BUILD_SHARED_LIBS)
293void dummy_vpKinect() { }
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
Implementation of column vector and the associated operations.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
void warpRGBFrame(const vpImage< vpRGBa > &Irgb, const vpImage< float > &Idepth, vpImage< vpRGBa > &IrgbWarped)
bool getDepthMap(vpImage< float > &map)
void start(vpKinect::vpDMResolution res=DMAP_LOW_RES)
vpKinect(freenect_context *ctx, int index)
bool getRGB(vpImage< vpRGBa > &IRGB)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Implementation of a pose vector and operations on poses.
XML parser to load and save intrinsic camera parameters.
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, unsigned int image_width=0, unsigned int image_height=0, bool verbose=true)