Advertisement

Kinect V2 开发环境搭建

阅读量:

中文版Kinect V2开发环境搭建指南稀缺,我将承担编写一份详尽的技术指导文件。

kinect v2 基本环境要求为:

windows8.0 以上

usb3.0接口

vs2012 或者2013来进行开发

kinect所有安装包分享左侧的链接提供所有Kinect安装包下载服务,其中包括Windows 8.1 ISO文件、Kinect V2 SDK工具包以及Visual Studio Community Edition 2013安装文件等资源。

接下来就是安装windows8.1, kinect v2 sdk, 和 visual sutdio community 2013.

然后运行 kinect Configuration Verifier 看看配置是否搭好。

接下来运行 Depth Basic-D2D 来看看深度摄像头是否可用

VS 2013 community 通过file->new->project ->console application

打开该project的property

安装kinectsdk v2后会自动生成kinectSDK20_DIR环境变量设置,请无需额外配置。按照下图所示步骤导入相应的lib和.h文件资料。

运行下面的代码会输出一系列深度距离

复制代码
 // ConsoleApplication1.cpp : Defines the entry point for the console application.

    
 //
    
  
    
 #include "stdafx.h"
    
 #include "iostream"
    
 #include "kinect.h"
    
 int _tmain(int argc, _TCHAR* argv[])
    
 { // 1a. Get default Sensor
    
 	IKinectSensor* pSensor = nullptr;
    
 	GetDefaultKinectSensor(&pSensor);
    
 	// 1b. Open sensor
    
 	pSensor->Open();
    
 	// 2a. Get frame source
    
 	IDepthFrameSource* pFrameSource = nullptr;
    
 	pSensor->get_DepthFrameSource(&pFrameSource);
    
 	// 3a. get frame reader
    
 	IDepthFrameReader* pFrameReader = nullptr;
    
 	pFrameSource->OpenReader(&pFrameReader);
    
 	// Enter main loop
    
 	size_t uFrameCount = 0;
    
 	while (uFrameCount < 100)
    
 	{
    
 		// 4a. Get last frame
    
 		IDepthFrame* pFrame = nullptr;
    
 		if (pFrameReader->AcquireLatestFrame(&pFrame) == S_OK)
    
 		{
    
 			// 4b. Get frame description
    
 			int        iWidth = 0;
    
 			int        iHeight = 0;
    
 			IFrameDescription* pFrameDescription = nullptr;
    
 			pFrame->get_FrameDescription(&pFrameDescription);
    
 			pFrameDescription->get_Width(&iWidth);
    
 			pFrameDescription->get_Height(&iHeight);
    
 			pFrameDescription->Release();
    
 			pFrameDescription = nullptr;
    
 			// 4c. Get image buffer
    
 			UINT    uBufferSize = 0;
    
 			UINT16*    pBuffer = nullptr;
    
 			pFrame->AccessUnderlyingBuffer(&uBufferSize, &pBuffer);
    
 			// 4d. Output depth value
    
 			int x = iWidth / 2,
    
 				y = iHeight / 2;
    
 			size_t idx = x + iWidth * y;
    
 			std::cout << pBuffer[idx] << std::endl;
    
 			// 4e. release frame
    
 			pFrame->Release();
    
 			pFrame = nullptr;
    
 			++uFrameCount;
    
 		}
    
 	}
    
 	// 3b. release frame reader
    
 	pFrameReader->Release();
    
 	pFrameReader = nullptr;
    
 	// 2b. release Frame source
    
 	pFrameSource->Release();
    
 	pFrameSource = nullptr;
    
 	// 1c. Close Sensor
    
 	pSensor->Close();
    
 	// 1d. Release Sensor
    
 	pSensor->Release();
    
 	pSensor = nullptr;
    
 	return 0;
    
 }

这样环境就搭配好了

将参考文章链接放置在此处,并且如果无法访问的话,则找不到相关资料。您需要将改写内容放入【

全部评论 (0)

还没有任何评论哟~