将 Kinect 深度图像转换为真实世界的尺寸
convert kinect depth image to real world dimensions
我正在做一个使用 kinect 来避免障碍的项目,我正在使用 Visual Studio C++、OpenCV 库和代码实验室驱动程序(CL NUI 平台)。我想将深度图像转换为现实世界的尺寸。
提前致谢这是我的代码:
#include "stdafx.h"
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <opencv/highgui.h>
#include <CLNUIDevice.h>
using namespace std;
void displayKinectImage();
int _tmain(int argc, _TCHAR* argv[])
{
displayKinectImage();
}
void displayKinectImage() {
PDWORD rgb32_data = (PDWORD)malloc(640 * 480 * 4);
PDWORD depth32_data = (PDWORD)malloc(640 * 480 * 4);
CLNUICamera cam = CreateNUICamera(GetNUIDeviceSerial(0));
CLNUIMotor motor = CreateNUIMotor(GetNUIDeviceSerial(0));
StartNUICamera(cam);
cvNamedWindow("Image", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Depth", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Grey", CV_WINDOW_AUTOSIZE);
IplImage *rgb32 = cvCreateImageHeader(cvSize(640, 480), 8, 4);
IplImage *grey;
IplImage *depth32 = cvCreateImageHeader(cvSize(640, 480), 8, 4);;
do {
GetNUICameraColorFrameRGB32(cam, rgb32_data);
GetNUICameraDepthFrameRGB32(cam, depth32_data);
rgb32 = cvCreateImageHeader(cvSize(640, 480), 8, 4);
grey = cvCreateImage(cvSize(640, 480), 8, 1);
depth32 = cvCreateImageHeader(cvSize(640, 480), 8, 4);
cvSetData(rgb32, rgb32_data, rgb32->widthStep);
cvSetData(depth32, depth32_data, depth32->widthStep);
// Convert RGB32 to greyscale
cvCvtColor(depth32, grey, CV_RGB2GRAY);
cvShowImage("Image", rgb32);
cvShowImage("Grey", grey);
cvShowImage("Depth", depth32);
cvReleaseImageHeader(&rgb32);
cvReleaseImage(&grey);
cvReleaseImageHeader(&depth32);
cvWaitKey(1);
} while (!GetAsyncKeyState(0x50));
free(rgb32_data);
free(depth32_data);
}
您可以使用以下命令获得与像素(j,i)
对应的 3D 点
constexpr int WIDTH = 640;
constexpr int HEIGHT = 480;
constexpr float DEPTH_TO_M = 0.001f;
constexpr float SCL = 1.0f / 520.0f;
float z = static_cast<float>(depth)*DEPTH_TO_M;
float x = staitc_cast<float>(j - WIDTH/2)*z*SCL;
float y = staitc_cast<float>(i - HEIGHT/2)*z*SCL;
常量DEPTH_TO_M
和SCL
是近似值。如果你想要准确的结果,那么你需要校准你的相机,但这是一个科学问题,超出了堆栈溢出的范围。
相关文章:
- 激励'inline'说明符的真实世界示例?
- 如何转换真实路径 CString c++
- 在 OpenGL 中将笛卡尔世界坐标转换为球面局部坐标
- 我们可以在不知道其真实类型的情况下将基类指针转换为派生类指针吗?
- 将 2D 图像坐标转换为 z = 0 的 3D 世界坐标
- 如何将世界坐标转换为相机图像坐标
- 将鼠标坐标转换为世界空间坐标
- 将 2D 屏幕坐标转换为 3D 世界坐标
- 使用特征元将转换矩阵从世界空间转换为相机空间
- 宇宙飞船操作员的真实世界使用示例
- 如何将像素坐标转换为世界坐标
- 图像点(像素)到真实世界坐标(米)
- 如何在C++中将像"u94b1"这样的字符串转换为一个真实字符?
- 使用点云库将点云转换为世界坐标
- 用于C++真实世界应用程序的GUI框架
- Qgraphics场景中的真实世界维度
- C++错误 C2664:无法将"mw::世界"转换为"mw::世界"
- C++ Kinect v2 & freenect2:如何将深度数据转换为真实世界的坐标
- 将Kinect深度图像转换为真实世界坐标
- 将 Kinect 深度图像转换为真实世界的尺寸