z6娱乐

z6娱乐

K4A 接见FemtoMega网络模式

K4A接见FemtoMega网络模式

急剧入门:网络接见设备利用法式

想要起头使用网络接见Femto Mega ?????本文将援手你启动并成功运行该设备!

 

本文将介绍以下函数:

●     k4a_device_get_installed_count()

●     k4a_device_open()

●     k4a_device_get_serialnum()

●     k4a_device_start_cameras()

●     k4a_device_stop_cameras()

●     k4a_device_close()

先决前提

1.      《设置 Femto Mega》并将FemtoMega将固件版本升级最新1.2.7以上版本;; ;;;;

2.      并装置 SDK《Orbbec SDK 和 Orbbec SDK K4A Wrapper》

3.      确保Femto Mega和Host主机在统一个局域网内(做设备发现用)

头文件

只必要一个头文件,,,,,,即 k4a.h。。。。。。 请确保所选的编译器设置为使用 SDK 的库并蕴含文件加祝。。。。。 此表,,,,,,必要链接 k4a.lib 和 k4a.dll 文件。。。。。。

#include <k4a/k4a.h>

查找 Femto Mega 设备

可将多个 Femto Mega 设备衔接到推算机。。。。。。

必要默认打开网络发现职能(仅局域网有效)

批改OrbbecSDKConfig_v1.0.xml中将EnumerateNetDevice值由false改为true

1.png

 

 首先,,,,,,我们将使用 k4a_device_get_installed_count() 函数确定有几多个设备,,,,,,或者是否衔接了任何设备。。。。。。 此函数应可立即运行,,,,,,而无需经过附加的设置。。。。。。

uint32_t count = k4a_device_get_installed_count();

确定某个设备已衔接到推算机后,,,,,,能够使用 k4a_device_open() 将其打开。。。。。。 能够提供想要打开的设备的索引,,,,,,或者只对第一个设备使用 K4A_DEVICE_DEFAULT。。。。。。

// Open the first plugged in Kinect device
k4a_device_t device = NULL;
k4a_device_open(K4A_DEVICE_DEFAULT, &device);

与 Azure Kinect 库中的大无数内容一样,,,,,,当你打开某种内容时,,,,,,也应该在用完时将其关关! 关关时,,,,,,请记得挪用 k4a_device_close()。。。。。。

 

k4a_device_close(device);

打开设备后,,,,,,能够进行测试以确保它正常工作。。。。。。 让我们读取设备的序列号!

 

// 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);

启动相机

打开设备后,,,,,,必要使用 k4a_device_configuration_t 对象配置相机。。。。。。 相机配置蕴含大量分歧的选项。。。。。。 请选择最适合自己规划的设置。。。。。。

 

// Configure a stream of 3840x2160 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_2160P;

// Start the camera with the given configuration
k4a_device_start_cameras(device, &config);

// ...Camera capture and application specific code would go here...

// Shut down the camera when finished with application logic
k4a_device_stop_cameras(device);

谬误处置

为简洁起见,,,,,,我们不会在某些例子中显示谬误处置。。。。。。 但是,,,,,,谬误处置始终很沉要! 很多函数返回通例的成功/失败类型 k4a_result_t,,,,,,或者蕴含具体信息的更具体的变量,,,,,,好比 k4a_wait_result_t。。。。。。 请查看每个函数的文档或 IntelliSense,,,,,,以相识该函数预期显示的谬误新闻!

能够使用 K4A_SUCCEEDED 和 K4A_FAILED 宏查抄函数的了局。。。。。。 因而,,,,,,除了打开 Femto Mega 设备以表,,,,,,我们还能够按如下所示;; ;;;;ず灿茫

 

// 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;
}

齐全源代码

 

#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 3840x2160 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_2160P;

    // 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;
}


后续步骤

相识若何使用传感器 SDK 查找并打开 Femto Mega 设备。。。。。。

《查找并打开设备》

 


【网站地图】【sitemap】