sub*_*b_o 5 opencv computer-vision kinect
我正在使用OpenCV处理给定的数据集,而我没有任何Kinect.我想将给定的深度数据映射到RGB对应物(这样我就可以得到实际的颜色和深度)
由于我使用的是OpenCV和C++,并且没有Kinect,遗憾的是我无法使用官方Kinect API中的MapDepthFrameToColorFrame方法.
从给定的相机的内在函数和失真系数,我可以将深度映射到世界坐标,并根据此处提供的算法返回到RGB
Vec3f depthToW( int x, int y, float depth ){
Vec3f result;
result[0] = (float) (x - depthCX) * depth / depthFX;
result[1] = (float) (y - depthCY) * depth / depthFY;
result[2] = (float) depth;
return result;
}
Vec2i wToRGB( const Vec3f & point ) {
Mat p3d( point );
p3d = extRotation * p3d + extTranslation;
float x = p3d.at<float>(0, 0);
float y = p3d.at<float>(1, 0);
float z = p3d.at<float>(2, 0);
Vec2i result;
result[0] = (int) round( (x * rgbFX / z) + rgbCX );
result[1] = (int) round( (y * rgbFY / z) + rgbCY );
return result;
}
void map( Mat& rgb, Mat& depth ) {
/* intrinsics are focal points and centers of camera */
undistort( rgb, rgb, rgbIntrinsic, rgbDistortion );
undistort( depth, depth, depthIntrinsic, depthDistortion );
Mat color = Mat( depth.size(), CV_8UC3, Scalar(0) );
ushort * raw_image_ptr;
for( int y = 0; y < depth.rows; y++ ) {
raw_image_ptr = depth.ptr<ushort>( y );
for( int x = 0; x < depth.cols; x++ ) {
if( raw_image_ptr[x] >= 2047 || raw_image_ptr[x] <= 0 )
continue;
float depth_value = depthMeters[ raw_image_ptr[x] ];
Vec3f depth_coord = depthToW( y, x, depth_value );
Vec2i rgb_coord = wToRGB( depth_coord );
color.at<Vec3b>(y, x) = rgb.at<Vec3b>(rgb_coord[0], rgb_coord[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
但结果似乎是错位的.我无法手动设置翻译,因为数据集是从3个不同的Kinects获得的,并且每个Kinect都在不同的方向上未对齐.您可以在下面看到其中一个(左:未失真的RGB,中间:未失真的深度,右:将RGB映射到深度)
我的问题是,此时我该怎么办?在尝试将世界或世界的深度投射回RGB时,我是否错过了一步?任何有立体相机经验的人都可以指出我的错误吗?
非常感谢你提前!