尊龙凯时中国游

      尊龙凯时中国游

      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

      查找 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

      #include
      #include

      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 设备。

      《查找并打开设备》