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

时间:2013-06-26 09:14:05

标签: opencv mapping kinect openni

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

我有Depthmap 640x480,深度为mm,试图像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相机和红外热像仪的估计校准值,我的结果在各个方向都失败了,只有在改变外在T参数时才能修复。

我有一些怀疑:

  • OpenNi是否已经将红外深度图映射到了RGB相机 超高动力学?
  • 我应该使用以米为单位的深度,还是将像素转换为 毫米? (我尝试乘以pixel_size * 0.001,但我得到了 相同的结果)

真的希望有人可以帮助我。 Thx提前。

1 个答案:

答案 0 :(得分:1)

AFAIK OpenNI会自行注册(出厂设置),您也可以切换注册。如果您已经使用OpenNI支持构建了OpenCV,那么就像这样简单:

capture.set(CV_CAP_PROP_OPENNI_REGISTRATION,1);

正如here所述,并且有一个最小的OpenNI / OpenCV示例here。 所以最小的工作样本看起来像这样:

#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()