OpenNI学习笔记1----在vs2010下OpenNI的安装配置

    对OpenNI在vs2010下的安装配置先做几点说明:

1.实验中是在64位win7上安装X86的OpenNI2.1

2.debug和release是独立的,所以配置时要对应一致,本实验是在debug下进行的。

    安装过程如下:

1.在官网上可以下载对应版本的OpenNI,按照提示进行安装。

2.在进行本次实验中,自动建立了OpenNI的环境变量,如果没有自动建立,那么环境变量的值要根据自己实际安装位置来新建变量,见图:

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第1张图片

3.打开vs2010,建立一个win32控制台应用程序,选择空项目后,添加一个cpp文件。

4.对项目属性进行配置:

      4.1 项目属性-->配置属性--->c/c++--->常规--->附加包含目录,点击右侧的下拉箭头,然后点击编辑,添加  $(OPENNI2_INCLUDE)  。

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第2张图片

      4.2 项目属性-->配置属性--->链接器--->常规--->附加库目录,点击右侧的下拉箭头,然后点击编辑,添加  $(OPENNI2_LIB)  。

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第3张图片

      4.3 项目属性-->配置属性--->c/c++--->输入--->附加依赖项,点击右侧的下拉箭头,然后点击编辑,添加  OPENNI2.lib  。

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第4张图片

      4.4 项目属性-->配置属性--->调试--->工作目录,点击右侧的下拉箭头,然后点击编辑,添加  $(OPENNI2_REDIST)  。

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第5张图片

5.最后在添加的cpp文件中添加示例代码,本代码来自openNI安装文件中,路径为D:\OpenNI2\Samples\SimpleRead 的main.cpp。做了一点修改,

将D:\OpenNI2\Samples\Common下的OniSampleUtilities.h复制到D:\OpenNI2\Include下,所以在包含头文件中一行代码改为    #include "OniSampleUtilities.h"

 

 

/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
#include 
#include 

#include "OniSampleUtilities.h"

using namespace openni;

int main()
{
	Status rc = OpenNI::initialize();
	if (rc != STATUS_OK)
	{
		printf("Initialize failed\n%s\n", OpenNI::getExtendedError());
		return 1;
	}

	Device device;
	rc = device.open(ANY_DEVICE);
	if (rc != STATUS_OK)
	{
		printf("Couldn't open device\n%s\n", OpenNI::getExtendedError());
		return 2;
	}

	VideoStream depth;

	if (device.getSensorInfo(SENSOR_DEPTH) != NULL)
	{
		rc = depth.create(device, SENSOR_DEPTH);
		if (rc != STATUS_OK)
		{
			printf("Couldn't create depth stream\n%s\n", OpenNI::getExtendedError());
			return 3;
		}
	}

	rc = depth.start();
	if (rc != STATUS_OK)
	{
		printf("Couldn't start the depth stream\n%s\n", OpenNI::getExtendedError());
		return 4;
	}

	VideoFrameRef frame;

	while (!wasKeyboardHit())
	{
		rc = depth.readFrame(&frame);
		if (rc != STATUS_OK)
		{
			printf("Wait failed\n");
			continue;
		}

		if (frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_1_MM && frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_100_UM)
		{
			printf("Unexpected frame format\n");
			continue;
		}

		DepthPixel* pDepth = (DepthPixel*)frame.getData();

		int middleIndex = (frame.getHeight()+1)*frame.getWidth()/2;

		printf("[%08llu] %8d\n", (long long)frame.getTimestamp(), pDepth[middleIndex]);

	}

	depth.stop();
	depth.destroy();
	device.close();
	OpenNI::shutdown();

	return 0;
}


 6.执行程序成功,由于未安装设备primesense sensor或Xtion,所以显示如下,可以正常执行。

OpenNI学习笔记1----在vs2010下OpenNI的安装配置_第6张图片

 

ps.安装时参考了Heresy 的文章,谢谢Heresy。

随后购买了Xtion后,可以正常执行: ))

你可能感兴趣的:(OpenNI)