今天开始第一个程序,参考这篇官方文档,但是写得有点简略,甚至有点抽象,我来实操一下实现过程。
1.首先新建一个c++项目,千篇一律具体参考这个博文
至于头文件那块这么引用:
?在安装好的SDK(下载配置过程在我上一篇博客)包里找到头文件,添加进去。
这些事干完后最好确认vs软件安装没问题,有window10SDK,不然会显示:无法打开源文件 !可以看看这个文章。
?2.安装?NuGet程序包
这个就比较重要了,不安装的话你的程序会报错:没有什么什么的exe
具体步骤:
搜索Azure kinect就会显示出来,先安装第一个就能满足本文的历程了,之后再开发再安装别的。
?万事俱备只差代码,我帮你们copy过来:
#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;
}
?这时你只需要轻轻的点一下这里
舒服了!!?
|