39 #include <visp3/core/vpConfig.h>
42 #if defined(VISP_HAVE_LIBFREENECT_AND_DEPENDENCIES)
46 #include <visp3/sensor/vpKinect.h>
47 #include <visp3/core/vpXmlParserCamera.h>
53 : Freenect::FreenectDevice(ctx, index),
54 m_rgb_mutex(), m_depth_mutex(), RGBcam(), IRcam(),
55 rgbMir(), irMrgb(), DMres(DMAP_LOW_RES),
58 m_new_rgb_frame(false),
59 m_new_depth_map(false),
60 m_new_depth_image(false),
61 height(480), width(640)
63 dmap.
resize(height, width);
64 IRGB.
resize(height, width);
65 vpPoseVector r(-0.0266,-0.0047,-0.0055,0.0320578,0.0169041,-0.0076519 );
85 std::cout <<
"vpKinect::start LOW depth map resolution 240x320" << std::endl;
94 std::cout <<
"vpKinect::start MEDIUM depth map resolution 480x640" << std::endl;
103 #if defined(VISP_HAVE_ACCESS_TO_NAS) && defined(VISP_HAVE_XML2)
105 char cameraXmlFile[FILENAME_MAX];
106 sprintf(cameraXmlFile,
"/udd/fspindle/robot/Viper850/Viper850-code/include/const_camera_Viper850.xml");
129 void vpKinect::VideoCallback(
void* rgb, uint32_t )
133 uint8_t* rgb_ =
static_cast<uint8_t*
>(rgb);
134 for (
unsigned i = 0; i< height;i++){
135 for (
unsigned j = 0 ; j < width ; j++)
137 IRGB[i][j].R = rgb_[3*(width*i +j)+0];
138 IRGB[i][j].G = rgb_[3*(width*i +j)+1];
139 IRGB[i][j].B = rgb_[3*(width*i +j)+2];
143 m_new_rgb_frame =
true;
156 void vpKinect::DepthCallback(
void* depth, uint32_t )
160 uint16_t* depth_ =
static_cast<uint16_t*
>(depth);
161 for (
unsigned i = 0; i< height;i++){
162 for (
unsigned j = 0 ; j < width ; j++)
164 dmap[i][j] = 0.1236f * tan(depth_[width*i +j] / 2842.5f + 1.1863f);
165 if(depth_[width*i +j]>1023){
170 m_new_depth_map =
true;
171 m_new_depth_image =
true;
181 if (!m_new_depth_map)
184 m_new_depth_map =
false;
196 m_depth_mutex.
lock();
197 if (!m_new_depth_map && !m_new_depth_image)
204 m_new_depth_map =
false;
205 m_new_depth_image =
false;
209 vpERROR_TRACE(1,
"Image size does not match vpKinect DM resolution");
211 for(
unsigned int i = 0; i < hd; i++)
212 for(
unsigned int j = 0; j < wd; j++){
213 map[i][j] = tempMap[i<<1][j<<1];
215 if (fabs(map[i][j] + 1.f) > std::numeric_limits<float>::epsilon())
216 Imap[i][j] = (
unsigned char)(255*map[i][j]/5);
223 for (
unsigned i = 0; i< height;i++)
224 for (
unsigned j = 0 ; j < width ; j++){
225 map[i][j] = tempMap[i][j];
227 if (fabs(map[i][j] + 1.f) > std::numeric_limits<float>::epsilon())
228 Imap[i][j] = (
unsigned char)(255*map[i][j]/5);
244 if (!m_new_rgb_frame)
247 m_new_rgb_frame =
false;
257 vpERROR_TRACE(1,
"Idepth image size does not match vpKinect DM resolution");
261 IrgbWarped.
resize(hd, wd);
263 double x1=0., y1=0., x2=0., y2=0., Z1, Z2;
270 for (
unsigned int i = 0; i< hd;i++)
271 for (
unsigned int j = 0 ; j < wd ; j++){
276 if (std::fabs(Z1+1) <= std::numeric_limits<double>::epsilon()){
286 if (std::fabs(Z2) > std::numeric_limits<double>::epsilon()){
291 std::cout<<
"Z2 = 0 !!"<<std::endl;
296 unsigned int u_ = (
unsigned int)u;
297 unsigned int v_ = (
unsigned int)v;
299 if ((u_<width)&&(v_<height)){
300 IrgbWarped[i][j] = Irgb[v_][u_];
303 IrgbWarped[i][j] = 0;
309 #elif !defined(VISP_BUILD_SHARED_LIBS)
311 void dummy_vpKinect() {};
312 #endif // VISP_HAVE_LIBFREENECT
Class that allows protection by mutex.
void start(vpKinect::vpDMResolution res=DMAP_LOW_RES)
unsigned int getWidth() const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
XML parser to load and save intrinsic camera parameters.
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
bool getRGB(vpImage< vpRGBa > &IRGB)
void warpRGBFrame(const vpImage< vpRGBa > &Irgb, const vpImage< float > &Idepth, vpImage< vpRGBa > &IrgbWarped)
Perspective projection with distortion model.
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Implementation of column vector and the associated operations.
Implementation of a pose vector and operations on poses.
vpHomogeneousMatrix inverse() const
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
int parse(vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width=0, const unsigned int image_height=0)
bool getDepthMap(vpImage< float > &map)
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)
vpKinect(freenect_context *ctx, int index)