在VS2019上部署Azure Kinect项目
1、配置环境
1.1、下载安装Visual Studio 2019 https://www.cnblogs.com/hsjj/p/VisualStudio.html
1.2、文件->新建->项目
创建一个空的c++项目
右击 ”引用”,选择 ”管理NuGet程序包(N)…”
选择nuget.org 作为包源,选择“浏览”选项卡,然后搜索 Microsoft.Azure.Kinect.Sensor 。
点击安装
在项目中添加源文件,输入下面代码
#pragma comment(lib, “k4a.lib”)
#include <k4a/k4a.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
uint32_t count = k4a_device_get_installed_count();
if (count == 0)
{
printf(“No k4a devices attached!\n”);
return 1;
}
// Open the first plugged in Kinect device
k4a_device_t device = NULL;
if (K4A_FAILED(k4a_device_open(K4A_DEVICE_DEFAULT, &device)))
{
printf(“Failed to open k4a device!\n”);
return 1;
}
// Get the size of the serial number
size_t serial_size = 0;
k4a_device_get_serialnum(device, NULL, &serial_size);
// Allocate memory for the serial, then acquire it
char serial = (char)(malloc(serial_size));
k4a_device_get_serialnum(device, serial, &serial_size);
printf(“Opened device: %s\n”, serial);
free(serial);
// Configure a stream of 4096x3072 BRGA color data at 15 frames per second
k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
config.camera_fps = K4A_FRAMES_PER_SECOND_15;
config.color_format = K4A_IMAGE_FORMAT_COLOR_BGRA32;
config.color_resolution = K4A_COLOR_RESOLUTION_3072P;
// Start the camera with the given configuration
if (K4A_FAILED(k4a_device_start_cameras(device, &config)))
{
printf(“Failed to start cameras!\n”);
k4a_device_close(device);
return 1;
}
// Camera capture and application specific code would go here
// Shut down the camera when finished with application logic
k4a_device_stop_cameras(device);
k4a_device_close(device);
return 0;
}
运行结果如下:
1.3、添加opencv到Visual Studio 2019,参考下面链接
https://www.jb51.net/article/184819.htm
Step1:打开属性管理器,右击Debug|x64选择属性
Step2:进入VC++目录,在包含目录中添加C:\opencv\build\include和C:\opencv\build\include\opencv2。在库目录添加C:\opencv\build\x64\vc15\lib
Step3:进入连接器->输入,在附加依赖项添加opencv_world412d.lib,opencv_world412.lib
1.4、Azure Kinect DK 深度数据获取并使用opencv可视化
https://blog.csdn.net/qq_40936780/article/details/102634734
1.5、测试结果如下(注意在X64下运行)