Femto Mega Documentation

Generate Your First Femto Mega Application

 

Want to get started with your Femto Mega? This quickstart guide will help you get your device powered on and running successfully!

This document will introduce the following functions:

 

Prerequisites

  1. You have completed Set up Femto Mega.
  2. The SDK is installed from Download Orbbec SDK and K4A Wrapper.
#include <k4a/k4a.h>

 

Header Files

Just one header file is needed, k4a.h. Make sure your chosen compiler is set up to use the SDK libraries and include folder. The k4a.lib and k4a.dll files will also need to be linked.

uint32_t count = k4a_device_get_installed_count();

 

Find Femto Mega Device

Multiple Femto Mega devices can be connected to a computer. First, we’ll use the k4a_device_get_installed_count() function to determine if any devices are connected, or how many there are. This function should work right away without any additional setup.

uint32_t count = k4a_device_get_installed_count();

Once a device is found to be connected to the computer, it can be opened with k4a_device_open(). The index of the device to open can be provided, or just K4A_DEVICE_DEFAULT for the first device.

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

As with most things in the Azure Kinect library, when you open something, you should also close it when finished! Make sure to call k4a_device_close() when closing.

k4a_device_close(device);

After opening the device, we can test it is working properly. Let’s read the device serial number!

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

 

Start Cameras

After opening the device, the cameras need to be configured using a k4a_device_configuration_t object. There are many different options available in the camera configuration. Choose settings most appropriate for your scenario.

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

 

Error Handling

For brevity, error handling will not be shown in all examples. But error handling is always important! Many functions return a regular success/failure type k4a_result_t, or more specific variables with extra details like k4a_wait_result_t. Check the documentation for each function or IntelliSense to see expected error messages the function can return!

We can check function results with the K4A_SUCCEEDED and K4A_FAILED macros. So in addition to opening the Femto Mega device, we can also protect function calls like:

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

 

Full Source

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

Stay updated

Be the first to learn about our new
products and updates.