生成的点云一直不太正常,发现深度图和彩色图没有配准
Kinect的SDK的函数貌似无用?
以下为找到的几个配准代码记录:
1.链接:https://blog.youkuaiyun.com/shihz_fy/article/details/43602393#commentsedit
/***** Measurement of height by kinect ******/
/***** VisualStudio 2012 (开发工具)
OpenCV2.4.8 (显示界面库 vc11库)
KinectSDK-v2.0-PublicPreview1409-Setup (Kinect SDK驱动版本)
Windows 8.1 (操作系统) ******/
/***** shihz ******/
/***** 2015-2-7 ******/
#include"stdafx.h"
#include "opencv2/opencv.hpp"
#define Y 160
using namespace cv;
// Safe release for interfaces
template<class Interface>
inline void SafeRelease(Interface *& pInterfaceToRelease)
{
if (pInterfaceToRelease != NULL)
{
pInterfaceToRelease->Release();
pInterfaceToRelease = NULL;
}
}
//定义Kinect方法类
class Kinect
{
public:
static const int cDepthWidth = 512; //深度图的大小
static const int cDepthHeight = 424;
static const int cColorWidth = 1920; //彩色图的大小
static const int cColorHeight = 1080;
Mat showImageDepth;
HRESULT InitKinect();//初始化Kinect
void UpdateDepth();//更新深度数据
void UpdateColor();//更新深度数据
void ProcessDepth(const UINT16* pBuffer, int nWidth, int nHeight, USHORT nMinDepth, USHORT nMaxDepth); //处理得到的深度图数据
void ProcessColor(RGBQUAD* pBuffer, int nWidth, int nHeight); //处理得到的彩色图数据
Kinect(); //构造函数
~Kinect(); //析构函数
private:
IKinectSensor* m_pKinectSensor;// Current Kinect
IDepthFrameReader* m_pDepthFrameReader;// Depth reader 在需要的时候可以再添加IColorFrameReader,进行color reader
RGBQUAD* m_pDepthRGBX;
IColorFrameReader* m_pColorFrameReader;// Color reader
RGBQUAD* m_pColorRGBX;
};
int main()
{
Kinect kinect;
Mat showImageColor;
kinect.InitKinect();
while(1)
{
kinect.UpdateColor(); //程序的中心内容,获取数据并显示
kinect.UpdateDepth();
if(waitKey(1) >= 0)//按下任意键退出
{
break;
}
}
return 0;
}
Kinect::Kinect()
{
m_pKinectSensor = NULL;
m_pColorFrameReader = NULL;
m_pDepthFrameReader = NULL;
m_pDepthRGBX = new RGBQUAD[cDepthWidth * cDepthHeight];// create heap storage for color pixel data in RGBX format ,开辟一个动态存储区域
m_pColorRGBX = new RGBQUAD[cColorWidth * cColorHeight];// create heap storage for color pixel data in RGBX format
}
Kinect::~Kinect() //定义析构函数
{
if (m_pDepthRGBX)
{
delete [] m_pDepthRGBX; //删除动态存储区域
m_pDepthRGBX = NULL;
}
SafeRelease(m_pDepthFrameReader);// done with depth frame reader
if (m_pColorRGBX)
{
delete [] m_pColorRGBX;
m_pColorRGBX = NULL;
}
SafeRelease(m_pColorFrameReader);// done with color frame reader
if (m_pKinectSensor)
{
m_pKinectSensor->Close();// close the Kinect Sensor
}
SafeRelease(m_pKinectSensor);
}
HRESULT Kinect::InitKinect() //定义初始化kinect函数
{
HRESULT hr; //typedef long HRESULT
hr = GetDefaultKinectSensor(&m_pKinectSensor); //获取默认的kinect,一般来说只有用一个kinect,所以默认的也就是唯一的那个
if (FAILED(hr)) //Failed这个函数的参数小于0的时候返回true else 返回false
{
return hr;
}
if (m_pKinectSensor)
{
// Initialize the Kinect and get the depth reader
IDepthFrameSource* pDepthFrameSource = NULL;
IColorFrameSource* pColorFrameSource = NULL;
hr = m_pKinectSensor->Open();
if (SUCCEEDED(hr))
{
hr = m_pKinectSensor->get_ColorFrameSource(&pColorFra