c++ - Convertion Between cv::Mat and XnDepthPixel* -
i working openni 1.5.4.0 , opencv 2.4.5, plus qt visualization purpose (only rgb images). basically, retrieving depth , rgb frames kinect , store them on hard drive, using conversion:
/* depth conversion */ cv::mat depth = cv::mat(2, sizes, cv_16uc1, (void*) pdepthmap); //xndepthpixel *pdepthmap /* rgb conversion */ ///image qimage* , pimagemap xnuint8* for(int = 0; < height; ++i) { (unsigned y = 0; y < height; ++y) { uchar *imageptr = (*image).scanline(y); (unsigned x=0; x < width; ++x) { imageptr[0] = pimagemap[2]; imageptr[1] = pimagemap[1]; imageptr[2] = pimagemap[0]; imageptr[3] = 0xff; imageptr+=4; pimagemap+=3; } } }
now, want load images hard drive, in order compute 3d pointclouds post-processing computation. loading depth maps as:
depth_image = cv::imread(m_rgb_files.at(w).tostdstring(), cv_load_image_anydepth | cv_load_image_anycolor );
but applying formulas:
depth = depth_image.at<int>(j,i); //depth_image stored 16bit p.z = (float)depth * 0.001f; //converting millimeters meters p.x = (float)(i - m_params.center_x) * depth * m_params.focal_length; //focal_length read using openni function p.y = (float)(j - m_params.center_y) * depth * m_params.focal_length;
the pointcloud obtained mess.
if "online" processing, using directly native xndepthpixel* data, result perfect, using formulas written before. can give me "hint" fault?
thanks in advance
edit: following resource, doesn't work me, because xndepthpixel contains real world data in millimeters
i think there possible problem here:
depth = depth_image.at<int>(j,i); //depth_image stored 16bit
if depth image is 16-bit, should be:
depth = depth_image.at<short>(j,i); //depth_image stored 16bit
because int
32-bits, not 16.
Comments
Post a Comment