CoordinateMapper离线 [英] CoordinateMapper offline

查看:152
本文介绍了CoordinateMapper离线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在尝试使用先前保存的CoordinateMapper加载图片,但没有任何成功。我保持kinect插入,我打开传感器,然后检索CoordinateMapper。然后,我使用OpenCV读取深度图像,并尝试将其传递给
函数MapColorFrameToDepthSpace。该函数不会给出任何错误,但它不会填充depthCoordinate结构。我认为问题是我将opencv指针传递给MapColorFrameToDepthSpace函数的方式(它仍然可能是),
因此我创建了UINT16 *变量以手动传递给函数。仍然没有成功。我的代码部分不起作用:


 int main(int argc,char * argv []) 
{
HRESULT hr;

static const int cDepthWidth = 512;
static const int cDepthHeight = 424;
static const int cColorWidth = 1920;
static const int cColorHeight = 1080;

IKinectSensor * m_pKinectSensor;
ICoordinateMapper * m_pCoordinateMapper;
DepthSpacePoint * m_pDepthCoordinates;

hr = GetDefaultKinectSensor(& m_pKinectSensor);
if(FAILED(hr))
{
return false;
}

if(m_pKinectSensor)
{
if(SUCCEEDED(hr))
{
hr = m_pKinectSensor-> get_CoordinateMapper( &安培; m_pCoordinateMapper);
m_pDepthCoordinates = new DepthSpacePoint [cColorWidth * cColorHeight];
}

hr = m_pKinectSensor-> Open();

Mat depth = imread(" C:/Users/User/Desktop/depth.png" ;, IMREAD_ANYDEPTH);
int rows = depth.rows;
int cols = depth.cols;
Mat rgb = imread(" C:/Users/User/Desktop/rgb.png" ;, IMREAD_COLOR);
Mat rgb_small(depth.rows,depth.cols,rgb.depth());

UINT16 * depthArray = new UINT16 [depth.rows * depth.cols];
int i = 0; int j = 0;
for(int k = 0; k< cDepthHeight * cDepthWidth; ++ k)
{
depthArray [k] = depth.at< ushort>(i,j);
j ++;
if(j == depth.cols)
{
i ++;
j = 0;
}
}

HRESULT hr = m_pCoordinateMapper-> MapColorFrameToDepthSpace(depth.rows * depth.cols,depthArray,rgb.cols * rgb.rows,m_pDepthCoordinates);

int m = 0;
int n = 0;
for(int colorIndex = 0; colorIndex<(rgb.cols * rgb.rows); ++ colorIndex)
{
DepthSpacePoint p = m_pDepthCoordinates [colorIndex];

if(pX!= -std :: numeric_limits< float> :: infinity()&& pY!= -std :: numeric_limits< float> :: infinity())
{
int depthX = static_cast< int>(pX + 0.5f);
int depthY = static_cast< int>(p.Y + 0.5f);

if((depthX> = 0&& depthX< depth.cols)&&(depthY> = 0&& depthY< depth.rows))
{
rgb_small.at< Vec3b>(depthX,depthY)= rgb.at< Vec3b>(m,n);
}
}

n ++;

if(n == rgb.cols)
{
n = 0;
m ++;
}
}
}

返回1;
}

我做错了什么?我忘记了初始化的东西吗?我还在做UINT16 *变量的错误吗? m_pDepthCoordinates总是返回荒谬的数字,当然,最终的矩阵(rgb_small)是空的。


非常感谢你的帮助。


最好,


Ilaria


解决方案

CoordinateMapper要求传感器由于技术的工作方式而连接。如果您使用Kinect Studio录制,则可以在没有传感器连接的情况下重放剪辑。此方法适用于坐标映射器。


如果不打算使用Kinect Studio,则必须将映射数据保存为原始记录的一部分。


Hi,

I have been trying to use the CoordinateMapper loading images previously saved, but without any success. I keep the kinect plugged, I open the sensor and I retrieve the CoordinateMapper. Then, I read the depth image using OpenCV and I try to pass it to the function MapColorFrameToDepthSpace. The function does not give any error, but it doesn't fill the depthCoordinate structure. I thought that the problem was the way I was passing the opencv pointer to the MapColorFrameToDepthSpace function (it still may be), so I created the UINT16* variable to pass to the function manually. Still, no success. The part of my code that doesn't work:

int main(int argc, char *argv[])
{
	HRESULT hr;

	static const int        cDepthWidth = 512;
	static const int        cDepthHeight = 424;
	static const int        cColorWidth = 1920;
	static const int        cColorHeight = 1080;

	IKinectSensor*          m_pKinectSensor;
	ICoordinateMapper*      m_pCoordinateMapper;
	DepthSpacePoint*        m_pDepthCoordinates;

	hr = GetDefaultKinectSensor(&m_pKinectSensor);
	if (FAILED(hr))
	{
		return false;
	}

	if (m_pKinectSensor)
	{
		if (SUCCEEDED(hr))
		{
			hr = m_pKinectSensor->get_CoordinateMapper(&m_pCoordinateMapper);
			m_pDepthCoordinates = new DepthSpacePoint[cColorWidth * cColorHeight];
		}

		hr = m_pKinectSensor->Open();

		Mat depth = imread("C:/Users/User/Desktop/depth.png", IMREAD_ANYDEPTH);
		int rows = depth.rows;
		int cols = depth.cols;
		Mat rgb = imread("C:/Users/User/Desktop/rgb.png", IMREAD_COLOR);
		Mat rgb_small(depth.rows, depth.cols, rgb.depth());

		UINT16 *depthArray = new UINT16[depth.rows * depth.cols];
		int i = 0; int j = 0;
		for (int k = 0; k < cDepthHeight * cDepthWidth; ++k)
		{
			depthArray[k] = depth.at<ushort>(i, j);
			j++;
			if (j == depth.cols)
			{
				i++;
				j = 0;
			}
		}

		HRESULT hr = m_pCoordinateMapper->MapColorFrameToDepthSpace(depth.rows * depth.cols, depthArray, rgb.cols * rgb.rows, m_pDepthCoordinates);

		int m = 0;
		int n = 0;
		for (int colorIndex = 0; colorIndex < (rgb.cols * rgb.rows); ++colorIndex)
		{
			DepthSpacePoint p = m_pDepthCoordinates[colorIndex];

			if (p.X != -std::numeric_limits<float>::infinity() && p.Y != -std::numeric_limits<float>::infinity())
			{
				int depthX = static_cast<int>(p.X + 0.5f);
				int depthY = static_cast<int>(p.Y + 0.5f);

				if ((depthX >= 0 && depthX < depth.cols) && (depthY >= 0 && depthY < depth.rows))
				{
					rgb_small.at<Vec3b>(depthX, depthY) = rgb.at<Vec3b>(m, n);
				}
			}

			n++;

			if (n == rgb.cols)
			{
				n = 0;
				m++;
			}
		}
	}

	return 1;
}

What am I doing wrong? Am I forgetting to initialize something? Am I still doing something wrong with the UINT16* variable? The m_pDepthCoordinates always returns absurd numbers, and of course, the final matrix (rgb_small) is empty.

Thank you very much for your help.

Best,

Ilaria

解决方案

The CoordinateMapper requires the sensor to be attached due to the way the technology works. If you use a Kinect Studio recording then you can replay clips without a sensor attached that way. This method will work with the coordinate mapper.

If are not planning to use Kinect Studio, then you will have to save the mapped data as part of that original recording as well.


这篇关于CoordinateMapper离线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆