Reputation: 21
I need to reconstruct a PointCloud using libfreenect2 registration::apply with color/depth images. The problem is I pre-saved the color & depth images as PNG files. Both color & depth images was obtained using libfreenect2::Frame and converted to a OpenCV Mat for imwrite.
Mat(rgb->height, rgb->width, CV_8UC4, rgb->data).copyTo(bgrImage);
Mat(depth->height, depth->width, CV_32FC1, depth->data).copyTo(depthImage);
I tried the following method to get my color Frame & it works. The problem is when I tried to do the same thing with the depth image, issues emerge.
Mat color_CV8UC3 = cv::imread(colorFilename);
cvtColor(color_CV8UC3, color_CV8UC4, CV_BGR2BGRA); //Convert to BGRX
libfreenect2::Frame rgb(color_CV8UC4.cols, color_CV8UC4.rows, 4, color_CV8UC4.data);
Mat depthImg = cv::imread(depthFilename);
depthImg.convertTo(depthFrame, CV_32FC1, 1.0/255.0); //Convert to 32FC1
libfreenect2::Frame depth(depthFrame.cols, depthFrame.rows, 4, depthFrame.data);
I tested the conversion of cv::Mat to libfreenect2::Frame by re-converting the libfreenect2::Frame for both rgb and depth & while I got the same image for rgb, it wasn't true for the depth image.
Mat(rgb.height, rgb.width, CV_8UC4, rgb.data).copyTo(rgb_image);
Mat(depth.height, depth.width, CV_32FC1, depth.data ).copyTo(depth_image);
imshow("Depth", depth_image);
imshow("Color", rgb_image);
Depth Image - Loaded & Converted to 32FC1
Depth Image - After Converted to Frame & Reconverted Back
Thanks for any assistance provided and please give any feedback as this is my first time posting a question here.
Upvotes: 2
Views: 673