3D将深度映射到RGB(Kinect OpenNI Depthmap到OpenCV RGB Cam)



我正在尝试将我的OpenNI(1.5.4.0)Kinect 4 Windows Depthmap映射到OpenCV RGB图像。

我有深度为毫米的640x480深度图,我试图像Burrus一样绘制地图:http://burrus.name/index.php/Research/KinectCalibration

我跳过了失真部分,但除此之外,我做了我想做的一切:

//with depth camera intrinsics, each pixel (x_d,y_d) of depth camera can be projected
//to metric 3D space. with fx_d, fy_d, cx_d and cy_d the intrinsics of the depth camera. 
P3D.at<Vec3f>(y,x)[0] = (x - cx_ir) * depth/fx_ir;
P3D.at<Vec3f>(y,x)[1] = (y - cy_ir) * depth/fy_ir;
P3D.at<Vec3f>(y,x)[2] = depth;

//P3D' = R.P3D + T:
RTMat = (Mat_<float>(4,4) << 0.999388, -0.00796202, -0.0480646, -3.96963,
0.00612322, 0.9993536, 0.0337474, -22.8512,
0.0244427, -0.03635059, 0.999173, -15.6307,
0,0,0,1);
perspectiveTransform(P3D, P3DS, RTMat);
//reproject each 3D point on the color image and get its color:  
depth = P3DS.at<Vec3f>(y,x)[2];
x_rgb =  (P3DS.at<Vec3f>(y,x)[0] * fx_rgb/ depth + cx_rgb;
y_rgb = (P3DS.at<Vec3f>(y,x)[1] * fy_rgb/ depth + cy_rgb;

但是,根据我对Kinect的RGB相机和IR相机的估计校准值,我的结果在各个方向上都失败了,并且不能仅通过更改外部T参数来修复。

我有一些怀疑:

  • OpenNi是否已经将IR Depthmap映射到Kinect
  • 我应该使用以米为单位的深度和/或将像素转换为毫米?(我试着乘以pixel_size*0.001,但我得到了相同的结果)

真希望有人能帮助我。提前Thx。

AFAIK-OpenNI自己注册(出厂设置),您也可以切换注册。如果你已经构建了支持OpenNI的OpenCV,它就这么简单:

capture.set(CV_CAP_PROP_OPENNI_REGISTRATION,1);

正如这里所解释的,这里有一个最小的OpenNI/OpenCV示例。因此,一个最小的工作样本看起来是这样的:

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(){
    VideoCapture capture;
    capture.open(CV_CAP_OPENNI);
    //registration
    if(capture.get( CV_CAP_PROP_OPENNI_REGISTRATION ) == 0) capture.set(CV_CAP_PROP_OPENNI_REGISTRATION,1);
    if( !capture.isOpened() ){
        cout << "Can not open a capture object." << endl;
        return -1;
    }
    cout << "ready" << endl;
    for(;;){
        Mat depthMap,depthShow;
        if( !capture.grab() ){
            cout << "Can not grab images." << endl;
            return -1;
        }else{
            if( capture.retrieve( depthMap, CV_CAP_OPENNI_DEPTH_MAP ) ){
                const float scaleFactor = 0.05f;
                depthMap.convertTo( depthShow, CV_8UC1, scaleFactor );
                imshow("depth",depthShow);
            }
        }
        if( waitKey( 30 ) == 27 )    break;//esc to exit
    }
}

如果您没有使用OpenNI支持构建OpenCV,您应该能够使用GetAlternativeViewPointCap()

最新更新