Do you want to start using the network to access Femto Mega? This quick start guide will help you start and run the device successfully!
This topic describes the following functions:
- k4a_device_get_installed_count()
- k4a_device_open()
- k4a_device_get_serialnum()
- k4a_device_start_cameras()
- k4a_device_stop_cameras()
- k4a_device_close()
Precondition
- Set up Femto Mega And upgrade the firmware version to the latest version 1.2.7 or later FemtoMega;
- The SDK is installed from Download Orbbec SDK and K4A Wrapper.
- Make sure that the FemtoMega and Host are in the same LAN (for device discovery)
Header file
Only one header file, namely k4a.h, is required. Make sure that the selected compiler is set to use the SDK library and contains folders. In addition, you need to link the k4a.lib and k4a.dll files.
#include <k4a/k4a.h>
Find Femto Mega device
You can connect multiple Femto Mega devices to a computer.
The network discovery function must be enabled by default (only valid for LAN)
Modify the OrbbecSDKConfig_v1.0.xml to change the value of EnumerateNetDevice from false to true
First, we will usek4a_device_get_installed_count()Function to determine the number of devices or whether any devices are connected. This function should run immediately without additional settings.
uint32_t count = k4a_device_get_installed_count();
After confirming that a device is connected to a computer, you can usek4a_device_open()Open it. You can provide the index of the device you want to open, or use K4A_DEVICE_DEFAULT only for the first device.
// Open the first plugged in Kinect device
k4a_device_t device = NULL;
k4a_device_open(K4A_DEVICE_DEFAULT, &device);
Like most content in the Azure Kinect library, when you open a certain content, you should also close it when it is used up! When disabled, remember to callk4a_device_close().
k4a_device_close(device);
After the device is turned on, it can be tested to ensure that it works properly. Let’s read the serial number of the 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);
Start camera
After the device is turned on, you need to usek4a_device_configuration_tObject configuration camera. The camera configuration contains a large number of different options. Select the setting that best suits your solution.
// Configure a stream of 3840×2160 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 simplicity, we will not show error handling in some examples. However, error handling is always important! Many functions return the success/failure type of the regular.k4a_result_t, or more specific variables that contain detailed information, suchk4a_wait_result_t. Check the documentation or IntelliSense of each function for expected error messages!
Can be usedK4A_SUCCEEDEDAndK4A_FAILEDThe result of the macro check function. Therefore, in addition to opening Femto Mega device, we can also protect function calls as follows:
// 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;
}
Complete source code
#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 3840×2160 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;
}